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