4 .SECONDEXPANSION: #sorry
6 ###--------------------------------------------------------------------------
10 quote = '$(subst ','\'',$1)'#'
12 ## Suss out how to print stuff.
13 print = printf "%s" $(call quote,$1)
15 ## Looking configuration things up.
16 mdw-conf = $(shell bin/mdw-conf "$1" "$2")
18 ## Checking symlink targets.
19 symlink-ok-p = $(shell \
20 case $$(readlink 2>/dev/null $1) in ($2) echo t ;; esac)
22 ## Silent rules machinery.
26 v_print = $(call v_print_$V,$1,$2)
28 printf " %-8s %s\n" "$1" $(call quote,$(patsubst $(HOME)/%,~/%,$2));
29 v_tag = $(V_AT)$(call v_print_$V,$1,$@)
34 ###--------------------------------------------------------------------------
37 ## Figure out where I am.
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
44 get-url = wget -q -O $1 $2
47 ## Which Emacs should I use?
50 for i in emacs24 emacs23 emacs22 emacs21 emacs; do \
51 if type >/dev/null 2>&1 $$i; then emacs=$$i; break; fi; \
55 ## Whence to obtain externally hosted stuff.
56 REPO = https://ftp.distorted.org.uk/u/mdw/profile
58 ## Additional local configuration.
61 ###--------------------------------------------------------------------------
62 ### Some utility rules.
67 ###--------------------------------------------------------------------------
72 EMACSLIB = $(HOME)/lib/emacs
74 EMACS_VERSION := $(shell $(EMACS) 2>&1 -Q --batch --eval \
75 '(message "%s %s" emacs-major-version emacs-minor-version)' | \
77 emacs-version-p = $(shell set -- $(EMACS_VERSION); \
78 if [ $$1 -gt $1 ] || ([ $$1 -eq $1 ] && [ $$2 -ge $2 ]); then \
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
87 ifeq ($(call emacs-version-p,24,3),t)
88 ELISP += bracketed-paste
92 dot-emacs_DEPS = make-regexp
94 SCRIPTLINKS += emacsclient-hack movemail-hack sendmail-hack
95 SCRIPTLINKS += aspell-hack emerge-hack wakey.sh
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; \
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) && \
112 ln -s $(HERE)/$< $@.new && \
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 \
122 (kill-emacs (condition-case nil \
123 (progn (load-library "$e") 0) \
124 (error 1))))'; then \
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)/$*) && \
132 DOTLINKS += .emacs .emacs-calc .vm .gnus.el .ercrc.el
134 all:: $(foreach e, $(ELISP), $(DEP_$e))
135 $(foreach e, $(ELISP), $(eval _emacs.$e: $(EMACSLIB)/$e.elc))
139 ###--------------------------------------------------------------------------
140 ### Other simpler things.
143 $(call v_tag,COPY)cp mdw.conf $@.new && mv $@.new $@
146 PACKAGES += mlib checkpath
147 mlib_CHECK = crc-mktab
148 checkpath_CHECK = tmpdir
149 checkpath_DEPS = mlib
151 ## Packaging machinery.
152 SCRIPTLINKS += mdw-build mdw-sbuild mdw-sbuild-server
153 SCRIPTLINKS += update-buildable-branch
154 DOTLINKS += .config/mdw-build.conf
155 .config/mdw-build.conf_SRC = mdw-build.conf
158 DOTLINKS += .profile .shell-rc .shell-logout
160 DOTLINKS += .zprofile .zshrc .zlogout .zshenv
161 DOTLINKS += .bash_profile .bash_completion .bash_logout
162 DOTLINKS += .bashrc .inputrc
163 .bash_profile_SRC = bash-profile
164 .bash_completion_SRC = bash-completion
165 .bash_logout_SRC = shell-logout
166 .zlogout_SRC = shell-logout
169 $(V_AT)if [ $(HOME)/.zcompdump -ot dot/zshrc ]; then \
170 $(call v_print,ZAP,$(HOME)/.zcompdump)rm -f $(HOME)/.zcompdump; \
173 ## The Plan 9 `rc' shell. This needs special hacking, because the Linux port
174 ## and Plan 9 From User Space have incompatible syntax.
175 DOTLINKS += lib/profile
176 lib/profile_SRC = rcrc
178 $(HOME)/.rcrc: dot/rcrc
179 $(call v_tag,SED)sed 's/; if not/else/' $< >$@.new && mv $@.new $@
182 DOTSUBST += .gitconfig
183 SCRIPTLINKS += git-copyright-dates
184 DOTLINKS += .cgrc .tigrc
185 .gitconfig_SUBSTS = \
186 $(call substvar,releasekey,$(call mdw-conf,releasekey,481334C2)) \
187 $(call substvar,email,$(call mdw-conf,email,mdw@distorted.org.uk))
188 $(HOME)/.gitconfig: $(HOME)/.mdw.conf
191 DOTLINKS += .pulse/daemon.conf
192 DOTSUBST += .pulse/default.pa
193 .pulse/daemon.conf_SRC = pulse-daemon.conf
194 .pulse/default.pa_SRC = pulse-default.pa.in
197 DOTLINKS += .vimrc .mg .zile
200 DOTLINKS += .mailrc .signature .muttrc
203 DOTLINKS += .cmucl-init.lisp .sbclrc .clisprc.lisp .eclrc
204 .cmucl-init.lisp_SRC = lisp-init.lisp
205 .sbclrc_SRC = lisp-init.lisp
206 .clisprc.lisp_SRC = lisp-init.lisp
207 .eclrc_SRC = lisp-init.lisp
208 DOTLINKS += .swank.lisp
211 DOTLINKS += .ipython/profile_default/ipython_config.py
212 DOTLINKS += .ipython/profile_default/startup/50-key-bindings.py
213 .ipython/profile_default/ipython_config.py_SRC = ipython-config.py
214 .ipython/profile_default/startup/50-key-bindings.py_SRC = ipython-key-bindings.py
218 DOTLINKS += .tclshrc .wishrc
219 .tclshrc_SRC = tclshrc
220 .wishrc_SRC = tclshrc
223 SCRIPTLINKS += disorder-switch-config
224 SCRIPTLINKS += disorder-propagate-autoplay
227 SCRIPTLINKS += mdw-editor mdw-pager
228 SCRIPTLINKS += mdw-conf
229 SCRIPTLINKS += svnwrap
230 SCRIPTLINKS += guest-console
231 SCRIPTLINKS += hyperspec
233 SCRIPTLINKS += datasyms
234 SCRIPTLINKS += fixsub
235 SCRIPTLINKS += check-debsyms
236 SCRIPTLINKS += check-blkdev-size
238 ## Random odds and ends.
239 DOTLINKS += .infokey .sqliterc
240 DOTLINKS += .gdbinit .toprc .aspell.conf
241 DOTLINKS += .dircolors .colordiffrc .screenrc .tmux.conf
242 DOTLINKS += .cvsrc .indent.pro .ditz-config
244 .lftp/rc_SRC = lftp-rc
245 DOTSUBST += .mykermrc
246 SCRIPTLINKS += lesspipe.sh
248 SCRIPTLINKS += run-with-shell-env
249 SCRIPTLINKS += start-ssh-agent start-ssh-pageant
250 SCRIPTLINKS += add-ssh-keys
251 SCRIPTLINKS += hacks/ssh/ssh
252 hacks/ssh/ssh_SRC = hacks/ssh
254 DOTLINKS += .w3m/config .elinks/elinks.conf
255 .w3m/config_SRC = w3m-config
256 .elinks/elinks.conf_SRC = elinks.conf
258 DOTLINKS += .mc/ini .mc/panels.ini
260 .mc/panels.ini_SRC = mc-panels.ini
262 DOTLINKS += .parallel/config .parallel/sshloginfile
263 .parallel/config_SRC = parallel-config
264 .parallel/sshloginfile_SRC = parallel-hosts
267 $(HOME)/.less: dot/lesskey
268 $(V_AT)rm -f $(HOME)/.lesskey
269 $(call v_tag,LESSKEY)lesskey -o$@ $<
271 ###--------------------------------------------------------------------------
272 ### X11 configuration.
280 DOTLINKS += .xinitrc .xsession .xmodmap .vncrc .vncsession
281 DOTLINKS += .config/fontconfig/fonts.conf
282 .config/fontconfig/fonts.conf_SRC = fonts.conf
283 DOTLINKS += .stalonetrayrc
285 DOTLINKS += .config/gnome-session/sessions/mdw.session
286 .config/gnome-session/sessions/mdw.session_SRC = mdw.session
288 DOTLINKS += .Eterm/themes/Eterm/theme.cfg
289 DOTLINKS += .enlightenment/keybindings.cfg
290 DOTLINKS += .enlightenment-vnc/keybindings.cfg
291 DOTLINKS += .e16/bindings.cfg
292 .Eterm/themes/Eterm/theme.cfg_SRC = eterm-theme.cfg
293 .enlightenment/keybindings.cfg_SRC = e-keybindings.cfg
294 .enlightenment-vnc/keybindings.cfg_SRC = evnc-keybindings.cfg
295 .e16/bindings.cfg_SRC = e16-bindings
297 DOTLINKS += .gtkrc-2.0
298 DOTLINKS += .config/gtk-3.0/gtk.css
299 DOTLINKS += .config/gtk-3.0/settings.ini
300 .config/gtk-3.0/gtk.css_SRC = gtk3.css
301 .config/gtk-3.0/settings.ini_SRC = gtk3-settings.ini
303 DOTLINKS += .config/user-dirs.dirs .config/user-dirs.locale
304 .config/user-dirs.dirs_SRC = user-dirs.dirs
305 .config/user-dirs.locale_SRC = user-dirs.locale
307 SCRIPTLINKS += xinitcmd lock-screen xshutdown
308 SCRIPTLINKS += un-backslashify-selection
309 SCRIPTLINKS += xpra-start-xdummy
310 SCRIPTLINKS += play-rawk
311 SCRIPTLINKS += media-keys
312 SCRIPTLINKS += disorder-notify
313 SCRIPTLINKS += xduplic-terminal
316 Xdefaults_DEFS = -DEMACSWD=$(call mdw-conf,emacs-width,77)
317 $(HOME)/.Xdefaults: $(HOME)/.mdw.conf dot/Xdefaults.pterm
319 ifeq ($(shell case $${DISPLAY-nil} in (:[0-9]*) echo t ;; (*) echo nil ;; esac),t)
320 dotfile-hook/.Xdefaults = \
321 $(call v_tag,XRDB)xrdb -override $<
326 ###--------------------------------------------------------------------------
327 ### Processing dotfiles.
329 dotfile-source = $(HERE)/dot/$(or $($1_SRC), $(1:.%=%)$2)
331 ## Easiest: just make symlinks.
333 $(call symlink-ok-p,$(HOME)/$1,$(call dotfile-source,$1))
334 all:: $(addprefix $(HOME)/, $(DOTLINKS))
335 $(addprefix $(HOME)/, $(subst %,\%,$(DOTLINKS))): $(HOME)/%: \
336 $$(if $$(call dotlink-ok-p,$$*),,_force)
337 $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
339 ln -s $(call dotfile-source,$*) $@.new && \
343 ## Hack with the C preprocessor.
344 all:: $(addprefix $(HOME)/, $(DOTCPP))
345 $(addprefix $(HOME)/, $(subst %,\%,$(DOTCPP))): $(HOME)/%: \
346 $$(call dotfile-source,$$*) Makefile
347 $(call v_tag,CPP)mkdir -p $(dir $@) && \
349 cpp -P -o$@.new $($*_DEFS) $< && \
353 ## Hack by making simple substitutions.
354 substvar = -e $(call quote,s
\a@$1@
\a$2
\ag)
355 SUBSTS += $(call substvar,home,$(HOME))
356 SUBSTS += $(call substvar,profile,$(HERE))
357 all:: $(addprefix $(HOME)/, $(DOTSUBST))
358 $(addprefix $(HOME)/, $(subst %,\%,$(DOTSUBST))): $(HOME)/%: \
359 $$(call dotfile-source,$$*,.in) Makefile
360 $(call v_tag,SUBST)mkdir -p $(dir $@) && \
363 $(relax)### generated by $(HERE)/Makefile; do not edit!" \
364 $(SUBSTS) $($*_SUBSTS) \
365 $(call dotfile-source,$*,.in) >$@.new && \
369 ###--------------------------------------------------------------------------
370 ### Processing script links.
372 script-source = $(HERE)/bin/$(or $($1_SRC), $1)
374 ifeq ($(prefix-shebang-p),t)
375 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
376 $(addprefix $(HOME)/bin/, $(SCRIPTLINKS)): $(HOME)/bin/%: \
377 $$(call script-source,$$*) Makefile
378 $(call v_tag,SHEBANG)mkdir -p $(dir $@) && \
380 sed "1s
\a\(#! *\)/
\a\1$(SHEBANG_PREFIX)/
\a" \
381 $(call script-source,$*) >$@.new && \
382 chmod --reference=$(call script-source,$*) $@.new && \
387 $(call symlink-ok-p,$(HOME)/bin/$1,$(call script-source,$1))
388 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
389 $(addprefix $(HOME)/bin/, $(SCRIPTLINKS)): $(HOME)/bin/%: \
390 $$(if $$(call scriptlink-ok-p,$$*),,_force)
391 $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
393 ln -s $(call script-source,$*) $@.new && \
398 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
400 ###--------------------------------------------------------------------------
401 ### Building packages from source tarballs.
403 SRCDIR = $(HOME)/src/profile
405 pkg-builddir = $(SRCDIR)/$1/build
406 pkg-stamp = $(call pkg-builddir,$1)/$2-stamp
408 $(foreach p, $(PACKAGES), $(eval DEP_$p = $(if $(shell \
409 if $($p_CHECK) >/dev/null 2>&1 --version; then echo t; fi),, \
410 $(call pkg-stamp,$p,install))))
412 $(PACKAGES:%=$(SRCDIR)/%.tar.gz): $(SRCDIR)/%.tar.gz:
413 $(call v_tag,FETCH)mkdir -p $(SRCDIR) && \
415 $(call get-url,$@.new,$(REPO)/$*.tar.gz) && \
418 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,unpack)): \
419 $(call pkg-stamp,%,unpack): $(SRCDIR)/%.tar.gz
420 $(call v_tag,EXTRACT)rm -rf $(SRCDIR)/$* && \
421 mkdir $(SRCDIR)/$*.tmp-unpack && \
422 cd $(SRCDIR)/$*.tmp-unpack && \
423 gzip -cd ../$*.tar.gz | tar xf - && \
426 rmdir $*.tmp-unpack && \
428 touch $*/build/unpack-stamp
430 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,configure)): \
431 $(call pkg-stamp,%,configure): \
432 $(call pkg-stamp,%,unpack) \
433 $$(foreach p, $$($$*_DEPS), $$(DEP_$$p))
434 $(call v_tag,CONFIG)cd $(dir $@) && \
435 ../configure --prefix=$(HOME) \
436 PKG_CONFIG_PATH=$(HOME)/lib/pkgconfig \
437 $($*_CONFIG) >>buildlog 2>&1 && \
438 touch configure-stamp
440 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,build)): \
441 $(call pkg-stamp,%,build): \
442 $(call pkg-stamp,%,configure)
443 $(call v_tag,BUILD)cd $(dir $@) && \
444 $(MAKE) $($*_MAKEFLAGS) >>buildlog 2>&1 && \
447 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,install)): \
448 $(call pkg-stamp,%,install): \
449 $(call pkg-stamp,%,build)
450 $(call v_tag,INSTALL)cd $(dir $@) && \
451 $(MAKE) $($*_MAKEFLAGS) install >>buildlog 2>&1 && \
455 all:: $(foreach p, $(PACKAGES), $(DEP_$p))
456 $(foreach p, $(PACKAGES), $(eval _pkg.$p: $(call pkg-stamp,$p,install)))
458 ###----- That's all, folks --------------------------------------------------