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