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 ###--------------------------------------------------------------------------
67 EMACSLIB = $(HOME)/lib/emacs
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
76 dot-emacs_DEPS = make-regexp
78 SCRIPTLINKS += emacsclient-hack movemail-hack sendmail-hack
79 SCRIPTLINKS += aspell-hack emerge-hack
81 %.elc: %.el $$(foreach e, $$($$*_DEPS), $$(DEP_$$e))
82 $(call v_tag,EMACS)if ! $(EMACS) >$*.build-log 2>&1 \
83 -L el/ -L $(EMACSLIB) \
84 --batch --no-site-file \
85 --eval '(byte-compile-file "$<")'; then \
86 cat $*.build-log; exit 2; \
89 LOCAL_ELISP = $(filter $(notdir $(wildcard el/*.el)), \
90 $(addsuffix .el, $(ELISP)))
91 $(foreach e, $(LOCAL_ELISP), \
92 $(eval DEP_$(basename $e) = $(EMACSLIB)/$(e:.el=.elc)))
93 $(addprefix $(EMACSLIB)/, $(LOCAL_ELISP)): $(EMACSLIB)/%: el/%
94 $(call v_tag,SYMINK)mkdir -p $(EMACSLIB) && \
96 ln -s $(HERE)/$< $@.new && \
99 REMOTE_ELISP = $(filter-out $(notdir $(wildcard el/*.el)), \
100 $(addsuffix .el, $(ELISP)))
101 $(foreach e, $(REMOTE_ELISP), \
102 $(eval DEP_$(basename $e) = $(if $(shell \
103 if $(EMACS) >/dev/null 2>&1 --no-site-file -q --batch \
106 (kill-emacs (condition-case nil \
107 (progn (load-library "$e") 0) \
108 (error 1))))'; then \
110 fi),, $(EMACSLIB)/$(e:.el=.elc))))
111 $(addprefix $(EMACSLIB)/, $(REMOTE_ELISP)): $(EMACSLIB)/%:
112 $(call v_tag,FETCH)mkdir -p $(EMACSLIB) && \
113 $(call get-url,$@.new,$(REPO)/$*) && \
116 DOTLINKS += .emacs .emacs-calc .vm .gnus.el .ercrc.el
118 all:: $(foreach e, $(ELISP), $(DEP_$e))
119 $(foreach e, $(ELISP), $(eval _emacs.$e: $(EMACSLIB)/$e.elc))
121 ###--------------------------------------------------------------------------
122 ### Other simpler things.
125 $(call v_tag,COPY)cp mdw.conf $@.new && mv $@.new $@
128 PACKAGES += mlib checkpath
129 mlib_CHECK = crc-mktab
130 checkpath_CHECK = tmpdir
131 checkpath_DEPS = mlib
133 ## Packaging machinery.
134 SCRIPTLINKS += mdw-build mdw-sbuild mdw-sbuild-server
135 SCRIPTLINKS += update-buildable-branch
138 DOTLINKS += .profile .shell-rc .shell-logout
139 DOTLINKS += .shrc .rcrc
140 DOTLINKS += .zprofile .zshrc .zshenv
141 DOTLINKS += .bash_profile .bash_completion .bashrc .inputrc
142 .bash_profile_SRC = bash-profile
143 .bash_completion_SRC = bash-completion
146 DOTSUBST += .gitconfig
147 DOTLINKS += .cgrc .tigrc
148 .gitconfig_SUBSTS = \
149 $(call substvar,releasekey,$(call mdw-conf,release-key,481334C2))
150 $(HOME)/.gitconfig: $(HOME)/.mdw.conf
153 DOTLINKS += .pulse/daemon.conf
154 DOTSUBST += .pulse/default.pa
155 .pulse/daemon.conf_SRC = pulse-daemon.conf
156 .pulse/default.pa_SRC = pulse-default.pa.in
159 DOTLINKS += .vimrc .mg .zile
162 DOTLINKS += .mailrc .signature .muttrc
165 DOTLINKS += .cmucl-init.lisp .sbclrc .clisprc.lisp .eclrc
166 .cmucl-init.lisp_SRC = lisp-init.lisp
167 .sbclrc_SRC = lisp-init.lisp
168 .clisprc.lisp_SRC = lisp-init.lisp
169 .eclrc_SRC = lisp-init.lisp
170 DOTLINKS += .swank.lisp
173 DOTLINKS += .ipython/profile_default/ipython_config.py
174 DOTLINKS += .ipython/profile_default/startup/50-key-bindings.py
175 .ipython/profile_default/ipython_config.py_SRC = ipython-config.py
176 .ipython/profile_default/startup/50-key-bindings.py_SRC = ipython-key-bindings.py
180 DOTLINKS += .tclshrc .wishrc
181 .tclshrc_SRC = tclshrc
182 .wishrc_SRC = tclshrc
185 SCRIPTLINKS += mdw-editor mdw-pager
186 SCRIPTLINKS += mdw-conf
187 SCRIPTLINKS += svnwrap
188 SCRIPTLINKS += guest-console
189 SCRIPTLINKS += hyperspec
191 ## Random odds and ends.
192 DOTLINKS += .lesskey .infokey .sqliterc
193 DOTLINKS += .gdbinit .toprc .aspell.conf
194 DOTLINKS += .dircolors .colordiffrc .screenrc .tmux.conf
195 DOTLINKS += .cvsrc .indent.pro .ditz-config
196 DOTSUBST += .mykermrc
197 SCRIPTLINKS += lesspipe.sh
199 SCRIPTLINKS += run-with-shell-env
200 SCRIPTLINKS += start-ssh-agent start-ssh-pageant
201 SCRIPTLINKS += add-ssh-keys
202 SCRIPTLINKS += hacks/ssh/ssh
203 hacks/ssh/ssh_SRC = hacks/ssh
205 DOTLINKS += .w3m/config .elinks/elinks.conf
206 .w3m/config_SRC = w3m-config
207 .elinks/elinks.conf_SRC = elinks.conf
209 DOTLINKS += .mc/ini .mc/panels.ini
211 .mc/panels.ini_SRC = mc-panels.ini
213 DOTLINKS += .parallel/config
214 .parallel/config_SRC = parallel-config
216 ###--------------------------------------------------------------------------
217 ### X11 configuration.
225 DOTLINKS += .xinitrc .xsession .xmodmap .vncrc .vncsession
226 DOTLINKS += .fonts.conf
227 DOTLINKS += .stalonetrayrc
229 DOTLINKS += .putty/sessions/Default%20Settings
230 .putty/sessions/Default%20Settings_SRC = putty-defaults
232 DOTLINKS += .config/gnome-session/sessions/mdw.session
233 .config/gnome-session/sessions/mdw.session_SRC = mdw.session
235 DOTLINKS += .Eterm/themes/Eterm/theme.cfg
236 DOTLINKS += .enlightenment/keybindings.cfg
237 DOTLINKS += .enlightenment-vnc/keybindings.cfg
238 DOTLINKS += .e16/bindings.cfg
239 .Eterm/themes/Eterm/theme.cfg_SRC = eterm-theme.cfg
240 .enlightenment/keybindings.cfg_SRC = e-keybindings.cfg
241 .enlightenment-vnc/keybindings.cfg_SRC = evnc-keybindings.cfg
242 .e16/bindings.cfg_SRC = e16-bindings
244 DOTLINKS += .gtkrc-2.0
245 DOTLINKS += .config/gtk-3.0/gtk.css
246 DOTLINKS += .config/gtk-3.0/settings.ini
247 .config/gtk-3.0/gtk.css_SRC = gtk3.css
248 .config/gtk-3.0/settings.ini_SRC = gtk3-settings.ini
250 SCRIPTLINKS += xinitcmd lock-screen xshutdown
251 SCRIPTLINKS += un-backslashify-selection
252 SCRIPTLINKS += xpra-start-xdummy
255 Xdefaults_DEFS = -DEMACSWD=$(call mdw-conf,emacs-width,77)
256 $(HOME)/.Xdefaults: $(HOME)/.mdw.conf
260 ###--------------------------------------------------------------------------
261 ### Processing dotfiles.
263 dotfile-source = $(HERE)/dot/$(or $($1_SRC), $(1:.%=%)$2)
265 ## Easiest: just make symlinks.
267 $(call symlink-ok-p,$(HOME)/$1,$(call dotfile-source,$1))
268 all:: $(addprefix $(HOME)/, $(DOTLINKS))
269 $(addprefix $(HOME)/, $(subst %,\%,$(DOTLINKS))): $(HOME)/%: \
270 $$(if $$(call dotlink-ok-p,$$*),,_force)
271 $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
273 ln -s $(call dotfile-source,$*) $@.new && \
276 ## Hack with the C preprocessor.
277 all:: $(addprefix $(HOME)/, $(DOTCPP))
278 $(addprefix $(HOME)/, $(subst %,\%,$(DOTCPP))): $(HOME)/%: \
279 $$(call dotfile-source,$$*) Makefile
280 $(call v_tag,CPP)mkdir -p $(dir $@) && \
282 cpp -P -o$@.new $($*_DEFS) $< && \
285 ## Hack by making simple substitutions.
286 substvar = -e $(call quote,s
\a@$1@
\a$2
\ag)
287 SUBSTS += $(call substvar,home,$(HOME))
288 SUBSTS += $(call substvar,profile,$(HERE))
289 all:: $(addprefix $(HOME)/, $(DOTSUBST))
290 $(addprefix $(HOME)/, $(subst %,\%,$(DOTSUBST))): $(HOME)/%: \
291 $$(call dotsubst-source,$$*,.in) Makefile
292 $(call v_tag,SUBST)mkdir -p $(dir $@) && \
295 $(relax)### generated by $(HERE)/Makefile; do not edit!" \
296 $(SUBSTS) $($*_SUBSTS) \
297 $(call dotfile-source,$*,.in) >$@.new && \
300 ###--------------------------------------------------------------------------
301 ### Processing script links.
303 script-source = $(HERE)/bin/$(or $($1_SRC), $1)
305 $(call symlink-ok-p,$(HOME)/bin/$1,$(call script-source,$1))
306 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
307 $(addprefix $(HOME)/bin/, $(SCRIPTLINKS)): $(HOME)/bin/%: \
308 $$(if $$(call scriptlink-ok-p,$$*),,_force)
309 $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
311 ln -s $(call script-source,$*) $@.new && \
314 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
316 ###--------------------------------------------------------------------------
317 ### Building packages from source tarballs.
319 SRCDIR = $(HOME)/src/profile
321 pkg-builddir = $(SRCDIR)/$1/build
322 pkg-stamp = $(call pkg-builddir,$1)/$2-stamp
324 $(foreach p, $(PACKAGES), $(eval DEP_$p = $(if $(shell \
325 if $($p_CHECK) >/dev/null 2>&1 --version; then echo t; fi),, \
326 $(call pkg-stamp,$p,install))))
328 $(PACKAGES:%=$(SRCDIR)/%.tar.gz): $(SRCDIR)/%.tar.gz:
329 $(call v_tag,FETCH)mkdir -p $(SRCDIR) && \
331 $(call get-url,$@.new,$(REPO)/$*.tar.gz) && \
334 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,unpack)): \
335 $(call pkg-stamp,%,unpack): $(SRCDIR)/%.tar.gz
336 $(call v_tag,EXTRACT)rm -rf $(SRCDIR)/$* && \
337 mkdir $(SRCDIR)/$*.tmp-unpack && \
338 cd $(SRCDIR)/$*.tmp-unpack && \
339 gzip -cd ../$*.tar.gz | tar xf - && \
342 rmdir $*.tmp-unpack && \
344 touch $*/build/unpack-stamp
346 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,configure)): \
347 $(call pkg-stamp,%,configure): \
348 $(call pkg-stamp,%,unpack) \
349 $$(foreach p, $$($$*_DEPS), $$(DEP_$$p))
350 $(call v_tag,CONFIG)cd $(dir $@) && \
351 ../configure --prefix=$(HOME) \
352 PKG_CONFIG_PATH=$(HOME)/lib/pkgconfig \
353 $($*_CONFIG) >>buildlog 2>&1 && \
354 touch configure-stamp
356 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,build)): \
357 $(call pkg-stamp,%,build): \
358 $(call pkg-stamp,%,configure)
359 $(call v_tag,BUILD)cd $(dir $@) && \
360 $(MAKE) $($*_MAKEFLAGS) >>buildlog 2>&1 && \
363 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,install)): \
364 $(call pkg-stamp,%,install): \
365 $(call pkg-stamp,%,build)
366 $(call v_tag,INSTALL)cd $(dir $@) && \
367 $(MAKE) $($*_MAKEFLAGS) install >>buildlog 2>&1 && \
370 all:: $(foreach p, $(PACKAGES), $(DEP_$p))
371 $(foreach p, $(PACKAGES), $(eval _pkg.$p: $(call pkg-stamp,$p,install)))
373 ###----- That's all, folks --------------------------------------------------