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,$2)
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 echo $$i; break; fi; \
52 ## Whence to obtain externally hosted stuff.
53 REPO = https://ftp.distorted.org.uk/u/mdw/profile
55 ## Additional local configuration.
58 ###--------------------------------------------------------------------------
59 ### Some utility rules.
64 ###--------------------------------------------------------------------------
69 EMACSLIB = $(HOME)/lib/emacs
71 ELISP += make-regexp ew-hols
72 ELISP += mdw-gnus-patch
73 ELISP += mdw-multiple-cursors
74 ELISP += git git-blame vc-git stgit quilt
75 ELISP += bracketed-paste
78 dot-emacs_DEPS = make-regexp
80 SCRIPTLINKS += emacsclient-hack movemail-hack sendmail-hack
81 SCRIPTLINKS += aspell-hack emerge-hack
83 %.elc: %.el $$(foreach e, $$($$*_DEPS), $$(DEP_$$e))
84 $(call v_tag,EMACS)if ! $(EMACS) >$*.build-log 2>&1 \
85 -L el/ -L $(EMACSLIB) \
86 --batch --no-site-file \
87 --eval '(byte-compile-file "$<")'; then \
88 cat $*.build-log; exit 2; \
91 LOCAL_ELISP = $(filter $(notdir $(wildcard el/*.el)), \
92 $(addsuffix .el, $(ELISP)))
93 $(foreach e, $(LOCAL_ELISP), \
94 $(eval DEP_$(basename $e) = $(EMACSLIB)/$(e:.el=.elc)))
95 $(addprefix $(EMACSLIB)/, $(LOCAL_ELISP)): $(EMACSLIB)/%: el/%
96 $(call v_tag,SYMINK)mkdir -p $(EMACSLIB) && \
98 ln -s $(HERE)/$< $@.new && \
101 REMOTE_ELISP = $(filter-out $(notdir $(wildcard el/*.el)), \
102 $(addsuffix .el, $(ELISP)))
103 $(foreach e, $(REMOTE_ELISP), \
104 $(eval DEP_$(basename $e) = $(if $(shell \
105 if $(EMACS) >/dev/null 2>&1 --no-site-file -q --batch \
108 (kill-emacs (condition-case nil \
109 (progn (load-library "$e") 0) \
110 (error 1))))'; then \
112 fi),, $(EMACSLIB)/$(e:.el=.elc))))
113 $(addprefix $(EMACSLIB)/, $(REMOTE_ELISP)): $(EMACSLIB)/%:
114 $(call v_tag,FETCH)mkdir -p $(EMACSLIB) && \
115 $(call get-url,$@.new,$(REPO)/$*) && \
118 DOTLINKS += .emacs .emacs-calc .vm .gnus.el .ercrc.el
120 all:: $(foreach e, $(ELISP), $(DEP_$e))
121 $(foreach e, $(ELISP), $(eval _emacs.$e: $(EMACSLIB)/$e.elc))
125 ###--------------------------------------------------------------------------
126 ### Other simpler things.
129 $(call v_tag,COPY)cp mdw.conf $@.new && mv $@.new $@
132 PACKAGES += mlib checkpath
133 mlib_CHECK = crc-mktab
134 checkpath_CHECK = tmpdir
135 checkpath_DEPS = mlib
137 ## Packaging machinery.
138 SCRIPTLINKS += mdw-build mdw-sbuild mdw-sbuild-server
139 SCRIPTLINKS += update-buildable-branch
142 DOTLINKS += .profile .shell-rc .shell-logout
143 DOTLINKS += .shrc .rcrc
144 DOTLINKS += .zprofile .zshrc .zshenv
145 DOTLINKS += .bash_profile .bash_completion .bashrc .inputrc
146 .bash_profile_SRC = bash-profile
147 .bash_completion_SRC = bash-completion
150 DOTSUBST += .gitconfig
151 DOTLINKS += .cgrc .tigrc
152 .gitconfig_SUBSTS = \
153 $(call substvar,releasekey,$(call mdw-conf,release-key,481334C2))
154 $(HOME)/.gitconfig: $(HOME)/.mdw.conf
157 DOTLINKS += .pulse/daemon.conf
158 DOTSUBST += .pulse/default.pa
159 .pulse/daemon.conf_SRC = pulse-daemon.conf
160 .pulse/default.pa_SRC = pulse-default.pa.in
163 DOTLINKS += .vimrc .mg .zile
166 DOTLINKS += .mailrc .signature .muttrc
169 DOTLINKS += .cmucl-init.lisp .sbclrc .clisprc.lisp .eclrc
170 .cmucl-init.lisp_SRC = lisp-init.lisp
171 .sbclrc_SRC = lisp-init.lisp
172 .clisprc.lisp_SRC = lisp-init.lisp
173 .eclrc_SRC = lisp-init.lisp
174 DOTLINKS += .swank.lisp
177 DOTLINKS += .ipython/profile_default/ipython_config.py
178 DOTLINKS += .ipython/profile_default/startup/50-key-bindings.py
179 .ipython/profile_default/ipython_config.py_SRC = ipython-config.py
180 .ipython/profile_default/startup/50-key-bindings.py_SRC = ipython-key-bindings.py
184 DOTLINKS += .tclshrc .wishrc
185 .tclshrc_SRC = tclshrc
186 .wishrc_SRC = tclshrc
189 SCRIPTLINKS += mdw-editor mdw-pager
190 SCRIPTLINKS += mdw-conf
191 SCRIPTLINKS += svnwrap
192 SCRIPTLINKS += guest-console
193 SCRIPTLINKS += hyperspec
195 ## Random odds and ends.
196 DOTLINKS += .lesskey .infokey .sqliterc
197 DOTLINKS += .gdbinit .toprc .aspell.conf
198 DOTLINKS += .dircolors .colordiffrc .screenrc .tmux.conf
199 DOTLINKS += .cvsrc .indent.pro .ditz-config
200 DOTSUBST += .mykermrc
201 SCRIPTLINKS += lesspipe.sh
203 SCRIPTLINKS += run-with-shell-env
204 SCRIPTLINKS += start-ssh-agent start-ssh-pageant
205 SCRIPTLINKS += add-ssh-keys
206 SCRIPTLINKS += hacks/ssh/ssh
207 hacks/ssh/ssh_SRC = hacks/ssh
209 DOTLINKS += .w3m/config .elinks/elinks.conf
210 .w3m/config_SRC = w3m-config
211 .elinks/elinks.conf_SRC = elinks.conf
213 DOTLINKS += .mc/ini .mc/panels.ini
215 .mc/panels.ini_SRC = mc-panels.ini
217 DOTLINKS += .parallel/config
218 .parallel/config_SRC = parallel-config
220 ###--------------------------------------------------------------------------
221 ### X11 configuration.
229 DOTLINKS += .xinitrc .xsession .xmodmap .vncrc .vncsession
230 DOTLINKS += .fonts.conf
231 DOTLINKS += .stalonetrayrc
233 DOTLINKS += .putty/sessions/Default%20Settings
234 .putty/sessions/Default%20Settings_SRC = putty-defaults
236 DOTLINKS += .config/gnome-session/sessions/mdw.session
237 .config/gnome-session/sessions/mdw.session_SRC = mdw.session
239 DOTLINKS += .Eterm/themes/Eterm/theme.cfg
240 DOTLINKS += .enlightenment/keybindings.cfg
241 DOTLINKS += .enlightenment-vnc/keybindings.cfg
242 DOTLINKS += .e16/bindings.cfg
243 .Eterm/themes/Eterm/theme.cfg_SRC = eterm-theme.cfg
244 .enlightenment/keybindings.cfg_SRC = e-keybindings.cfg
245 .enlightenment-vnc/keybindings.cfg_SRC = evnc-keybindings.cfg
246 .e16/bindings.cfg_SRC = e16-bindings
248 DOTLINKS += .gtkrc-2.0
249 DOTLINKS += .config/gtk-3.0/gtk.css
250 DOTLINKS += .config/gtk-3.0/settings.ini
251 .config/gtk-3.0/gtk.css_SRC = gtk3.css
252 .config/gtk-3.0/settings.ini_SRC = gtk3-settings.ini
254 SCRIPTLINKS += xinitcmd lock-screen xshutdown
255 SCRIPTLINKS += un-backslashify-selection
256 SCRIPTLINKS += xpra-start-xdummy
259 Xdefaults_DEFS = -DEMACSWD=$(call mdw-conf,emacs-width,77)
260 $(HOME)/.Xdefaults: $(HOME)/.mdw.conf
264 ###--------------------------------------------------------------------------
265 ### Processing dotfiles.
267 dotfile-source = $(HERE)/dot/$(or $($1_SRC), $(1:.%=%)$2)
269 ## Easiest: just make symlinks.
271 $(call symlink-ok-p,$(HOME)/$1,$(call dotfile-source,$1))
272 all:: $(addprefix $(HOME)/, $(DOTLINKS))
273 $(addprefix $(HOME)/, $(subst %,\%,$(DOTLINKS))): $(HOME)/%: \
274 $$(if $$(call dotlink-ok-p,$$*),,_force)
275 $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
277 ln -s $(call dotfile-source,$*) $@.new && \
280 ## Hack with the C preprocessor.
281 all:: $(addprefix $(HOME)/, $(DOTCPP))
282 $(addprefix $(HOME)/, $(subst %,\%,$(DOTCPP))): $(HOME)/%: \
283 $$(call dotfile-source,$$*) Makefile
284 $(call v_tag,CPP)mkdir -p $(dir $@) && \
286 cpp -P -o$@.new $($*_DEFS) $< && \
289 ## Hack by making simple substitutions.
290 substvar = -e $(call quote,s
\a@$1@
\a$2
\ag)
291 SUBSTS += $(call substvar,home,$(HOME))
292 SUBSTS += $(call substvar,profile,$(HERE))
293 all:: $(addprefix $(HOME)/, $(DOTSUBST))
294 $(addprefix $(HOME)/, $(subst %,\%,$(DOTSUBST))): $(HOME)/%: \
295 $$(call dotsubst-source,$$*,.in) Makefile
296 $(call v_tag,SUBST)mkdir -p $(dir $@) && \
299 $(relax)### generated by $(HERE)/Makefile; do not edit!" \
300 $(SUBSTS) $($*_SUBSTS) \
301 $(call dotfile-source,$*,.in) >$@.new && \
304 ###--------------------------------------------------------------------------
305 ### Processing script links.
307 script-source = $(HERE)/bin/$(or $($1_SRC), $1)
309 $(call symlink-ok-p,$(HOME)/bin/$1,$(call script-source,$1))
310 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
311 $(addprefix $(HOME)/bin/, $(SCRIPTLINKS)): $(HOME)/bin/%: \
312 $$(if $$(call scriptlink-ok-p,$$*),,_force)
313 $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
315 ln -s $(call script-source,$*) $@.new && \
318 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
320 ###--------------------------------------------------------------------------
321 ### Building packages from source tarballs.
323 SRCDIR = $(HOME)/src/profile
325 pkg-builddir = $(SRCDIR)/$1/build
326 pkg-stamp = $(call pkg-builddir,$1)/$2-stamp
328 $(foreach p, $(PACKAGES), $(eval DEP_$p = $(if $(shell \
329 if $($p_CHECK) >/dev/null 2>&1 --version; then echo t; fi),, \
330 $(call pkg-stamp,$p,install))))
332 $(PACKAGES:%=$(SRCDIR)/%.tar.gz): $(SRCDIR)/%.tar.gz:
333 $(call v_tag,FETCH)mkdir -p $(SRCDIR) && \
335 $(call get-url,$@.new,$(REPO)/$*.tar.gz) && \
338 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,unpack)): \
339 $(call pkg-stamp,%,unpack): $(SRCDIR)/%.tar.gz
340 $(call v_tag,EXTRACT)rm -rf $(SRCDIR)/$* && \
341 mkdir $(SRCDIR)/$*.tmp-unpack && \
342 cd $(SRCDIR)/$*.tmp-unpack && \
343 gzip -cd ../$*.tar.gz | tar xf - && \
346 rmdir $*.tmp-unpack && \
348 touch $*/build/unpack-stamp
350 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,configure)): \
351 $(call pkg-stamp,%,configure): \
352 $(call pkg-stamp,%,unpack) \
353 $$(foreach p, $$($$*_DEPS), $$(DEP_$$p))
354 $(call v_tag,CONFIG)cd $(dir $@) && \
355 ../configure --prefix=$(HOME) \
356 PKG_CONFIG_PATH=$(HOME)/lib/pkgconfig \
357 $($*_CONFIG) >>buildlog 2>&1 && \
358 touch configure-stamp
360 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,build)): \
361 $(call pkg-stamp,%,build): \
362 $(call pkg-stamp,%,configure)
363 $(call v_tag,BUILD)cd $(dir $@) && \
364 $(MAKE) $($*_MAKEFLAGS) >>buildlog 2>&1 && \
367 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,install)): \
368 $(call pkg-stamp,%,install): \
369 $(call pkg-stamp,%,build)
370 $(call v_tag,INSTALL)cd $(dir $@) && \
371 $(MAKE) $($*_MAKEFLAGS) install >>buildlog 2>&1 && \
374 all:: $(foreach p, $(PACKAGES), $(DEP_$p))
375 $(foreach p, $(PACKAGES), $(eval _pkg.$p: $(call pkg-stamp,$p,install)))
377 ###----- That's all, folks --------------------------------------------------