Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

418 Zeilen
9.7 KiB

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