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