chiark / gitweb /
dot/zshrc: Turn off `KSH_GLOB'.
[profile] / Makefile
CommitLineData
67b1a15a
MW
1## -*-makefile-*-
2
3all::
4.SECONDEXPANSION: #sorry
5
6###--------------------------------------------------------------------------
7### Utilities.
8
9##
10quote = '$(subst ','\'',$1)'#'
11
12## Suss out how to print stuff.
13print = printf "%s" $(call quote,$1)
14
15## Looking configuration things up.
16mdw-conf = $(shell bin/mdw-conf "$1" "$2")
17
18## Checking symlink targets.
19symlink-ok-p = $(shell \
20 case $$(readlink 2>/dev/null $1) in ($2) echo t ;; esac)
21
22## Silent rules machinery.
23V = 0
24v_tag = $(call v_tag_$V,$1,$2)
25v_tag_0 = @printf " %-8s %s\n" "$1" $(call quote,$@);
26V_AT = $(V_AT_$V)
27V_AT_0 = @
28
29## Hack.
30relax =
31
32###--------------------------------------------------------------------------
33### Configuration.
34
35## Figure out where I am.
36HERE = $(shell pwd)
37
38## Decide on how to fetch things from URLs.
39ifeq ($(shell (curl >/dev/null 2>&1 --version || [ $$? -eq 2 ]) && echo t),t)
40 get-url = curl -fs -o $1 $2
41else
42 get-url = wget -q -O $1 $2
43endif
44
45## Which Emacs should I use?
46EMACS := $(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.
53REPO = 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
67ifneq ($(EMACS),nil)
68
67b1a15a
MW
69EMACSLIB = $(HOME)/lib/emacs
70
486623cb 71EMACS_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
74emacs-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
79ELISP += make-regexp ew-hols
80ELISP += mdw-gnus-patch
81ELISP += mdw-multiple-cursors
82ELISP += git git-blame vc-git stgit quilt
486623cb
MW
83
84ifeq ($(call emacs-version-p,24,3),t)
6369ae29 85ELISP += bracketed-paste
486623cb 86endif
67b1a15a 87
3e441da6
MW
88ELISP += dot-emacs
89dot-emacs_DEPS = make-regexp
90
67b1a15a
MW
91SCRIPTLINKS += emacsclient-hack movemail-hack sendmail-hack
92SCRIPTLINKS += 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
102LOCAL_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
112REMOTE_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
129DOTLINKS += .emacs .emacs-calc .vm .gnus.el .ercrc.el
130
131all:: $(foreach e, $(ELISP), $(DEP_$e))
6369ae29 132$(foreach e, $(ELISP), $(eval _emacs.$e: $(EMACSLIB)/$e.elc))
67b1a15a 133
967148ff
MW
134endif
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.
143PACKAGES += mlib checkpath
144mlib_CHECK = crc-mktab
145checkpath_CHECK = tmpdir
146checkpath_DEPS = mlib
147
148## Packaging machinery.
149SCRIPTLINKS += mdw-build mdw-sbuild mdw-sbuild-server
150SCRIPTLINKS += update-buildable-branch
151
152## Shells.
153DOTLINKS += .profile .shell-rc .shell-logout
a3857ab2 154DOTLINKS += .shrc
9ba9bb2f
MW
155DOTLINKS += .zprofile .zshrc .zlogout .zshenv
156DOTLINKS += .bash_profile .bash_completion .bash_logout
157DOTLINKS += .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.
165DOTLINKS += lib/profile
166lib/profile_SRC = rcrc
167all:: $(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.
172DOTSUBST += .gitconfig
2e15741e 173SCRIPTLINKS += git-copyright-dates
67b1a15a
MW
174DOTLINKS += .cgrc .tigrc
175.gitconfig_SUBSTS = \
176 $(call substvar,releasekey,$(call mdw-conf,release-key,481334C2))
177$(HOME)/.gitconfig: $(HOME)/.mdw.conf
178
179## PulseAudio.
180DOTLINKS += .pulse/daemon.conf
181DOTSUBST += .pulse/default.pa
182.pulse/daemon.conf_SRC = pulse-daemon.conf
183.pulse/default.pa_SRC = pulse-default.pa.in
184
185## Other editors.
186DOTLINKS += .vimrc .mg .zile
187
188## Mail.
189DOTLINKS += .mailrc .signature .muttrc
190
191## Lisp.
192DOTLINKS += .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
197DOTLINKS += .swank.lisp
198
199## IPython.
200DOTLINKS += .ipython/profile_default/ipython_config.py
201DOTLINKS += .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.
206DOTLINKS += .guile
207DOTLINKS += .tclshrc .wishrc
208.tclshrc_SRC = tclshrc
209.wishrc_SRC = tclshrc
210
211## Random scripts.
212SCRIPTLINKS += mdw-editor mdw-pager
213SCRIPTLINKS += mdw-conf
214SCRIPTLINKS += svnwrap
215SCRIPTLINKS += guest-console
216SCRIPTLINKS += hyperspec
217
218## Random odds and ends.
219DOTLINKS += .lesskey .infokey .sqliterc
220DOTLINKS += .gdbinit .toprc .aspell.conf
221DOTLINKS += .dircolors .colordiffrc .screenrc .tmux.conf
222DOTLINKS += .cvsrc .indent.pro .ditz-config
da526ba7
MW
223DOTLINKS += .lftp/rc
224.lftp/rc_SRC = lftp-rc
67b1a15a
MW
225DOTSUBST += .mykermrc
226SCRIPTLINKS += lesspipe.sh
227
228SCRIPTLINKS += run-with-shell-env
229SCRIPTLINKS += start-ssh-agent start-ssh-pageant
230SCRIPTLINKS += add-ssh-keys
231SCRIPTLINKS += hacks/ssh/ssh
232hacks/ssh/ssh_SRC = hacks/ssh
233
234DOTLINKS += .w3m/config .elinks/elinks.conf
235.w3m/config_SRC = w3m-config
236.elinks/elinks.conf_SRC = elinks.conf
237
238DOTLINKS += .mc/ini .mc/panels.ini
239.mc/ini_SRC = mc-ini
240.mc/panels.ini_SRC = mc-panels.ini
241
242DOTLINKS += .parallel/config
243.parallel/config_SRC = parallel-config
244
245###--------------------------------------------------------------------------
246### X11 configuration.
247
248ifeq ($X,t)
249
250PACKAGES += xtoys
251xtoys_CHECK = xatom
252xtoys_DEPS = mlib
253
254DOTLINKS += .xinitrc .xsession .xmodmap .vncrc .vncsession
255DOTLINKS += .fonts.conf
256DOTLINKS += .stalonetrayrc
257
258DOTLINKS += .putty/sessions/Default%20Settings
259.putty/sessions/Default%20Settings_SRC = putty-defaults
260
261DOTLINKS += .config/gnome-session/sessions/mdw.session
262.config/gnome-session/sessions/mdw.session_SRC = mdw.session
263
264DOTLINKS += .Eterm/themes/Eterm/theme.cfg
265DOTLINKS += .enlightenment/keybindings.cfg
266DOTLINKS += .enlightenment-vnc/keybindings.cfg
267DOTLINKS += .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
273DOTLINKS += .gtkrc-2.0
274DOTLINKS += .config/gtk-3.0/gtk.css
275DOTLINKS += .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
279SCRIPTLINKS += xinitcmd lock-screen xshutdown
280SCRIPTLINKS += un-backslashify-selection
281SCRIPTLINKS += xpra-start-xdummy
5f9b345a 282SCRIPTLINKS += play-rawk
67b1a15a
MW
283
284DOTCPP += .Xdefaults
285Xdefaults_DEFS = -DEMACSWD=$(call mdw-conf,emacs-width,77)
286$(HOME)/.Xdefaults: $(HOME)/.mdw.conf
287
ddc97f65
MW
288ifeq ($(shell case $${DISPLAY-nil} in (:[0-9]*) echo t ;; (*) echo nil ;; esac),t)
289dotfile-hook/.Xdefaults = \
290 $(call v_tag,XRDB)xrdb -override $<
291endif
292
67b1a15a
MW
293endif
294
295###--------------------------------------------------------------------------
296### Processing dotfiles.
297
298dotfile-source = $(HERE)/dot/$(or $($1_SRC), $(1:.%=%)$2)
299
4937ba2d 300## Easiest: just make symlinks.
67b1a15a
MW
301dotlink-ok-p = \
302 $(call symlink-ok-p,$(HOME)/$1,$(call dotfile-source,$1))
303all:: $(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.
313all:: $(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.
323substvar = -e $(call quote,s\a@$1@\a$2\ag)
324SUBSTS += $(call substvar,home,$(HOME))
325SUBSTS += $(call substvar,profile,$(HERE))
326all:: $(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
341script-source = $(HERE)/bin/$(or $($1_SRC), $1)
0cd3b798
MW
342
343ifeq ($(prefix-shebang-p),t)
344all:: $(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/$*)
354else
67b1a15a
MW
355scriptlink-ok-p = \
356 $(call symlink-ok-p,$(HOME)/bin/$1,$(call script-source,$1))
357all:: $(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 365endif
67b1a15a
MW
366
367all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
368
369###--------------------------------------------------------------------------
370### Building packages from source tarballs.
371
372SRCDIR = $(HOME)/src/profile
373
374pkg-builddir = $(SRCDIR)/$1/build
375pkg-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
424all:: $(foreach p, $(PACKAGES), $(DEP_$p))
425$(foreach p, $(PACKAGES), $(eval _pkg.$p: $(call pkg-stamp,$p,install)))
426
427###----- That's all, folks --------------------------------------------------