No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

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