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