25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

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