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