chiark / gitweb /
7668ee2d3755310ea1fbce78ec1451a631a689f5
[profile] / Makefile
1 ## -*-makefile-*-
2
3 all::
4 .SECONDEXPANSION: #sorry
5
6 ###--------------------------------------------------------------------------
7 ### Utilities.
8
9 ##
10 quote                    = '$(subst ','\'',$1)'#'
11
12 ## Suss out how to print stuff.
13 print                    = printf "%s" $(call quote,$1)
14
15 ## Looking configuration things up.
16 mdw-conf                 = $(shell bin/mdw-conf "$1" "$2")
17
18 ## Checking symlink targets.
19 symlink-ok-p             = $(shell \
20         case $$(readlink 2>/dev/null $1) in ($2) echo t ;; esac)
21
22 ## Silent rules machinery.
23 V                        = 0
24 v_tag                    = $(call v_tag_$V,$1,$2)
25 v_tag_0                  = @printf "  %-8s %s\n" "$1" $(call quote,$@);
26 V_AT                     = $(V_AT_$V)
27 V_AT_0                   = @
28
29 ## Hack.
30 relax                    =
31
32 ###--------------------------------------------------------------------------
33 ### Configuration.
34
35 ## Figure out where I am.
36 HERE                     = $(shell pwd)
37
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
41 else
42   get-url                = wget -q -O $1 $2
43 endif
44
45 ## Which Emacs should I use?
46 EMACS                   := $(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.
53 REPO                     = 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
67 ifneq ($(EMACS),nil)
68
69 EMACSLIB                 = $(HOME)/lib/emacs
70
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
76
77 ELISP                   += dot-emacs
78 dot-emacs_DEPS           = make-regexp
79
80 SCRIPTLINKS             += emacsclient-hack movemail-hack sendmail-hack
81 SCRIPTLINKS             += aspell-hack emerge-hack
82
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; \
89         fi
90
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) && \
97                 rm -f $@.new && \
98                 ln -s $(HERE)/$< $@.new && \
99                 mv $@.new $@
100
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 \
106                         --eval ' \
107                           (progn \
108                             (kill-emacs (condition-case nil \
109                                             (progn (load-library "$e") 0) \
110                                           (error 1))))'; then \
111                   echo t; \
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)/$*) && \
116                 mv $@.new $@
117
118 DOTLINKS                += .emacs .emacs-calc .vm .gnus.el .ercrc.el
119
120 all:: $(foreach e, $(ELISP), $(DEP_$e))
121 $(foreach e, $(ELISP), $(eval _emacs.$e: $(EMACSLIB)/$e.elc))
122
123 endif
124
125 ###--------------------------------------------------------------------------
126 ### Other simpler things.
127
128 $(HOME)/.mdw.conf:
129         $(call v_tag,COPY)cp mdw.conf $@.new && mv $@.new $@
130
131 ## Utility packages.
132 PACKAGES                += mlib checkpath
133 mlib_CHECK               = crc-mktab
134 checkpath_CHECK          = tmpdir
135 checkpath_DEPS           = mlib
136
137 ## Packaging machinery.
138 SCRIPTLINKS             += mdw-build mdw-sbuild mdw-sbuild-server
139 SCRIPTLINKS             += update-buildable-branch
140
141 ## Shells.
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
148
149 ## Git.
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
155
156 ## PulseAudio.
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
161
162 ## Other editors.
163 DOTLINKS                += .vimrc .mg .zile
164
165 ## Mail.
166 DOTLINKS                += .mailrc .signature .muttrc
167
168 ## Lisp.
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
175
176 ## IPython.
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
181
182 ## Other languages.
183 DOTLINKS                += .guile
184 DOTLINKS                += .tclshrc .wishrc
185 .tclshrc_SRC             = tclshrc
186 .wishrc_SRC              = tclshrc
187
188 ## Random scripts.
189 SCRIPTLINKS             += mdw-editor mdw-pager
190 SCRIPTLINKS             += mdw-conf
191 SCRIPTLINKS             += svnwrap
192 SCRIPTLINKS             += guest-console
193 SCRIPTLINKS             += hyperspec
194
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
202
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
208
209 DOTLINKS                += .w3m/config .elinks/elinks.conf
210 .w3m/config_SRC          = w3m-config
211 .elinks/elinks.conf_SRC  = elinks.conf
212
213 DOTLINKS                += .mc/ini .mc/panels.ini
214 .mc/ini_SRC              = mc-ini
215 .mc/panels.ini_SRC       = mc-panels.ini
216
217 DOTLINKS                += .parallel/config
218 .parallel/config_SRC     = parallel-config
219
220 ###--------------------------------------------------------------------------
221 ### X11 configuration.
222
223 ifeq ($X,t)
224
225 PACKAGES                += xtoys
226 xtoys_CHECK              = xatom
227 xtoys_DEPS               = mlib
228
229 DOTLINKS                += .xinitrc .xsession .xmodmap .vncrc .vncsession
230 DOTLINKS                += .fonts.conf
231 DOTLINKS                += .stalonetrayrc
232
233 DOTLINKS                += .putty/sessions/Default%20Settings
234 .putty/sessions/Default%20Settings_SRC = putty-defaults
235
236 DOTLINKS                += .config/gnome-session/sessions/mdw.session
237 .config/gnome-session/sessions/mdw.session_SRC = mdw.session
238
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
247
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
253
254 SCRIPTLINKS             += xinitcmd lock-screen xshutdown
255 SCRIPTLINKS             += un-backslashify-selection
256 SCRIPTLINKS             += xpra-start-xdummy
257
258 DOTCPP                  += .Xdefaults
259 Xdefaults_DEFS           = -DEMACSWD=$(call mdw-conf,emacs-width,77)
260 $(HOME)/.Xdefaults: $(HOME)/.mdw.conf
261
262 endif
263
264 ###--------------------------------------------------------------------------
265 ### Processing dotfiles.
266
267 dotfile-source           = $(HERE)/dot/$(or $($1_SRC), $(1:.%=%)$2)
268
269 ## Easiest: just make symlinks.
270 dotlink-ok-p             = \
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 $@) && \
276                 rm -f $@.new && \
277                 ln -s $(call dotfile-source,$*) $@.new && \
278                 mv $@.new $@
279
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 $@) && \
285                 rm -f $@.new && \
286                 cpp -P -o$@.new $($*_DEFS) $< && \
287                 mv $@.new $@
288
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 $@) && \
297                 rm -f $@.new && \
298                 sed -e "1i\
299 $(relax)### generated by $(HERE)/Makefile; do not edit!" \
300                         $(SUBSTS) $($*_SUBSTS) \
301                         $(call dotfile-source,$*,.in) >$@.new && \
302                 mv $@.new $@
303
304 ###--------------------------------------------------------------------------
305 ### Processing script links.
306
307 script-source            = $(HERE)/bin/$(or $($1_SRC), $1)
308 scriptlink-ok-p          = \
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 $@) && \
314                 rm -f $@.new && \
315                 ln -s $(call script-source,$*) $@.new && \
316                 mv $@.new $@
317
318 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
319
320 ###--------------------------------------------------------------------------
321 ### Building packages from source tarballs.
322
323 SRCDIR                   = $(HOME)/src/profile
324
325 pkg-builddir             = $(SRCDIR)/$1/build
326 pkg-stamp                = $(call pkg-builddir,$1)/$2-stamp
327
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))))
331
332 $(PACKAGES:%=$(SRCDIR)/%.tar.gz): $(SRCDIR)/%.tar.gz:
333         $(call v_tag,FETCH)mkdir -p $(SRCDIR) && \
334                 rm -f $@.new && \
335                 $(call get-url,$@.new,$(REPO)/$*.tar.gz) && \
336                 mv $@.new $@
337
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 - && \
344                 mv * ../$* && \
345                 cd .. && \
346                 rmdir $*.tmp-unpack && \
347                 mkdir $*/build && \
348                 touch $*/build/unpack-stamp
349
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
359
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 && \
365                 touch build-stamp
366
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 && \
372                 touch install-stamp
373
374 all:: $(foreach p, $(PACKAGES), $(DEP_$p))
375 $(foreach p, $(PACKAGES), $(eval _pkg.$p: $(call pkg-stamp,$p,install)))
376
377 ###----- That's all, folks --------------------------------------------------