Commit | Line | Data |
---|---|---|
67b1a15a MW |
1 | ## -*-makefile-*- |
2 | ||
3 | all:: | |
4 | .SECONDEXPANSION: #sorry | |
5 | ||
6 | ###-------------------------------------------------------------------------- | |
7 | ### Utilities. | |
8 | ||
9 | ## | |
10 | quote = '$(subst ','\'',$1)'#' | |
11 | ||
12 | ## Suss out how to print stuff. | |
13 | print = printf "%s" $(call quote,$1) | |
14 | ||
15 | ## Looking configuration things up. | |
16 | mdw-conf = $(shell bin/mdw-conf "$1" "$2") | |
17 | ||
18 | ## Checking symlink targets. | |
19 | symlink-ok-p = $(shell \ | |
20 | case $$(readlink 2>/dev/null $1) in ($2) echo t ;; esac) | |
21 | ||
22 | ## Silent rules machinery. | |
23 | V = 0 | |
24 | v_tag = $(call v_tag_$V,$1,$2) | |
25 | v_tag_0 = @printf " %-8s %s\n" "$1" $(call quote,$@); | |
26 | V_AT = $(V_AT_$V) | |
27 | V_AT_0 = @ | |
28 | ||
29 | ## Hack. | |
30 | relax = | |
31 | ||
32 | ###-------------------------------------------------------------------------- | |
33 | ### Configuration. | |
34 | ||
35 | ## Figure out where I am. | |
36 | HERE = $(shell pwd) | |
37 | ||
38 | ## Decide on how to fetch things from URLs. | |
39 | ifeq ($(shell (curl >/dev/null 2>&1 --version || [ $$? -eq 2 ]) && echo t),t) | |
40 | get-url = curl -fs -o $1 $2 | |
41 | else | |
42 | get-url = wget -q -O $1 $2 | |
43 | endif | |
44 | ||
45 | ## Which Emacs should I use? | |
46 | EMACS := $(shell \ | |
47 | emacs=nil; \ | |
48 | for i in emacs24 emacs23 emacs22 emacs21 emacs; do \ | |
49 | if type >/dev/null 2>&1 $$i; then echo $$i; break; fi; \ | |
50 | done) | |
51 | ||
52 | ## Whence to obtain externally hosted stuff. | |
53 | REPO = https://ftp.distorted.org.uk/u/mdw/profile | |
54 | ||
55 | ## Additional local configuration. | |
56 | -include local.mk | |
57 | ||
58 | ###-------------------------------------------------------------------------- | |
59 | ### Some utility rules. | |
60 | ||
61 | _force: | |
62 | .PHONY: _force | |
63 | ||
64 | ###-------------------------------------------------------------------------- | |
65 | ### Emacs. | |
66 | ||
967148ff MW |
67 | ifneq ($(EMACS),nil) |
68 | ||
67b1a15a MW |
69 | EMACSLIB = $(HOME)/lib/emacs |
70 | ||
486623cb | 71 | EMACS_VERSION := $(shell $(EMACS) 2>&1 -Q --batch --eval \ |
b2f6f110 MW |
72 | '(message "%s %s" emacs-major-version emacs-minor-version)' | \ |
73 | tail -n1) | |
486623cb MW |
74 | emacs-version-p = $(shell set -- $(EMACS_VERSION); \ |
75 | if [ $$1 -gt $1 ] || ([ $$1 -eq $1 ] && [ $$2 -ge $2 ]); then \ | |
76 | echo t; \ | |
77 | fi) | |
78 | ||
6369ae29 MW |
79 | ELISP += make-regexp ew-hols |
80 | ELISP += mdw-gnus-patch | |
81 | ELISP += mdw-multiple-cursors | |
82 | ELISP += git git-blame vc-git stgit quilt | |
486623cb MW |
83 | |
84 | ifeq ($(call emacs-version-p,24,3),t) | |
6369ae29 | 85 | ELISP += bracketed-paste |
486623cb | 86 | endif |
67b1a15a | 87 | |
3e441da6 MW |
88 | ELISP += dot-emacs |
89 | dot-emacs_DEPS = make-regexp | |
90 | ||
67b1a15a MW |
91 | SCRIPTLINKS += emacsclient-hack movemail-hack sendmail-hack |
92 | SCRIPTLINKS += aspell-hack emerge-hack | |
93 | ||
3e441da6 | 94 | %.elc: %.el $$(foreach e, $$($$*_DEPS), $$(DEP_$$e)) |
83198952 MW |
95 | $(call v_tag,EMACS)if ! $(EMACS) >$*.build-log 2>&1 \ |
96 | -L el/ -L $(EMACSLIB) \ | |
67b1a15a | 97 | --batch --no-site-file \ |
83198952 MW |
98 | --eval '(byte-compile-file "$<")'; then \ |
99 | cat $*.build-log; exit 2; \ | |
100 | fi | |
67b1a15a | 101 | |
6369ae29 MW |
102 | LOCAL_ELISP = $(filter $(notdir $(wildcard el/*.el)), \ |
103 | $(addsuffix .el, $(ELISP))) | |
104 | $(foreach e, $(LOCAL_ELISP), \ | |
105 | $(eval DEP_$(basename $e) = $(EMACSLIB)/$(e:.el=.elc))) | |
67b1a15a MW |
106 | $(addprefix $(EMACSLIB)/, $(LOCAL_ELISP)): $(EMACSLIB)/%: el/% |
107 | $(call v_tag,SYMINK)mkdir -p $(EMACSLIB) && \ | |
108 | rm -f $@.new && \ | |
109 | ln -s $(HERE)/$< $@.new && \ | |
110 | mv $@.new $@ | |
111 | ||
112 | REMOTE_ELISP = $(filter-out $(notdir $(wildcard el/*.el)), \ | |
6369ae29 | 113 | $(addsuffix .el, $(ELISP))) |
67b1a15a | 114 | $(foreach e, $(REMOTE_ELISP), \ |
6369ae29 | 115 | $(eval DEP_$(basename $e) = $(if $(shell \ |
67b1a15a MW |
116 | if $(EMACS) >/dev/null 2>&1 --no-site-file -q --batch \ |
117 | --eval ' \ | |
118 | (progn \ | |
119 | (kill-emacs (condition-case nil \ | |
120 | (progn (load-library "$e") 0) \ | |
121 | (error 1))))'; then \ | |
122 | echo t; \ | |
123 | fi),, $(EMACSLIB)/$(e:.el=.elc)))) | |
124 | $(addprefix $(EMACSLIB)/, $(REMOTE_ELISP)): $(EMACSLIB)/%: | |
125 | $(call v_tag,FETCH)mkdir -p $(EMACSLIB) && \ | |
126 | $(call get-url,$@.new,$(REPO)/$*) && \ | |
127 | mv $@.new $@ | |
128 | ||
129 | DOTLINKS += .emacs .emacs-calc .vm .gnus.el .ercrc.el | |
130 | ||
131 | all:: $(foreach e, $(ELISP), $(DEP_$e)) | |
6369ae29 | 132 | $(foreach e, $(ELISP), $(eval _emacs.$e: $(EMACSLIB)/$e.elc)) |
67b1a15a | 133 | |
967148ff MW |
134 | endif |
135 | ||
67b1a15a MW |
136 | ###-------------------------------------------------------------------------- |
137 | ### Other simpler things. | |
138 | ||
139 | $(HOME)/.mdw.conf: | |
140 | $(call v_tag,COPY)cp mdw.conf $@.new && mv $@.new $@ | |
141 | ||
142 | ## Utility packages. | |
143 | PACKAGES += mlib checkpath | |
144 | mlib_CHECK = crc-mktab | |
145 | checkpath_CHECK = tmpdir | |
146 | checkpath_DEPS = mlib | |
147 | ||
148 | ## Packaging machinery. | |
149 | SCRIPTLINKS += mdw-build mdw-sbuild mdw-sbuild-server | |
150 | SCRIPTLINKS += update-buildable-branch | |
151 | ||
152 | ## Shells. | |
153 | DOTLINKS += .profile .shell-rc .shell-logout | |
a3857ab2 | 154 | DOTLINKS += .shrc |
9ba9bb2f MW |
155 | DOTLINKS += .zprofile .zshrc .zlogout .zshenv |
156 | DOTLINKS += .bash_profile .bash_completion .bash_logout | |
157 | DOTLINKS += .bashrc .inputrc | |
67b1a15a MW |
158 | .bash_profile_SRC = bash-profile |
159 | .bash_completion_SRC = bash-completion | |
9ba9bb2f MW |
160 | .bash_logout_SRC = shell-logout |
161 | .zlogout_SRC = shell-logout | |
67b1a15a | 162 | |
a3857ab2 MW |
163 | ## The Plan 9 `rc' shell. This needs special hacking, because the Linux port |
164 | ## and Plan 9 From User Space have incompatible syntax. | |
165 | DOTLINKS += lib/profile | |
166 | lib/profile_SRC = rcrc | |
167 | all:: $(HOME)/.rcrc | |
168 | $(HOME)/.rcrc: dot/rcrc | |
169 | $(call v_tag,SED)sed 's/; if not/else/' $< >$@.new && mv $@.new $@ | |
170 | ||
67b1a15a MW |
171 | ## Git. |
172 | DOTSUBST += .gitconfig | |
2e15741e | 173 | SCRIPTLINKS += git-copyright-dates |
67b1a15a MW |
174 | DOTLINKS += .cgrc .tigrc |
175 | .gitconfig_SUBSTS = \ | |
176 | $(call substvar,releasekey,$(call mdw-conf,release-key,481334C2)) | |
177 | $(HOME)/.gitconfig: $(HOME)/.mdw.conf | |
178 | ||
179 | ## PulseAudio. | |
180 | DOTLINKS += .pulse/daemon.conf | |
181 | DOTSUBST += .pulse/default.pa | |
182 | .pulse/daemon.conf_SRC = pulse-daemon.conf | |
183 | .pulse/default.pa_SRC = pulse-default.pa.in | |
184 | ||
185 | ## Other editors. | |
186 | DOTLINKS += .vimrc .mg .zile | |
187 | ||
188 | ## Mail. | |
189 | DOTLINKS += .mailrc .signature .muttrc | |
190 | ||
191 | ## Lisp. | |
192 | DOTLINKS += .cmucl-init.lisp .sbclrc .clisprc.lisp .eclrc | |
193 | .cmucl-init.lisp_SRC = lisp-init.lisp | |
194 | .sbclrc_SRC = lisp-init.lisp | |
195 | .clisprc.lisp_SRC = lisp-init.lisp | |
196 | .eclrc_SRC = lisp-init.lisp | |
197 | DOTLINKS += .swank.lisp | |
198 | ||
199 | ## IPython. | |
200 | DOTLINKS += .ipython/profile_default/ipython_config.py | |
201 | DOTLINKS += .ipython/profile_default/startup/50-key-bindings.py | |
202 | .ipython/profile_default/ipython_config.py_SRC = ipython-config.py | |
203 | .ipython/profile_default/startup/50-key-bindings.py_SRC = ipython-key-bindings.py | |
204 | ||
205 | ## Other languages. | |
206 | DOTLINKS += .guile | |
207 | DOTLINKS += .tclshrc .wishrc | |
208 | .tclshrc_SRC = tclshrc | |
209 | .wishrc_SRC = tclshrc | |
210 | ||
211 | ## Random scripts. | |
212 | SCRIPTLINKS += mdw-editor mdw-pager | |
213 | SCRIPTLINKS += mdw-conf | |
214 | SCRIPTLINKS += svnwrap | |
215 | SCRIPTLINKS += guest-console | |
216 | SCRIPTLINKS += hyperspec | |
217 | ||
218 | ## Random odds and ends. | |
219 | DOTLINKS += .lesskey .infokey .sqliterc | |
220 | DOTLINKS += .gdbinit .toprc .aspell.conf | |
221 | DOTLINKS += .dircolors .colordiffrc .screenrc .tmux.conf | |
222 | DOTLINKS += .cvsrc .indent.pro .ditz-config | |
da526ba7 MW |
223 | DOTLINKS += .lftp/rc |
224 | .lftp/rc_SRC = lftp-rc | |
67b1a15a MW |
225 | DOTSUBST += .mykermrc |
226 | SCRIPTLINKS += lesspipe.sh | |
227 | ||
228 | SCRIPTLINKS += run-with-shell-env | |
229 | SCRIPTLINKS += start-ssh-agent start-ssh-pageant | |
230 | SCRIPTLINKS += add-ssh-keys | |
231 | SCRIPTLINKS += hacks/ssh/ssh | |
232 | hacks/ssh/ssh_SRC = hacks/ssh | |
233 | ||
234 | DOTLINKS += .w3m/config .elinks/elinks.conf | |
235 | .w3m/config_SRC = w3m-config | |
236 | .elinks/elinks.conf_SRC = elinks.conf | |
237 | ||
238 | DOTLINKS += .mc/ini .mc/panels.ini | |
239 | .mc/ini_SRC = mc-ini | |
240 | .mc/panels.ini_SRC = mc-panels.ini | |
241 | ||
242 | DOTLINKS += .parallel/config | |
243 | .parallel/config_SRC = parallel-config | |
244 | ||
245 | ###-------------------------------------------------------------------------- | |
246 | ### X11 configuration. | |
247 | ||
248 | ifeq ($X,t) | |
249 | ||
250 | PACKAGES += xtoys | |
251 | xtoys_CHECK = xatom | |
252 | xtoys_DEPS = mlib | |
253 | ||
254 | DOTLINKS += .xinitrc .xsession .xmodmap .vncrc .vncsession | |
255 | DOTLINKS += .fonts.conf | |
256 | DOTLINKS += .stalonetrayrc | |
257 | ||
258 | DOTLINKS += .putty/sessions/Default%20Settings | |
259 | .putty/sessions/Default%20Settings_SRC = putty-defaults | |
260 | ||
261 | DOTLINKS += .config/gnome-session/sessions/mdw.session | |
262 | .config/gnome-session/sessions/mdw.session_SRC = mdw.session | |
263 | ||
264 | DOTLINKS += .Eterm/themes/Eterm/theme.cfg | |
265 | DOTLINKS += .enlightenment/keybindings.cfg | |
266 | DOTLINKS += .enlightenment-vnc/keybindings.cfg | |
267 | DOTLINKS += .e16/bindings.cfg | |
268 | .Eterm/themes/Eterm/theme.cfg_SRC = eterm-theme.cfg | |
269 | .enlightenment/keybindings.cfg_SRC = e-keybindings.cfg | |
270 | .enlightenment-vnc/keybindings.cfg_SRC = evnc-keybindings.cfg | |
271 | .e16/bindings.cfg_SRC = e16-bindings | |
272 | ||
273 | DOTLINKS += .gtkrc-2.0 | |
274 | DOTLINKS += .config/gtk-3.0/gtk.css | |
275 | DOTLINKS += .config/gtk-3.0/settings.ini | |
276 | .config/gtk-3.0/gtk.css_SRC = gtk3.css | |
277 | .config/gtk-3.0/settings.ini_SRC = gtk3-settings.ini | |
278 | ||
279 | SCRIPTLINKS += xinitcmd lock-screen xshutdown | |
280 | SCRIPTLINKS += un-backslashify-selection | |
281 | SCRIPTLINKS += xpra-start-xdummy | |
5f9b345a | 282 | SCRIPTLINKS += play-rawk |
67b1a15a MW |
283 | |
284 | DOTCPP += .Xdefaults | |
285 | Xdefaults_DEFS = -DEMACSWD=$(call mdw-conf,emacs-width,77) | |
286 | $(HOME)/.Xdefaults: $(HOME)/.mdw.conf | |
287 | ||
ddc97f65 MW |
288 | ifeq ($(shell case $${DISPLAY-nil} in (:[0-9]*) echo t ;; (*) echo nil ;; esac),t) |
289 | dotfile-hook/.Xdefaults = \ | |
290 | $(call v_tag,XRDB)xrdb -override $< | |
291 | endif | |
292 | ||
67b1a15a MW |
293 | endif |
294 | ||
295 | ###-------------------------------------------------------------------------- | |
296 | ### Processing dotfiles. | |
297 | ||
298 | dotfile-source = $(HERE)/dot/$(or $($1_SRC), $(1:.%=%)$2) | |
299 | ||
4937ba2d | 300 | ## Easiest: just make symlinks. |
67b1a15a MW |
301 | dotlink-ok-p = \ |
302 | $(call symlink-ok-p,$(HOME)/$1,$(call dotfile-source,$1)) | |
303 | all:: $(addprefix $(HOME)/, $(DOTLINKS)) | |
304 | $(addprefix $(HOME)/, $(subst %,\%,$(DOTLINKS))): $(HOME)/%: \ | |
305 | $$(if $$(call dotlink-ok-p,$$*),,_force) | |
306 | $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \ | |
307 | rm -f $@.new && \ | |
308 | ln -s $(call dotfile-source,$*) $@.new && \ | |
309 | mv $@.new $@ | |
f6c3a80b | 310 | $(dotfile-hook/$*) |
67b1a15a MW |
311 | |
312 | ## Hack with the C preprocessor. | |
313 | all:: $(addprefix $(HOME)/, $(DOTCPP)) | |
314 | $(addprefix $(HOME)/, $(subst %,\%,$(DOTCPP))): $(HOME)/%: \ | |
315 | $$(call dotfile-source,$$*) Makefile | |
316 | $(call v_tag,CPP)mkdir -p $(dir $@) && \ | |
317 | rm -f $@.new && \ | |
318 | cpp -P -o$@.new $($*_DEFS) $< && \ | |
319 | mv $@.new $@ | |
f6c3a80b | 320 | $(dotfile-hook/$*) |
67b1a15a MW |
321 | |
322 | ## Hack by making simple substitutions. | |
323 | substvar = -e $(call quote,s\a@$1@\a$2\ag) | |
324 | SUBSTS += $(call substvar,home,$(HOME)) | |
325 | SUBSTS += $(call substvar,profile,$(HERE)) | |
326 | all:: $(addprefix $(HOME)/, $(DOTSUBST)) | |
327 | $(addprefix $(HOME)/, $(subst %,\%,$(DOTSUBST))): $(HOME)/%: \ | |
33271a96 | 328 | $$(call dotfile-source,$$*,.in) Makefile |
67b1a15a MW |
329 | $(call v_tag,SUBST)mkdir -p $(dir $@) && \ |
330 | rm -f $@.new && \ | |
331 | sed -e "1i\ | |
332 | $(relax)### generated by $(HERE)/Makefile; do not edit!" \ | |
333 | $(SUBSTS) $($*_SUBSTS) \ | |
334 | $(call dotfile-source,$*,.in) >$@.new && \ | |
335 | mv $@.new $@ | |
f6c3a80b | 336 | $(dotfile-hook/$*) |
67b1a15a MW |
337 | |
338 | ###-------------------------------------------------------------------------- | |
339 | ### Processing script links. | |
340 | ||
341 | script-source = $(HERE)/bin/$(or $($1_SRC), $1) | |
0cd3b798 MW |
342 | |
343 | ifeq ($(prefix-shebang-p),t) | |
344 | all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS)) | |
345 | $(addprefix $(HOME)/bin/, $(SCRIPTLINKS)): $(HOME)/bin/%: \ | |
346 | $$(call script-source,$$*) Makefile | |
347 | $(call v_tag,SHEBANG)mkdir -p $(dir $@) && \ | |
348 | rm -f $@.new && \ | |
349 | sed "1s\a\(#! *\)/\a\1$(SHEBANG_PREFIX)/\a" \ | |
350 | $(call script-source,$*) >$@.new && \ | |
351 | chmod --reference=$(call script-source,$*) $@.new && \ | |
352 | mv $@.new $@ | |
353 | $(script-hook/$*) | |
354 | else | |
67b1a15a MW |
355 | scriptlink-ok-p = \ |
356 | $(call symlink-ok-p,$(HOME)/bin/$1,$(call script-source,$1)) | |
357 | all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS)) | |
358 | $(addprefix $(HOME)/bin/, $(SCRIPTLINKS)): $(HOME)/bin/%: \ | |
359 | $$(if $$(call scriptlink-ok-p,$$*),,_force) | |
360 | $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \ | |
361 | rm -f $@.new && \ | |
362 | ln -s $(call script-source,$*) $@.new && \ | |
363 | mv $@.new $@ | |
f6c3a80b | 364 | $(script-hook/$*) |
0cd3b798 | 365 | endif |
67b1a15a MW |
366 | |
367 | all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS)) | |
368 | ||
369 | ###-------------------------------------------------------------------------- | |
370 | ### Building packages from source tarballs. | |
371 | ||
372 | SRCDIR = $(HOME)/src/profile | |
373 | ||
374 | pkg-builddir = $(SRCDIR)/$1/build | |
375 | pkg-stamp = $(call pkg-builddir,$1)/$2-stamp | |
376 | ||
377 | $(foreach p, $(PACKAGES), $(eval DEP_$p = $(if $(shell \ | |
378 | if $($p_CHECK) >/dev/null 2>&1 --version; then echo t; fi),, \ | |
379 | $(call pkg-stamp,$p,install)))) | |
380 | ||
381 | $(PACKAGES:%=$(SRCDIR)/%.tar.gz): $(SRCDIR)/%.tar.gz: | |
382 | $(call v_tag,FETCH)mkdir -p $(SRCDIR) && \ | |
383 | rm -f $@.new && \ | |
384 | $(call get-url,$@.new,$(REPO)/$*.tar.gz) && \ | |
385 | mv $@.new $@ | |
386 | ||
387 | $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,unpack)): \ | |
388 | $(call pkg-stamp,%,unpack): $(SRCDIR)/%.tar.gz | |
389 | $(call v_tag,EXTRACT)rm -rf $(SRCDIR)/$* && \ | |
390 | mkdir $(SRCDIR)/$*.tmp-unpack && \ | |
391 | cd $(SRCDIR)/$*.tmp-unpack && \ | |
392 | gzip -cd ../$*.tar.gz | tar xf - && \ | |
393 | mv * ../$* && \ | |
394 | cd .. && \ | |
395 | rmdir $*.tmp-unpack && \ | |
396 | mkdir $*/build && \ | |
397 | touch $*/build/unpack-stamp | |
398 | ||
399 | $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,configure)): \ | |
400 | $(call pkg-stamp,%,configure): \ | |
401 | $(call pkg-stamp,%,unpack) \ | |
402 | $$(foreach p, $$($$*_DEPS), $$(DEP_$$p)) | |
403 | $(call v_tag,CONFIG)cd $(dir $@) && \ | |
404 | ../configure --prefix=$(HOME) \ | |
405 | PKG_CONFIG_PATH=$(HOME)/lib/pkgconfig \ | |
406 | $($*_CONFIG) >>buildlog 2>&1 && \ | |
407 | touch configure-stamp | |
408 | ||
409 | $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,build)): \ | |
410 | $(call pkg-stamp,%,build): \ | |
411 | $(call pkg-stamp,%,configure) | |
412 | $(call v_tag,BUILD)cd $(dir $@) && \ | |
413 | $(MAKE) $($*_MAKEFLAGS) >>buildlog 2>&1 && \ | |
414 | touch build-stamp | |
415 | ||
416 | $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,install)): \ | |
417 | $(call pkg-stamp,%,install): \ | |
418 | $(call pkg-stamp,%,build) | |
419 | $(call v_tag,INSTALL)cd $(dir $@) && \ | |
420 | $(MAKE) $($*_MAKEFLAGS) install >>buildlog 2>&1 && \ | |
421 | touch install-stamp | |
f6c3a80b | 422 | $(package-hook/$*) |
67b1a15a MW |
423 | |
424 | all:: $(foreach p, $(PACKAGES), $(DEP_$p)) | |
425 | $(foreach p, $(PACKAGES), $(eval _pkg.$p: $(call pkg-stamp,$p,install))) | |
426 | ||
427 | ###----- That's all, folks -------------------------------------------------- |