chiark / gitweb /
Use a proper makefile rather than the `setup' script.
[profile] / Makefile
CommitLineData
67b1a15a
MW
1## -*-makefile-*-
2
3all::
4.SECONDEXPANSION: #sorry
5
6###--------------------------------------------------------------------------
7### Utilities.
8
9##
10quote = '$(subst ','\'',$1)'#'
11
12## Suss out how to print stuff.
13print = printf "%s" $(call quote,$1)
14
15## Looking configuration things up.
16mdw-conf = $(shell bin/mdw-conf "$1" "$2")
17
18## Checking symlink targets.
19symlink-ok-p = $(shell \
20 case $$(readlink 2>/dev/null $1) in ($2) echo t ;; esac)
21
22## Silent rules machinery.
23V = 0
24v_tag = $(call v_tag_$V,$1,$2)
25v_tag_0 = @printf " %-8s %s\n" "$1" $(call quote,$@);
26V_AT = $(V_AT_$V)
27V_AT_0 = @
28
29## Hack.
30relax =
31
32###--------------------------------------------------------------------------
33### Configuration.
34
35## Figure out where I am.
36HERE = $(shell pwd)
37
38## Decide on how to fetch things from URLs.
39ifeq ($(shell (curl >/dev/null 2>&1 --version || [ $$? -eq 2 ]) && echo t),t)
40 get-url = curl -fs -o $1 $2
41else
42 get-url = wget -q -O $1 $2
43endif
44
45## Which Emacs should I use?
46EMACS := $(shell \
47 emacs=nil; \
48 for i in emacs24 emacs23 emacs22 emacs21 emacs; do \
49 if type >/dev/null 2>&1 $$i; then echo $$i; break; fi; \
50 done)
51
52## Whence to obtain externally hosted stuff.
53REPO = https://ftp.distorted.org.uk/u/mdw/profile
54
55## Additional local configuration.
56-include local.mk
57
58###--------------------------------------------------------------------------
59### Some utility rules.
60
61_force:
62.PHONY: _force
63
64###--------------------------------------------------------------------------
65### Emacs.
66
67EMACSLIB = $(HOME)/lib/emacs
68
69ELISP += dot-emacs.el
70ELISP += make-regexp.el ew-hols.el
71ELISP += mdw-gnus-patch.el
72ELISP += mdw-multiple-cursors.el
73ELISP += git.el git-blame.el vc-git.el stgit.el quilt.el
74ELISP += bracketed-paste.el
75
76SCRIPTLINKS += emacsclient-hack movemail-hack sendmail-hack
77SCRIPTLINKS += aspell-hack emerge-hack
78
79%.elc: %.el
80 $(call v_tag,EMACS)$(EMACS) -L el/ -L $(EMACSLIB) \
81 --batch --no-site-file \
82 --eval '(byte-compile-file "$<")'
83
84LOCAL_ELISP = $(filter $(notdir $(wildcard el/*.el)), $(ELISP))
85$(foreach e, $(LOCAL_ELISP), $(eval DEP_$e = $(EMACSLIB)/$(e:.el=.elc)))
86$(addprefix $(EMACSLIB)/, $(LOCAL_ELISP)): $(EMACSLIB)/%: el/%
87 $(call v_tag,SYMINK)mkdir -p $(EMACSLIB) && \
88 rm -f $@.new && \
89 ln -s $(HERE)/$< $@.new && \
90 mv $@.new $@
91
92REMOTE_ELISP = $(filter-out $(notdir $(wildcard el/*.el)), \
93 $(ELISP))
94$(foreach e, $(REMOTE_ELISP), \
95 $(eval DEP_$e = $(if $(shell \
96 if $(EMACS) >/dev/null 2>&1 --no-site-file -q --batch \
97 --eval ' \
98 (progn \
99 (kill-emacs (condition-case nil \
100 (progn (load-library "$e") 0) \
101 (error 1))))'; then \
102 echo t; \
103 fi),, $(EMACSLIB)/$(e:.el=.elc))))
104$(addprefix $(EMACSLIB)/, $(REMOTE_ELISP)): $(EMACSLIB)/%:
105 $(call v_tag,FETCH)mkdir -p $(EMACSLIB) && \
106 $(call get-url,$@.new,$(REPO)/$*) && \
107 mv $@.new $@
108
109DOTLINKS += .emacs .emacs-calc .vm .gnus.el .ercrc.el
110
111all:: $(foreach e, $(ELISP), $(DEP_$e))
112$(foreach e, $(ELISP), $(eval _emacs.$(e:.el=): $(EMACSLIB)/$(e:.el=.elc)))
113
114###--------------------------------------------------------------------------
115### Other simpler things.
116
117$(HOME)/.mdw.conf:
118 $(call v_tag,COPY)cp mdw.conf $@.new && mv $@.new $@
119
120## Utility packages.
121PACKAGES += mlib checkpath
122mlib_CHECK = crc-mktab
123checkpath_CHECK = tmpdir
124checkpath_DEPS = mlib
125
126## Packaging machinery.
127SCRIPTLINKS += mdw-build mdw-sbuild mdw-sbuild-server
128SCRIPTLINKS += update-buildable-branch
129
130## Shells.
131DOTLINKS += .profile .shell-rc .shell-logout
132DOTLINKS += .shrc .rcrc
133DOTLINKS += .zprofile .zshrc .zshenv
134DOTLINKS += .bash_profile .bash_completion .bashrc .inputrc
135.bash_profile_SRC = bash-profile
136.bash_completion_SRC = bash-completion
137
138## Git.
139DOTSUBST += .gitconfig
140DOTLINKS += .cgrc .tigrc
141.gitconfig_SUBSTS = \
142 $(call substvar,releasekey,$(call mdw-conf,release-key,481334C2))
143$(HOME)/.gitconfig: $(HOME)/.mdw.conf
144
145## PulseAudio.
146DOTLINKS += .pulse/daemon.conf
147DOTSUBST += .pulse/default.pa
148.pulse/daemon.conf_SRC = pulse-daemon.conf
149.pulse/default.pa_SRC = pulse-default.pa.in
150
151## Other editors.
152DOTLINKS += .vimrc .mg .zile
153
154## Mail.
155DOTLINKS += .mailrc .signature .muttrc
156
157## Lisp.
158DOTLINKS += .cmucl-init.lisp .sbclrc .clisprc.lisp .eclrc
159.cmucl-init.lisp_SRC = lisp-init.lisp
160.sbclrc_SRC = lisp-init.lisp
161.clisprc.lisp_SRC = lisp-init.lisp
162.eclrc_SRC = lisp-init.lisp
163DOTLINKS += .swank.lisp
164
165## IPython.
166DOTLINKS += .ipython/profile_default/ipython_config.py
167DOTLINKS += .ipython/profile_default/startup/50-key-bindings.py
168.ipython/profile_default/ipython_config.py_SRC = ipython-config.py
169.ipython/profile_default/startup/50-key-bindings.py_SRC = ipython-key-bindings.py
170
171## Other languages.
172DOTLINKS += .guile
173DOTLINKS += .tclshrc .wishrc
174.tclshrc_SRC = tclshrc
175.wishrc_SRC = tclshrc
176
177## Random scripts.
178SCRIPTLINKS += mdw-editor mdw-pager
179SCRIPTLINKS += mdw-conf
180SCRIPTLINKS += svnwrap
181SCRIPTLINKS += guest-console
182SCRIPTLINKS += hyperspec
183
184## Random odds and ends.
185DOTLINKS += .lesskey .infokey .sqliterc
186DOTLINKS += .gdbinit .toprc .aspell.conf
187DOTLINKS += .dircolors .colordiffrc .screenrc .tmux.conf
188DOTLINKS += .cvsrc .indent.pro .ditz-config
189DOTSUBST += .mykermrc
190SCRIPTLINKS += lesspipe.sh
191
192SCRIPTLINKS += run-with-shell-env
193SCRIPTLINKS += start-ssh-agent start-ssh-pageant
194SCRIPTLINKS += add-ssh-keys
195SCRIPTLINKS += hacks/ssh/ssh
196hacks/ssh/ssh_SRC = hacks/ssh
197
198DOTLINKS += .w3m/config .elinks/elinks.conf
199.w3m/config_SRC = w3m-config
200.elinks/elinks.conf_SRC = elinks.conf
201
202DOTLINKS += .mc/ini .mc/panels.ini
203.mc/ini_SRC = mc-ini
204.mc/panels.ini_SRC = mc-panels.ini
205
206DOTLINKS += .parallel/config
207.parallel/config_SRC = parallel-config
208
209###--------------------------------------------------------------------------
210### X11 configuration.
211
212ifeq ($X,t)
213
214PACKAGES += xtoys
215xtoys_CHECK = xatom
216xtoys_DEPS = mlib
217
218DOTLINKS += .xinitrc .xsession .xmodmap .vncrc .vncsession
219DOTLINKS += .fonts.conf
220DOTLINKS += .stalonetrayrc
221
222DOTLINKS += .putty/sessions/Default%20Settings
223.putty/sessions/Default%20Settings_SRC = putty-defaults
224
225DOTLINKS += .config/gnome-session/sessions/mdw.session
226.config/gnome-session/sessions/mdw.session_SRC = mdw.session
227
228DOTLINKS += .Eterm/themes/Eterm/theme.cfg
229DOTLINKS += .enlightenment/keybindings.cfg
230DOTLINKS += .enlightenment-vnc/keybindings.cfg
231DOTLINKS += .e16/bindings.cfg
232.Eterm/themes/Eterm/theme.cfg_SRC = eterm-theme.cfg
233.enlightenment/keybindings.cfg_SRC = e-keybindings.cfg
234.enlightenment-vnc/keybindings.cfg_SRC = evnc-keybindings.cfg
235.e16/bindings.cfg_SRC = e16-bindings
236
237DOTLINKS += .gtkrc-2.0
238DOTLINKS += .config/gtk-3.0/gtk.css
239DOTLINKS += .config/gtk-3.0/settings.ini
240.config/gtk-3.0/gtk.css_SRC = gtk3.css
241.config/gtk-3.0/settings.ini_SRC = gtk3-settings.ini
242
243SCRIPTLINKS += xinitcmd lock-screen xshutdown
244SCRIPTLINKS += un-backslashify-selection
245SCRIPTLINKS += xpra-start-xdummy
246
247DOTCPP += .Xdefaults
248Xdefaults_DEFS = -DEMACSWD=$(call mdw-conf,emacs-width,77)
249$(HOME)/.Xdefaults: $(HOME)/.mdw.conf
250
251endif
252
253###--------------------------------------------------------------------------
254### Processing dotfiles.
255
256dotfile-source = $(HERE)/dot/$(or $($1_SRC), $(1:.%=%)$2)
257
258## Easist: just make symlinks.
259dotlink-ok-p = \
260 $(call symlink-ok-p,$(HOME)/$1,$(call dotfile-source,$1))
261all:: $(addprefix $(HOME)/, $(DOTLINKS))
262$(addprefix $(HOME)/, $(subst %,\%,$(DOTLINKS))): $(HOME)/%: \
263 $$(if $$(call dotlink-ok-p,$$*),,_force)
264 $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
265 rm -f $@.new && \
266 ln -s $(call dotfile-source,$*) $@.new && \
267 mv $@.new $@
268
269## Hack with the C preprocessor.
270all:: $(addprefix $(HOME)/, $(DOTCPP))
271$(addprefix $(HOME)/, $(subst %,\%,$(DOTCPP))): $(HOME)/%: \
272 $$(call dotfile-source,$$*) Makefile
273 $(call v_tag,CPP)mkdir -p $(dir $@) && \
274 rm -f $@.new && \
275 cpp -P -o$@.new $($*_DEFS) $< && \
276 mv $@.new $@
277
278## Hack by making simple substitutions.
279substvar = -e $(call quote,s\a@$1@\a$2\ag)
280SUBSTS += $(call substvar,home,$(HOME))
281SUBSTS += $(call substvar,profile,$(HERE))
282all:: $(addprefix $(HOME)/, $(DOTSUBST))
283$(addprefix $(HOME)/, $(subst %,\%,$(DOTSUBST))): $(HOME)/%: \
284 $$(call dotsubst-source,$$*,.in) Makefile
285 $(call v_tag,SUBST)mkdir -p $(dir $@) && \
286 rm -f $@.new && \
287 sed -e "1i\
288$(relax)### generated by $(HERE)/Makefile; do not edit!" \
289 $(SUBSTS) $($*_SUBSTS) \
290 $(call dotfile-source,$*,.in) >$@.new && \
291 mv $@.new $@
292
293###--------------------------------------------------------------------------
294### Processing script links.
295
296script-source = $(HERE)/bin/$(or $($1_SRC), $1)
297scriptlink-ok-p = \
298 $(call symlink-ok-p,$(HOME)/bin/$1,$(call script-source,$1))
299all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
300$(addprefix $(HOME)/bin/, $(SCRIPTLINKS)): $(HOME)/bin/%: \
301 $$(if $$(call scriptlink-ok-p,$$*),,_force)
302 $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
303 rm -f $@.new && \
304 ln -s $(call script-source,$*) $@.new && \
305 mv $@.new $@
306
307all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
308
309###--------------------------------------------------------------------------
310### Building packages from source tarballs.
311
312SRCDIR = $(HOME)/src/profile
313
314pkg-builddir = $(SRCDIR)/$1/build
315pkg-stamp = $(call pkg-builddir,$1)/$2-stamp
316
317$(foreach p, $(PACKAGES), $(eval DEP_$p = $(if $(shell \
318 if $($p_CHECK) >/dev/null 2>&1 --version; then echo t; fi),, \
319 $(call pkg-stamp,$p,install))))
320
321$(PACKAGES:%=$(SRCDIR)/%.tar.gz): $(SRCDIR)/%.tar.gz:
322 $(call v_tag,FETCH)mkdir -p $(SRCDIR) && \
323 rm -f $@.new && \
324 $(call get-url,$@.new,$(REPO)/$*.tar.gz) && \
325 mv $@.new $@
326
327$(foreach p, $(PACKAGES), $(call pkg-stamp,$p,unpack)): \
328 $(call pkg-stamp,%,unpack): $(SRCDIR)/%.tar.gz
329 $(call v_tag,EXTRACT)rm -rf $(SRCDIR)/$* && \
330 mkdir $(SRCDIR)/$*.tmp-unpack && \
331 cd $(SRCDIR)/$*.tmp-unpack && \
332 gzip -cd ../$*.tar.gz | tar xf - && \
333 mv * ../$* && \
334 cd .. && \
335 rmdir $*.tmp-unpack && \
336 mkdir $*/build && \
337 touch $*/build/unpack-stamp
338
339$(foreach p, $(PACKAGES), $(call pkg-stamp,$p,configure)): \
340 $(call pkg-stamp,%,configure): \
341 $(call pkg-stamp,%,unpack) \
342 $$(foreach p, $$($$*_DEPS), $$(DEP_$$p))
343 $(call v_tag,CONFIG)cd $(dir $@) && \
344 ../configure --prefix=$(HOME) \
345 PKG_CONFIG_PATH=$(HOME)/lib/pkgconfig \
346 $($*_CONFIG) >>buildlog 2>&1 && \
347 touch configure-stamp
348
349$(foreach p, $(PACKAGES), $(call pkg-stamp,$p,build)): \
350 $(call pkg-stamp,%,build): \
351 $(call pkg-stamp,%,configure)
352 $(call v_tag,BUILD)cd $(dir $@) && \
353 $(MAKE) $($*_MAKEFLAGS) >>buildlog 2>&1 && \
354 touch build-stamp
355
356$(foreach p, $(PACKAGES), $(call pkg-stamp,$p,install)): \
357 $(call pkg-stamp,%,install): \
358 $(call pkg-stamp,%,build)
359 $(call v_tag,INSTALL)cd $(dir $@) && \
360 $(MAKE) $($*_MAKEFLAGS) install >>buildlog 2>&1 && \
361 touch install-stamp
362
363all:: $(foreach p, $(PACKAGES), $(DEP_$p))
364$(foreach p, $(PACKAGES), $(eval _pkg.$p: $(call pkg-stamp,$p,install)))
365
366###----- That's all, folks --------------------------------------------------