選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

443 行
11 KiB

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