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