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