25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

375 lines
8.8 KiB

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