Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

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