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