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