Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

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