You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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