Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Makefile 8.4 KiB

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