You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 9.1 KiB

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