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.
 
 
 
 
 
 

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