Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Makefile 9.6 KiB

10 anos atrás
9 anos atrás
10 anos atrás
9 anos atrás
10 anos atrás
10 anos atrás
9 anos atrás
9 anos atrás
10 anos atrás
10 anos atrás
9 anos atrás
9 anos atrás
9 anos atrás
9 anos atrás
9 anos atrás
9 anos atrás
9 anos atrás
9 anos atrás
9 anos atrás
9 anos atrás
10 anos atrás
9 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
9 anos atrás
9 anos atrás
9 anos atrás
9 anos atrás
10 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. # Makefile --- 10sr make dotfiles
  2. # 2014, 10sr. Unlicensed <http://unlicense.org>
  3. # Variable definitions
  4. home ?= $(HOME)
  5. dotfiles_url_base := https://raw.githubusercontent.com/10sr/dotfiles/master
  6. use_git ?= t
  7. git_auth ?= t
  8. dotfiles_git_path := 10sr/dotfiles.git
  9. ifneq (,$(git_auth))
  10. dotfiles_git := git@github.com:$(dotfiles_git_path)
  11. else
  12. $(warning 'git_auth' is empty. Use public read-only git repository.)
  13. dotfiles_git := http://github.com/$(dotfiles_git_path)
  14. endif
  15. current_origin_url := $(shell git config remote.origin.url)
  16. ifeq (,$(dotfiles_dir))
  17. ifneq (,$(findstring $(dotfiles_git_path),$(current_origin_url)))
  18. $(warning Currently in dotfiles repository)
  19. dotfiles_dir := $(PWD)
  20. else
  21. # Current directory is not 10sr/dotfiles.git reposioty
  22. ifeq (,$(DOTFILES_DIR))
  23. $(warning Neigher DOTFILES_DIR nor dotfiles_dir is defined)
  24. $(warning Use default value)
  25. dotfiles_dir := $(home)/10sr_dotfiles
  26. else
  27. # dotfiles_dir is empty but DOTFILES_DIR has a value
  28. $(warning dotfiles_dir is set from DOTFILES_DIR)
  29. dotfiles_dir := $(DOTFILES_DIR)
  30. endif
  31. endif
  32. endif
  33. $(warning dotfiles_dir: $(dotfiles_dir))
  34. localdir := $(home)/.local
  35. vardir := $(home)/.var
  36. bindir := $(localdir)/bin
  37. current := $(shell date)
  38. uname := $(shell uname)
  39. shrc_loadables := sh bash zsh
  40. emacs ?= $(shell which emacs 2>/dev/null)
  41. git ?= $(shell which git 2>/dev/null)
  42. curl ?= $(shell which curl 2>/dev/null)
  43. grep ?= GREP_OPTIONS= $(shell which grep 2>/dev/null)
  44. # Targets
  45. all: default
  46. tests := test-el
  47. test: test-syntax $(tests)
  48. test_syntaxes := test-syntax-el test-syntax-sh
  49. test-syntax: $(test_syntaxes)
  50. setups := setup-darwin setup-directories setup-emacs setup-gitconf \
  51. setup-repository setup-util setup-rc
  52. # `make setup` to setup these all sounds to be too match
  53. setup-all: $(setups)
  54. runs := run-emacs run-bash run-zsh
  55. # `make check` is just an alias for `make test`
  56. check: test
  57. # Similarly, check-syntax is test-syntax
  58. check-syntax: test-syntax
  59. .PHONY: all default \
  60. test check $(tests) \
  61. test-syntax check-syntax $(test_syntaxes)\
  62. setup-all $(setups)
  63. # System detection
  64. # ================
  65. # Is this usefull? Just checking uname is not enough?
  66. ismsys :=
  67. iscygwin :=
  68. iswindows :=
  69. isdarwin :=
  70. isfreebsd :=
  71. isbsd :=
  72. islinux :=
  73. ifneq (,$(findstring MINGW,$(uname)))
  74. ismsys := t
  75. endif
  76. ifneq (,$(findstring CYGWIN,$(uname)))
  77. iscygwin := t
  78. endif
  79. ifneq (,$(ismsys)$(iscygwin))
  80. iswindows := t
  81. endif
  82. ifneq (,$(findstring Darwin,$(uname)))
  83. isdarwin := t
  84. endif
  85. ifneq (,$(findstring FreeBSD,$(uname)))
  86. isfreebsd := t
  87. endif
  88. ifneq (,$(isdarwin)$(isfreebsd))
  89. isbsd := t
  90. endif
  91. ifneq (,$(findstring Linux,$(uname)))
  92. islinux := t
  93. endif
  94. # preparing files
  95. # ===============
  96. ifeq (,$(use_git))
  97. $(warning 'use_git' is set to empty. Use curl to fetch files)
  98. $(dotfiles_dir)/%:
  99. mkdir -vp $(dotfiles_dir)
  100. curl --url $(dotfiles_url_base)/$* --output $@
  101. else
  102. $(warning 'use_git' is set to non-empty. Use git to retrieve files)
  103. $(dotfiles_dir)/%: setup-repository
  104. test -f "$@"
  105. endif
  106. # Shortcut target for interactive usage
  107. # For example, `make file-emacs.el use_git=` will fetch emacs.el from web with
  108. # curl program.
  109. # NOTE: Is there any way to make all `file-%` targets phony?
  110. file-%: $(dotfiles_dir)/%
  111. test -f "$<"
  112. # Make sure $(dotfiles_dir)/% wont be removed as intermidiate files
  113. .PRECIOUS: $(dotfiles_dir)/%
  114. # setups
  115. # ======
  116. # setup git repository
  117. # --------------------
  118. setup-repository: $(dotfiles_dir)/.git
  119. $(dotfiles_dir)/.git:
  120. ifeq (,$(git))
  121. false "Git not installed"
  122. endif
  123. $(git) clone $(dotfiles_git) $(dotfiles_dir)
  124. # utils
  125. # -----
  126. setup_utils := colortable16.sh 256colors2.pl pacapt ack-2.12
  127. setup-util: $(setup_utils)
  128. .PHONY: $(setup_utils)
  129. setup_utils_path := $(setup_utils:%=$(bindir)/%)
  130. $(setup_utils): %: $(bindir)/%
  131. $(setup_utils_path):
  132. $(curl) -L --url "$(util_url)" --output "$@"
  133. chmod +x "$@"
  134. colortable16.sh: \
  135. util_url := https://gist.github.com/10sr/6852317/raw/colortable16.sh
  136. 256colors2.pl: util_url := https://gist.github.com/10sr/6852331/raw/256colors2.pl
  137. pacapt: util_url := https://github.com/icy/pacapt/raw/ng/pacapt
  138. ack-2.12: util_url := http://beyondgrep.com/ack-2.12-single-file
  139. # create directories
  140. # ------------------
  141. setup_directories := $(localdir) $(vardir) $(bindir)
  142. setup-directory: $(setup_directories)
  143. $(localdir) $(vardir) $(bindir):
  144. mkdir -vp $@
  145. # darwin setup
  146. # ------------
  147. setup_darwins := setup-darwin-defaults setup-darwin-daemon
  148. setup-darwin: $(setup_darwins)
  149. .PHONY: $(setup_darwins)
  150. setup-darwin-defaults:
  151. # http://appdrill.net/60641/mac-boot-mute.html
  152. #sudo nvram SystemAudioVolume=%80
  153. # add quit entry in menu
  154. defaults write com.apple.finder QuitMenuItem -bool YES
  155. # show full path on titlebar
  156. defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES
  157. # do not show desktop icons
  158. defaults write com.apple.finder CreateDesktop -boolean false
  159. killall Finder
  160. # disable dashboard
  161. #defaults write com.apple.dashboard mcx-disabled -bool YES
  162. setup-darwin-daemon:
  163. test "`launchctl getenv LC_ALL`" = C || sudo launchctl setenv LC_ALL C
  164. if ! (launchctl list | grep com.apple.locate) >/dev/null ;\
  165. then \
  166. sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist ;\
  167. fi
  168. # emacs setup
  169. # -----------
  170. setup-emacs: $(dotfiles_dir)/emacs.el
  171. $(emacs) -q --debug-init --batch --load $< -f my-auto-install-package
  172. # git config setup
  173. # ----------------
  174. ifneq (,$(git))
  175. git_conf := $(git) config --global
  176. endif
  177. xz := $(shell which xz 2>/dev/null)
  178. setup-gitconf:
  179. ifeq (,$(git))
  180. $(warnning "Git program not found")
  181. else
  182. $(git_conf) user.name '10sr'
  183. $(git_conf) user.email '8slashes+git@gmail.com'
  184. $(git_conf) core.autocrlf false
  185. $(git_conf) core.excludesfile '~/.gitignore'
  186. $(git_conf) color.ui auto
  187. $(git_conf) status.relativePaths false
  188. $(git_conf) status.showUntrackedFiles normal
  189. $(git_conf) log.date iso
  190. $(git_conf) push.default current
  191. ifneq (,$(xz))
  192. $(git_conf) tar.txz.command "xz -c"
  193. endif
  194. $(git_conf) alias.graph "log --graph --date-order -C -M --pretty=tformat:\"%C(green)%h%C(reset) %C(white)%ad%C(reset) %C(red)%an%C(reset)%C(yellow)%d%C(reset) %C(white bold)%s%C(reset)\" --date=short -n 499"
  195. $(git_conf) alias.st "status -s -b"
  196. $(git_conf) alias.b "branch"
  197. $(git_conf) alias.sb "show-branch"
  198. $(git_conf) alias.ci "commit --verbose"
  199. $(git_conf) alias.co "checkout"
  200. $(git_conf) alias.cim "commit --verbose -m"
  201. $(git_conf) alias.di "diff --color"
  202. $(git_conf) alias.me "merge --no-ff --stat --verbose"
  203. $(git_conf) alias.ffme "merge --ff-only --stat --verbose"
  204. $(git_conf) alias.gr "grep -n"
  205. $(git_conf) alias.ls "ls-files"
  206. # $(git_conf) alias.ls "ls-files -v --full-name"
  207. # $(git_conf) alias.ls "status -u -s ."
  208. $(git_conf) alias.sl "!sl"
  209. # $(git_conf) alias.my-ls "ls-files | xargs ls"
  210. # $(git_conf) alias.ll "!git ls-files | xargs ls -l -CFG --color=auto --time-style=long-iso"
  211. $(git_conf) alias.addi "add -i"
  212. # Add patch to index
  213. $(git_conf) alias.ap "apply --cached"
  214. $(git_conf) alias.clean-p "diff --quiet"
  215. $(git_conf) alias.echo-ref "for-each-ref --format='%(refname:short)'"
  216. $(git_conf) alias.todo "grep -nH -E -i 'todo:|note:|fixme:'"
  217. $(git_conf) alias.snap '! gitdir="`git rev-parse --git-dir`" && : >>"$gitdir"/logs/refs/snapshot && cmt=`git stash create` && test -n "$cmt" && git update-ref refs/snapshot $cmt && echo Snapshot created: $cmt'
  218. #$(git_conf) alias.wc "!git ls-files -z | xargs -0 wc"
  219. # $(git_conf) push.default "simple"
  220. ifneq (,$(iswindows))
  221. $(git_conf) core.fileMode false
  222. endif
  223. endif
  224. # setup rc files
  225. # --------------
  226. # Generate load codes from the files themselves.
  227. # Load codes are defined by following SETUP_LOAD: indicator.
  228. # String DOTFILES_DIR in the load codes will be replaced into the value of
  229. # $(dotfiles_dir).
  230. # If append_load is non-empty, the load codes are appended to $(topfile),
  231. # otherwise the code will be just printed out to stdout.
  232. setup_rcs := setup-rc-vimrc setup-rc-tmux.conf setup-rc-emacs.el
  233. setup-rc: $(setup_rcs)
  234. .PHONY: $(setup_rcs)
  235. command_extract_setup_load := $(grep) -e 'SETUP_LOAD: ' | \
  236. sed -e 's/^.*SETUP_LOAD: //' -e 's|DOTFILES_DIR|$(dotfiles_dir)|'
  237. $(setup_rcs): setup-rc-%: $(dotfiles_dir)/%
  238. ifeq (,$(append_load))
  239. @echo "\`append_load' is not defined. Just print load command."
  240. cat "$<" | $(command_extract_setup_load)
  241. else
  242. cat "$<" | $(command_extract_setup_load) | tee -a "$(topfile)"
  243. endif
  244. setup-rc-vimrc: topfile := $(home)/.vimrc
  245. setup-rc-tmux.conf: topfile := $(home)/.tmux.conf
  246. setup-rc-emacs.el: topfile := $(home)/.emacs.d/init.el
  247. # run
  248. # ===
  249. run-emacs: $(dotfiles_dir)/emacs.el
  250. $(emacs) -q --eval "(setq )" --load "$<"
  251. # test
  252. # ====
  253. test_els := test-el-emacs.el
  254. test-el: $(test_els)
  255. .PHONY: $(test_els)
  256. $(test_els): test-el-%: $(dotfiles_dir)/%
  257. $(emacs) -Q -batch -f batch-byte-compile $<
  258. EMACS_EL_DRY_RUN=t $(emacs) -q --debug-init --batch \
  259. --eval "(setq debug-on-error t)" --load $<c --kill
  260. # test syntax
  261. # ===========
  262. test_syntax_shs := test-syntax-shrc test-syntax-profile \
  263. test-syntax-xinitrc test-syntax-xprograms
  264. test-syntax-sh: $(test_syntax_shs)
  265. .PHONY: $(test_syntax_shs)
  266. $(test_syntax_shs): test-syntax-%: $(dotfiles_dir)/%
  267. sh -ec 'for sh in $(shrc_loadables); do $$sh -n $<; done'
  268. test_syntax_els := test-syntax-emacs.el
  269. test-syntax-el: $(test_syntax_els)
  270. .PHONY: $(test_syntax_els)
  271. sexp_elisp_syntax_check := \
  272. (with-temp-buffer \
  273. (emacs-lisp-mode) \
  274. (insert-file-contents file) \
  275. (condition-case err \
  276. (check-parens) \
  277. (user-error \
  278. (error (format "%s:%d:%d:Unmatched brancet or quote" \
  279. file \
  280. (line-number-at-pos) \
  281. (- (point) (point-at-bol)))))))
  282. $(test_syntax_els): test-syntax-%: $(dotfiles_dir)/%
  283. $(emacs) -Q --debug-init --batch \
  284. --eval '(let ((file "$<")) $(sexp_elisp_syntax_check))' --kill