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