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