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