chiark / gitweb /
Makefile: Zap Zsh's secret `~/.zcompdump' file if `.zshrc' is newer.
[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 all::
166         $(V_AT)if [ $(HOME)/.zcompdump -ot dot/zshrc ]; then \
167           $(call v_print,ZAP,$(HOME)/.zcompdump)rm -f $(HOME)/.zcompdump; \
168         fi
169
170 ## The Plan 9 `rc' shell.  This needs special hacking, because the Linux port
171 ## and Plan 9 From User Space have incompatible syntax.
172 DOTLINKS                += lib/profile
173 lib/profile_SRC          = rcrc
174 all:: $(HOME)/.rcrc
175 $(HOME)/.rcrc: dot/rcrc
176         $(call v_tag,SED)sed 's/; if not/else/' $< >$@.new && mv $@.new $@
177
178 ## Git.
179 DOTSUBST                += .gitconfig
180 SCRIPTLINKS             += git-copyright-dates
181 DOTLINKS                += .cgrc .tigrc
182 .gitconfig_SUBSTS        = \
183         $(call substvar,releasekey,$(call mdw-conf,release-key,481334C2))
184 $(HOME)/.gitconfig: $(HOME)/.mdw.conf
185
186 ## PulseAudio.
187 DOTLINKS                += .pulse/daemon.conf
188 DOTSUBST                += .pulse/default.pa
189 .pulse/daemon.conf_SRC   = pulse-daemon.conf
190 .pulse/default.pa_SRC    = pulse-default.pa.in
191
192 ## Other editors.
193 DOTLINKS                += .vimrc .mg .zile
194
195 ## Mail.
196 DOTLINKS                += .mailrc .signature .muttrc
197
198 ## Lisp.
199 DOTLINKS                += .cmucl-init.lisp .sbclrc .clisprc.lisp .eclrc
200 .cmucl-init.lisp_SRC     = lisp-init.lisp
201 .sbclrc_SRC              = lisp-init.lisp
202 .clisprc.lisp_SRC        = lisp-init.lisp
203 .eclrc_SRC               = lisp-init.lisp
204 DOTLINKS                += .swank.lisp
205
206 ## IPython.
207 DOTLINKS                += .ipython/profile_default/ipython_config.py
208 DOTLINKS                += .ipython/profile_default/startup/50-key-bindings.py
209 .ipython/profile_default/ipython_config.py_SRC = ipython-config.py
210 .ipython/profile_default/startup/50-key-bindings.py_SRC = ipython-key-bindings.py
211
212 ## Other languages.
213 DOTLINKS                += .guile
214 DOTLINKS                += .tclshrc .wishrc
215 .tclshrc_SRC             = tclshrc
216 .wishrc_SRC              = tclshrc
217
218 ## Random scripts.
219 SCRIPTLINKS             += mdw-editor mdw-pager
220 SCRIPTLINKS             += mdw-conf
221 SCRIPTLINKS             += svnwrap
222 SCRIPTLINKS             += guest-console
223 SCRIPTLINKS             += hyperspec
224
225 ## Random odds and ends.
226 DOTLINKS                += .lesskey .infokey .sqliterc
227 DOTLINKS                += .gdbinit .toprc .aspell.conf
228 DOTLINKS                += .dircolors .colordiffrc .screenrc .tmux.conf
229 DOTLINKS                += .cvsrc .indent.pro .ditz-config
230 DOTLINKS                += .lftp/rc
231 .lftp/rc_SRC             = lftp-rc
232 DOTSUBST                += .mykermrc
233 SCRIPTLINKS             += lesspipe.sh
234
235 SCRIPTLINKS             += run-with-shell-env
236 SCRIPTLINKS             += start-ssh-agent start-ssh-pageant
237 SCRIPTLINKS             += add-ssh-keys
238 SCRIPTLINKS             += hacks/ssh/ssh
239 hacks/ssh/ssh_SRC        = hacks/ssh
240
241 DOTLINKS                += .w3m/config .elinks/elinks.conf
242 .w3m/config_SRC          = w3m-config
243 .elinks/elinks.conf_SRC  = elinks.conf
244
245 DOTLINKS                += .mc/ini .mc/panels.ini
246 .mc/ini_SRC              = mc-ini
247 .mc/panels.ini_SRC       = mc-panels.ini
248
249 DOTLINKS                += .parallel/config
250 .parallel/config_SRC     = parallel-config
251
252 ###--------------------------------------------------------------------------
253 ### X11 configuration.
254
255 ifeq ($X,t)
256
257 PACKAGES                += xtoys
258 xtoys_CHECK              = xatom
259 xtoys_DEPS               = mlib
260
261 DOTLINKS                += .xinitrc .xsession .xmodmap .vncrc .vncsession
262 DOTLINKS                += .fonts.conf
263 DOTLINKS                += .stalonetrayrc
264
265 DOTLINKS                += .putty/sessions/Default%20Settings
266 .putty/sessions/Default%20Settings_SRC = putty-defaults
267
268 DOTLINKS                += .config/gnome-session/sessions/mdw.session
269 .config/gnome-session/sessions/mdw.session_SRC = mdw.session
270
271 DOTLINKS                += .Eterm/themes/Eterm/theme.cfg
272 DOTLINKS                += .enlightenment/keybindings.cfg
273 DOTLINKS                += .enlightenment-vnc/keybindings.cfg
274 DOTLINKS                += .e16/bindings.cfg
275 .Eterm/themes/Eterm/theme.cfg_SRC = eterm-theme.cfg
276 .enlightenment/keybindings.cfg_SRC = e-keybindings.cfg
277 .enlightenment-vnc/keybindings.cfg_SRC = evnc-keybindings.cfg
278 .e16/bindings.cfg_SRC    = e16-bindings
279
280 DOTLINKS                += .gtkrc-2.0
281 DOTLINKS                += .config/gtk-3.0/gtk.css
282 DOTLINKS                += .config/gtk-3.0/settings.ini
283 .config/gtk-3.0/gtk.css_SRC = gtk3.css
284 .config/gtk-3.0/settings.ini_SRC = gtk3-settings.ini
285
286 SCRIPTLINKS             += xinitcmd lock-screen xshutdown
287 SCRIPTLINKS             += un-backslashify-selection
288 SCRIPTLINKS             += xpra-start-xdummy
289 SCRIPTLINKS             += play-rawk
290 SCRIPTLINKS             += media-keys
291 SCRIPTLINKS             += disorder-notify
292
293 DOTCPP                  += .Xdefaults
294 Xdefaults_DEFS           = -DEMACSWD=$(call mdw-conf,emacs-width,77)
295 $(HOME)/.Xdefaults: $(HOME)/.mdw.conf
296
297 ifeq ($(shell case $${DISPLAY-nil} in (:[0-9]*) echo t ;; (*) echo nil ;; esac),t)
298 dotfile-hook/.Xdefaults = \
299         $(call v_tag,XRDB)xrdb -override $<
300 endif
301
302 endif
303
304 ###--------------------------------------------------------------------------
305 ### Processing dotfiles.
306
307 dotfile-source           = $(HERE)/dot/$(or $($1_SRC), $(1:.%=%)$2)
308
309 ## Easiest: just make symlinks.
310 dotlink-ok-p             = \
311         $(call symlink-ok-p,$(HOME)/$1,$(call dotfile-source,$1))
312 all:: $(addprefix $(HOME)/, $(DOTLINKS))
313 $(addprefix $(HOME)/, $(subst %,\%,$(DOTLINKS))): $(HOME)/%: \
314                 $$(if $$(call dotlink-ok-p,$$*),,_force)
315         $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
316                 rm -f $@.new && \
317                 ln -s $(call dotfile-source,$*) $@.new && \
318                 mv $@.new $@
319         $(dotfile-hook/$*)
320
321 ## Hack with the C preprocessor.
322 all:: $(addprefix $(HOME)/, $(DOTCPP))
323 $(addprefix $(HOME)/, $(subst %,\%,$(DOTCPP))): $(HOME)/%: \
324                 $$(call dotfile-source,$$*) Makefile
325         $(call v_tag,CPP)mkdir -p $(dir $@) && \
326                 rm -f $@.new && \
327                 cpp -P -o$@.new $($*_DEFS) $< && \
328                 mv $@.new $@
329         $(dotfile-hook/$*)
330
331 ## Hack by making simple substitutions.
332 substvar                 = -e $(call quote,s\a@$1@\a$2\ag)
333 SUBSTS                  += $(call substvar,home,$(HOME))
334 SUBSTS                  += $(call substvar,profile,$(HERE))
335 all:: $(addprefix $(HOME)/, $(DOTSUBST))
336 $(addprefix $(HOME)/, $(subst %,\%,$(DOTSUBST))): $(HOME)/%: \
337                 $$(call dotfile-source,$$*,.in) Makefile
338         $(call v_tag,SUBST)mkdir -p $(dir $@) && \
339                 rm -f $@.new && \
340                 sed -e "1i\
341 $(relax)### generated by $(HERE)/Makefile; do not edit!" \
342                         $(SUBSTS) $($*_SUBSTS) \
343                         $(call dotfile-source,$*,.in) >$@.new && \
344                 mv $@.new $@
345         $(dotfile-hook/$*)
346
347 ###--------------------------------------------------------------------------
348 ### Processing script links.
349
350 script-source            = $(HERE)/bin/$(or $($1_SRC), $1)
351
352 ifeq ($(prefix-shebang-p),t)
353 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
354 $(addprefix $(HOME)/bin/, $(SCRIPTLINKS)): $(HOME)/bin/%: \
355                 $$(call script-source,$$*) Makefile
356         $(call v_tag,SHEBANG)mkdir -p $(dir $@) && \
357                 rm -f $@.new && \
358                 sed "1s\a\(#! *\)/\a\1$(SHEBANG_PREFIX)/\a" \
359                         $(call script-source,$*) >$@.new && \
360                 chmod --reference=$(call script-source,$*) $@.new && \
361                 mv $@.new $@
362         $(script-hook/$*)
363 else
364 scriptlink-ok-p          = \
365         $(call symlink-ok-p,$(HOME)/bin/$1,$(call script-source,$1))
366 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
367 $(addprefix $(HOME)/bin/, $(SCRIPTLINKS)): $(HOME)/bin/%: \
368                 $$(if $$(call scriptlink-ok-p,$$*),,_force)
369         $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
370                 rm -f $@.new && \
371                 ln -s $(call script-source,$*) $@.new && \
372                 mv $@.new $@
373         $(script-hook/$*)
374 endif
375
376 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
377
378 ###--------------------------------------------------------------------------
379 ### Building packages from source tarballs.
380
381 SRCDIR                   = $(HOME)/src/profile
382
383 pkg-builddir             = $(SRCDIR)/$1/build
384 pkg-stamp                = $(call pkg-builddir,$1)/$2-stamp
385
386 $(foreach p, $(PACKAGES), $(eval DEP_$p = $(if $(shell \
387         if $($p_CHECK) >/dev/null 2>&1 --version; then echo t; fi),, \
388         $(call pkg-stamp,$p,install))))
389
390 $(PACKAGES:%=$(SRCDIR)/%.tar.gz): $(SRCDIR)/%.tar.gz:
391         $(call v_tag,FETCH)mkdir -p $(SRCDIR) && \
392                 rm -f $@.new && \
393                 $(call get-url,$@.new,$(REPO)/$*.tar.gz) && \
394                 mv $@.new $@
395
396 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,unpack)): \
397                 $(call pkg-stamp,%,unpack): $(SRCDIR)/%.tar.gz
398         $(call v_tag,EXTRACT)rm -rf $(SRCDIR)/$* && \
399                 mkdir $(SRCDIR)/$*.tmp-unpack && \
400                 cd $(SRCDIR)/$*.tmp-unpack && \
401                 gzip -cd ../$*.tar.gz | tar xf - && \
402                 mv * ../$* && \
403                 cd .. && \
404                 rmdir $*.tmp-unpack && \
405                 mkdir $*/build && \
406                 touch $*/build/unpack-stamp
407
408 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,configure)): \
409                 $(call pkg-stamp,%,configure): \
410                 $(call pkg-stamp,%,unpack) \
411                 $$(foreach p, $$($$*_DEPS), $$(DEP_$$p))
412         $(call v_tag,CONFIG)cd $(dir $@) && \
413                 ../configure --prefix=$(HOME) \
414                         PKG_CONFIG_PATH=$(HOME)/lib/pkgconfig \
415                         $($*_CONFIG) >>buildlog 2>&1 && \
416                 touch configure-stamp
417
418 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,build)): \
419                 $(call pkg-stamp,%,build): \
420                 $(call pkg-stamp,%,configure)
421         $(call v_tag,BUILD)cd $(dir $@) && \
422                 $(MAKE) $($*_MAKEFLAGS) >>buildlog 2>&1 && \
423                 touch build-stamp
424
425 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,install)): \
426                 $(call pkg-stamp,%,install): \
427                 $(call pkg-stamp,%,build)
428         $(call v_tag,INSTALL)cd $(dir $@) && \
429                 $(MAKE) $($*_MAKEFLAGS) install >>buildlog 2>&1 && \
430                 touch install-stamp
431         $(package-hook/$*)
432
433 all:: $(foreach p, $(PACKAGES), $(DEP_$p))
434 $(foreach p, $(PACKAGES), $(eval _pkg.$p: $(call pkg-stamp,$p,install)))
435
436 ###----- That's all, folks --------------------------------------------------