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.
24 v_tag = $(call v_tag_$V,$1)
25 v_tag_0 = @printf " %-8s %s\n" "$1" $(call quote,$@);
32 ###--------------------------------------------------------------------------
35 ## Figure out where I am.
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
42 get-url = wget -q -O $1 $2
45 ## Which Emacs should I use?
48 for i in emacs24 emacs23 emacs22 emacs21 emacs; do \
49 if type >/dev/null 2>&1 $$i; then emacs=$$i; break; fi; \
53 ## Whence to obtain externally hosted stuff.
54 REPO = https://ftp.distorted.org.uk/u/mdw/profile
56 ## Additional local configuration.
59 ###--------------------------------------------------------------------------
60 ### Some utility rules.
65 ###--------------------------------------------------------------------------
70 EMACSLIB = $(HOME)/lib/emacs
72 EMACS_VERSION := $(shell $(EMACS) 2>&1 -Q --batch --eval \
73 '(message "%s %s" emacs-major-version emacs-minor-version)' | \
75 emacs-version-p = $(shell set -- $(EMACS_VERSION); \
76 if [ $$1 -gt $1 ] || ([ $$1 -eq $1 ] && [ $$2 -ge $2 ]); then \
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
85 ifeq ($(call emacs-version-p,24,3),t)
86 ELISP += bracketed-paste
90 dot-emacs_DEPS = make-regexp
92 SCRIPTLINKS += emacsclient-hack movemail-hack sendmail-hack
93 SCRIPTLINKS += aspell-hack emerge-hack
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; \
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) && \
110 ln -s $(HERE)/$< $@.new && \
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 \
120 (kill-emacs (condition-case nil \
121 (progn (load-library "$e") 0) \
122 (error 1))))'; then \
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)/$*) && \
130 DOTLINKS += .emacs .emacs-calc .vm .gnus.el .ercrc.el
132 all:: $(foreach e, $(ELISP), $(DEP_$e))
133 $(foreach e, $(ELISP), $(eval _emacs.$e: $(EMACSLIB)/$e.elc))
137 ###--------------------------------------------------------------------------
138 ### Other simpler things.
141 $(call v_tag,COPY)cp mdw.conf $@.new && mv $@.new $@
144 PACKAGES += mlib checkpath
145 mlib_CHECK = crc-mktab
146 checkpath_CHECK = tmpdir
147 checkpath_DEPS = mlib
149 ## Packaging machinery.
150 SCRIPTLINKS += mdw-build mdw-sbuild mdw-sbuild-server
151 SCRIPTLINKS += update-buildable-branch
154 DOTLINKS += .profile .shell-rc .shell-logout
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
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
169 $(HOME)/.rcrc: dot/rcrc
170 $(call v_tag,SED)sed 's/; if not/else/' $< >$@.new && mv $@.new $@
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
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
187 DOTLINKS += .vimrc .mg .zile
190 DOTLINKS += .mailrc .signature .muttrc
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
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
208 DOTLINKS += .tclshrc .wishrc
209 .tclshrc_SRC = tclshrc
210 .wishrc_SRC = tclshrc
213 SCRIPTLINKS += mdw-editor mdw-pager
214 SCRIPTLINKS += mdw-conf
215 SCRIPTLINKS += svnwrap
216 SCRIPTLINKS += guest-console
217 SCRIPTLINKS += hyperspec
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
225 .lftp/rc_SRC = lftp-rc
226 DOTSUBST += .mykermrc
227 SCRIPTLINKS += lesspipe.sh
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
235 DOTLINKS += .w3m/config .elinks/elinks.conf
236 .w3m/config_SRC = w3m-config
237 .elinks/elinks.conf_SRC = elinks.conf
239 DOTLINKS += .mc/ini .mc/panels.ini
241 .mc/panels.ini_SRC = mc-panels.ini
243 DOTLINKS += .parallel/config
244 .parallel/config_SRC = parallel-config
246 ###--------------------------------------------------------------------------
247 ### X11 configuration.
255 DOTLINKS += .xinitrc .xsession .xmodmap .vncrc .vncsession
256 DOTLINKS += .fonts.conf
257 DOTLINKS += .stalonetrayrc
259 DOTLINKS += .putty/sessions/Default%20Settings
260 .putty/sessions/Default%20Settings_SRC = putty-defaults
262 DOTLINKS += .config/gnome-session/sessions/mdw.session
263 .config/gnome-session/sessions/mdw.session_SRC = mdw.session
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
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
280 SCRIPTLINKS += xinitcmd lock-screen xshutdown
281 SCRIPTLINKS += un-backslashify-selection
282 SCRIPTLINKS += xpra-start-xdummy
283 SCRIPTLINKS += play-rawk
284 SCRIPTLINKS += media-keys
285 SCRIPTLINKS += disorder-notify
288 Xdefaults_DEFS = -DEMACSWD=$(call mdw-conf,emacs-width,77)
289 $(HOME)/.Xdefaults: $(HOME)/.mdw.conf
291 ifeq ($(shell case $${DISPLAY-nil} in (:[0-9]*) echo t ;; (*) echo nil ;; esac),t)
292 dotfile-hook/.Xdefaults = \
293 $(call v_tag,XRDB)xrdb -override $<
298 ###--------------------------------------------------------------------------
299 ### Processing dotfiles.
301 dotfile-source = $(HERE)/dot/$(or $($1_SRC), $(1:.%=%)$2)
303 ## Easiest: just make symlinks.
305 $(call symlink-ok-p,$(HOME)/$1,$(call dotfile-source,$1))
306 all:: $(addprefix $(HOME)/, $(DOTLINKS))
307 $(addprefix $(HOME)/, $(subst %,\%,$(DOTLINKS))): $(HOME)/%: \
308 $$(if $$(call dotlink-ok-p,$$*),,_force)
309 $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
311 ln -s $(call dotfile-source,$*) $@.new && \
315 ## Hack with the C preprocessor.
316 all:: $(addprefix $(HOME)/, $(DOTCPP))
317 $(addprefix $(HOME)/, $(subst %,\%,$(DOTCPP))): $(HOME)/%: \
318 $$(call dotfile-source,$$*) Makefile
319 $(call v_tag,CPP)mkdir -p $(dir $@) && \
321 cpp -P -o$@.new $($*_DEFS) $< && \
325 ## Hack by making simple substitutions.
326 substvar = -e $(call quote,s
\a@$1@
\a$2
\ag)
327 SUBSTS += $(call substvar,home,$(HOME))
328 SUBSTS += $(call substvar,profile,$(HERE))
329 all:: $(addprefix $(HOME)/, $(DOTSUBST))
330 $(addprefix $(HOME)/, $(subst %,\%,$(DOTSUBST))): $(HOME)/%: \
331 $$(call dotfile-source,$$*,.in) Makefile
332 $(call v_tag,SUBST)mkdir -p $(dir $@) && \
335 $(relax)### generated by $(HERE)/Makefile; do not edit!" \
336 $(SUBSTS) $($*_SUBSTS) \
337 $(call dotfile-source,$*,.in) >$@.new && \
341 ###--------------------------------------------------------------------------
342 ### Processing script links.
344 script-source = $(HERE)/bin/$(or $($1_SRC), $1)
346 ifeq ($(prefix-shebang-p),t)
347 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
348 $(addprefix $(HOME)/bin/, $(SCRIPTLINKS)): $(HOME)/bin/%: \
349 $$(call script-source,$$*) Makefile
350 $(call v_tag,SHEBANG)mkdir -p $(dir $@) && \
352 sed "1s
\a\(#! *\)/
\a\1$(SHEBANG_PREFIX)/
\a" \
353 $(call script-source,$*) >$@.new && \
354 chmod --reference=$(call script-source,$*) $@.new && \
359 $(call symlink-ok-p,$(HOME)/bin/$1,$(call script-source,$1))
360 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
361 $(addprefix $(HOME)/bin/, $(SCRIPTLINKS)): $(HOME)/bin/%: \
362 $$(if $$(call scriptlink-ok-p,$$*),,_force)
363 $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
365 ln -s $(call script-source,$*) $@.new && \
370 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
372 ###--------------------------------------------------------------------------
373 ### Building packages from source tarballs.
375 SRCDIR = $(HOME)/src/profile
377 pkg-builddir = $(SRCDIR)/$1/build
378 pkg-stamp = $(call pkg-builddir,$1)/$2-stamp
380 $(foreach p, $(PACKAGES), $(eval DEP_$p = $(if $(shell \
381 if $($p_CHECK) >/dev/null 2>&1 --version; then echo t; fi),, \
382 $(call pkg-stamp,$p,install))))
384 $(PACKAGES:%=$(SRCDIR)/%.tar.gz): $(SRCDIR)/%.tar.gz:
385 $(call v_tag,FETCH)mkdir -p $(SRCDIR) && \
387 $(call get-url,$@.new,$(REPO)/$*.tar.gz) && \
390 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,unpack)): \
391 $(call pkg-stamp,%,unpack): $(SRCDIR)/%.tar.gz
392 $(call v_tag,EXTRACT)rm -rf $(SRCDIR)/$* && \
393 mkdir $(SRCDIR)/$*.tmp-unpack && \
394 cd $(SRCDIR)/$*.tmp-unpack && \
395 gzip -cd ../$*.tar.gz | tar xf - && \
398 rmdir $*.tmp-unpack && \
400 touch $*/build/unpack-stamp
402 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,configure)): \
403 $(call pkg-stamp,%,configure): \
404 $(call pkg-stamp,%,unpack) \
405 $$(foreach p, $$($$*_DEPS), $$(DEP_$$p))
406 $(call v_tag,CONFIG)cd $(dir $@) && \
407 ../configure --prefix=$(HOME) \
408 PKG_CONFIG_PATH=$(HOME)/lib/pkgconfig \
409 $($*_CONFIG) >>buildlog 2>&1 && \
410 touch configure-stamp
412 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,build)): \
413 $(call pkg-stamp,%,build): \
414 $(call pkg-stamp,%,configure)
415 $(call v_tag,BUILD)cd $(dir $@) && \
416 $(MAKE) $($*_MAKEFLAGS) >>buildlog 2>&1 && \
419 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,install)): \
420 $(call pkg-stamp,%,install): \
421 $(call pkg-stamp,%,build)
422 $(call v_tag,INSTALL)cd $(dir $@) && \
423 $(MAKE) $($*_MAKEFLAGS) install >>buildlog 2>&1 && \
427 all:: $(foreach p, $(PACKAGES), $(DEP_$p))
428 $(foreach p, $(PACKAGES), $(eval _pkg.$p: $(call pkg-stamp,$p,install)))
430 ###----- That's all, folks --------------------------------------------------