chiark / gitweb /
Makefile, dot/rcrc: Hack rc(1) profile for Plan 9 compatibility.
[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 EMACS_VERSION           := $(shell $(EMACS) 2>&1 -Q --batch --eval \
72         '(message "%s %s" emacs-major-version emacs-minor-version)')
73 emacs-version-p          = $(shell set -- $(EMACS_VERSION); \
74         if [ $$1 -gt $1 ] || ([ $$1 -eq $1 ] && [ $$2 -ge $2 ]); then \
75           echo t; \
76         fi)
77
78 ELISP                   += make-regexp ew-hols
79 ELISP                   += mdw-gnus-patch
80 ELISP                   += mdw-multiple-cursors
81 ELISP                   += git git-blame vc-git stgit quilt
82
83 ifeq ($(call emacs-version-p,24,3),t)
84 ELISP                   += bracketed-paste
85 endif
86
87 ELISP                   += dot-emacs
88 dot-emacs_DEPS           = make-regexp
89
90 SCRIPTLINKS             += emacsclient-hack movemail-hack sendmail-hack
91 SCRIPTLINKS             += aspell-hack emerge-hack
92
93 %.elc: %.el $$(foreach e, $$($$*_DEPS), $$(DEP_$$e))
94         $(call v_tag,EMACS)if ! $(EMACS) >$*.build-log 2>&1 \
95                 -L el/ -L $(EMACSLIB) \
96                 --batch --no-site-file \
97                 --eval '(byte-compile-file "$<")'; then \
98           cat $*.build-log; exit 2; \
99         fi
100
101 LOCAL_ELISP              = $(filter $(notdir $(wildcard el/*.el)), \
102                                 $(addsuffix .el, $(ELISP)))
103 $(foreach e, $(LOCAL_ELISP), \
104         $(eval DEP_$(basename $e) = $(EMACSLIB)/$(e:.el=.elc)))
105 $(addprefix $(EMACSLIB)/, $(LOCAL_ELISP)): $(EMACSLIB)/%: el/%
106         $(call v_tag,SYMINK)mkdir -p $(EMACSLIB) && \
107                 rm -f $@.new && \
108                 ln -s $(HERE)/$< $@.new && \
109                 mv $@.new $@
110
111 REMOTE_ELISP             = $(filter-out $(notdir $(wildcard el/*.el)), \
112                                 $(addsuffix .el, $(ELISP)))
113 $(foreach e, $(REMOTE_ELISP), \
114         $(eval DEP_$(basename $e) = $(if $(shell \
115                 if $(EMACS) >/dev/null 2>&1 --no-site-file -q --batch \
116                         --eval ' \
117                           (progn \
118                             (kill-emacs (condition-case nil \
119                                             (progn (load-library "$e") 0) \
120                                           (error 1))))'; then \
121                   echo t; \
122                 fi),, $(EMACSLIB)/$(e:.el=.elc))))
123 $(addprefix $(EMACSLIB)/, $(REMOTE_ELISP)): $(EMACSLIB)/%:
124         $(call v_tag,FETCH)mkdir -p $(EMACSLIB) && \
125                 $(call get-url,$@.new,$(REPO)/$*) && \
126                 mv $@.new $@
127
128 DOTLINKS                += .emacs .emacs-calc .vm .gnus.el .ercrc.el
129
130 all:: $(foreach e, $(ELISP), $(DEP_$e))
131 $(foreach e, $(ELISP), $(eval _emacs.$e: $(EMACSLIB)/$e.elc))
132
133 endif
134
135 ###--------------------------------------------------------------------------
136 ### Other simpler things.
137
138 $(HOME)/.mdw.conf:
139         $(call v_tag,COPY)cp mdw.conf $@.new && mv $@.new $@
140
141 ## Utility packages.
142 PACKAGES                += mlib checkpath
143 mlib_CHECK               = crc-mktab
144 checkpath_CHECK          = tmpdir
145 checkpath_DEPS           = mlib
146
147 ## Packaging machinery.
148 SCRIPTLINKS             += mdw-build mdw-sbuild mdw-sbuild-server
149 SCRIPTLINKS             += update-buildable-branch
150
151 ## Shells.
152 DOTLINKS                += .profile .shell-rc .shell-logout
153 DOTLINKS                += .shrc
154 DOTLINKS                += .zprofile .zshrc .zlogout .zshenv
155 DOTLINKS                += .bash_profile .bash_completion .bash_logout
156 DOTLINKS                += .bashrc .inputrc
157 .bash_profile_SRC        = bash-profile
158 .bash_completion_SRC     = bash-completion
159 .bash_logout_SRC         = shell-logout
160 .zlogout_SRC             = shell-logout
161
162 ## The Plan 9 `rc' shell.  This needs special hacking, because the Linux port
163 ## and Plan 9 From User Space have incompatible syntax.
164 DOTLINKS                += lib/profile
165 lib/profile_SRC          = rcrc
166 all:: $(HOME)/.rcrc
167 $(HOME)/.rcrc: dot/rcrc
168         $(call v_tag,SED)sed 's/; if not/else/' $< >$@.new && mv $@.new $@
169
170 ## Git.
171 DOTSUBST                += .gitconfig
172 SCRIPTLINKS             += git-copyright-dates
173 DOTLINKS                += .cgrc .tigrc
174 .gitconfig_SUBSTS        = \
175         $(call substvar,releasekey,$(call mdw-conf,release-key,481334C2))
176 $(HOME)/.gitconfig: $(HOME)/.mdw.conf
177
178 ## PulseAudio.
179 DOTLINKS                += .pulse/daemon.conf
180 DOTSUBST                += .pulse/default.pa
181 .pulse/daemon.conf_SRC   = pulse-daemon.conf
182 .pulse/default.pa_SRC    = pulse-default.pa.in
183
184 ## Other editors.
185 DOTLINKS                += .vimrc .mg .zile
186
187 ## Mail.
188 DOTLINKS                += .mailrc .signature .muttrc
189
190 ## Lisp.
191 DOTLINKS                += .cmucl-init.lisp .sbclrc .clisprc.lisp .eclrc
192 .cmucl-init.lisp_SRC     = lisp-init.lisp
193 .sbclrc_SRC              = lisp-init.lisp
194 .clisprc.lisp_SRC        = lisp-init.lisp
195 .eclrc_SRC               = lisp-init.lisp
196 DOTLINKS                += .swank.lisp
197
198 ## IPython.
199 DOTLINKS                += .ipython/profile_default/ipython_config.py
200 DOTLINKS                += .ipython/profile_default/startup/50-key-bindings.py
201 .ipython/profile_default/ipython_config.py_SRC = ipython-config.py
202 .ipython/profile_default/startup/50-key-bindings.py_SRC = ipython-key-bindings.py
203
204 ## Other languages.
205 DOTLINKS                += .guile
206 DOTLINKS                += .tclshrc .wishrc
207 .tclshrc_SRC             = tclshrc
208 .wishrc_SRC              = tclshrc
209
210 ## Random scripts.
211 SCRIPTLINKS             += mdw-editor mdw-pager
212 SCRIPTLINKS             += mdw-conf
213 SCRIPTLINKS             += svnwrap
214 SCRIPTLINKS             += guest-console
215 SCRIPTLINKS             += hyperspec
216
217 ## Random odds and ends.
218 DOTLINKS                += .lesskey .infokey .sqliterc
219 DOTLINKS                += .gdbinit .toprc .aspell.conf
220 DOTLINKS                += .dircolors .colordiffrc .screenrc .tmux.conf
221 DOTLINKS                += .cvsrc .indent.pro .ditz-config
222 DOTLINKS                += .lftp/rc
223 .lftp/rc_SRC             = lftp-rc
224 DOTSUBST                += .mykermrc
225 SCRIPTLINKS             += lesspipe.sh
226
227 SCRIPTLINKS             += run-with-shell-env
228 SCRIPTLINKS             += start-ssh-agent start-ssh-pageant
229 SCRIPTLINKS             += add-ssh-keys
230 SCRIPTLINKS             += hacks/ssh/ssh
231 hacks/ssh/ssh_SRC        = hacks/ssh
232
233 DOTLINKS                += .w3m/config .elinks/elinks.conf
234 .w3m/config_SRC          = w3m-config
235 .elinks/elinks.conf_SRC  = elinks.conf
236
237 DOTLINKS                += .mc/ini .mc/panels.ini
238 .mc/ini_SRC              = mc-ini
239 .mc/panels.ini_SRC       = mc-panels.ini
240
241 DOTLINKS                += .parallel/config
242 .parallel/config_SRC     = parallel-config
243
244 ###--------------------------------------------------------------------------
245 ### X11 configuration.
246
247 ifeq ($X,t)
248
249 PACKAGES                += xtoys
250 xtoys_CHECK              = xatom
251 xtoys_DEPS               = mlib
252
253 DOTLINKS                += .xinitrc .xsession .xmodmap .vncrc .vncsession
254 DOTLINKS                += .fonts.conf
255 DOTLINKS                += .stalonetrayrc
256
257 DOTLINKS                += .putty/sessions/Default%20Settings
258 .putty/sessions/Default%20Settings_SRC = putty-defaults
259
260 DOTLINKS                += .config/gnome-session/sessions/mdw.session
261 .config/gnome-session/sessions/mdw.session_SRC = mdw.session
262
263 DOTLINKS                += .Eterm/themes/Eterm/theme.cfg
264 DOTLINKS                += .enlightenment/keybindings.cfg
265 DOTLINKS                += .enlightenment-vnc/keybindings.cfg
266 DOTLINKS                += .e16/bindings.cfg
267 .Eterm/themes/Eterm/theme.cfg_SRC = eterm-theme.cfg
268 .enlightenment/keybindings.cfg_SRC = e-keybindings.cfg
269 .enlightenment-vnc/keybindings.cfg_SRC = evnc-keybindings.cfg
270 .e16/bindings.cfg_SRC    = e16-bindings
271
272 DOTLINKS                += .gtkrc-2.0
273 DOTLINKS                += .config/gtk-3.0/gtk.css
274 DOTLINKS                += .config/gtk-3.0/settings.ini
275 .config/gtk-3.0/gtk.css_SRC = gtk3.css
276 .config/gtk-3.0/settings.ini_SRC = gtk3-settings.ini
277
278 SCRIPTLINKS             += xinitcmd lock-screen xshutdown
279 SCRIPTLINKS             += un-backslashify-selection
280 SCRIPTLINKS             += xpra-start-xdummy
281 SCRIPTLINKS             += play-rawk
282
283 DOTCPP                  += .Xdefaults
284 Xdefaults_DEFS           = -DEMACSWD=$(call mdw-conf,emacs-width,77)
285 $(HOME)/.Xdefaults: $(HOME)/.mdw.conf
286
287 ifeq ($(shell case $${DISPLAY-nil} in (:[0-9]*) echo t ;; (*) echo nil ;; esac),t)
288 dotfile-hook/.Xdefaults = \
289         $(call v_tag,XRDB)xrdb -override $<
290 endif
291
292 endif
293
294 ###--------------------------------------------------------------------------
295 ### Processing dotfiles.
296
297 dotfile-source           = $(HERE)/dot/$(or $($1_SRC), $(1:.%=%)$2)
298
299 ## Easiest: just make symlinks.
300 dotlink-ok-p             = \
301         $(call symlink-ok-p,$(HOME)/$1,$(call dotfile-source,$1))
302 all:: $(addprefix $(HOME)/, $(DOTLINKS))
303 $(addprefix $(HOME)/, $(subst %,\%,$(DOTLINKS))): $(HOME)/%: \
304                 $$(if $$(call dotlink-ok-p,$$*),,_force)
305         $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
306                 rm -f $@.new && \
307                 ln -s $(call dotfile-source,$*) $@.new && \
308                 mv $@.new $@
309         $(dotfile-hook/$*)
310
311 ## Hack with the C preprocessor.
312 all:: $(addprefix $(HOME)/, $(DOTCPP))
313 $(addprefix $(HOME)/, $(subst %,\%,$(DOTCPP))): $(HOME)/%: \
314                 $$(call dotfile-source,$$*) Makefile
315         $(call v_tag,CPP)mkdir -p $(dir $@) && \
316                 rm -f $@.new && \
317                 cpp -P -o$@.new $($*_DEFS) $< && \
318                 mv $@.new $@
319         $(dotfile-hook/$*)
320
321 ## Hack by making simple substitutions.
322 substvar                 = -e $(call quote,s\a@$1@\a$2\ag)
323 SUBSTS                  += $(call substvar,home,$(HOME))
324 SUBSTS                  += $(call substvar,profile,$(HERE))
325 all:: $(addprefix $(HOME)/, $(DOTSUBST))
326 $(addprefix $(HOME)/, $(subst %,\%,$(DOTSUBST))): $(HOME)/%: \
327                 $$(call dotfile-source,$$*,.in) Makefile
328         $(call v_tag,SUBST)mkdir -p $(dir $@) && \
329                 rm -f $@.new && \
330                 sed -e "1i\
331 $(relax)### generated by $(HERE)/Makefile; do not edit!" \
332                         $(SUBSTS) $($*_SUBSTS) \
333                         $(call dotfile-source,$*,.in) >$@.new && \
334                 mv $@.new $@
335         $(dotfile-hook/$*)
336
337 ###--------------------------------------------------------------------------
338 ### Processing script links.
339
340 script-source            = $(HERE)/bin/$(or $($1_SRC), $1)
341 scriptlink-ok-p          = \
342         $(call symlink-ok-p,$(HOME)/bin/$1,$(call script-source,$1))
343 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
344 $(addprefix $(HOME)/bin/, $(SCRIPTLINKS)): $(HOME)/bin/%: \
345                 $$(if $$(call scriptlink-ok-p,$$*),,_force)
346         $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
347                 rm -f $@.new && \
348                 ln -s $(call script-source,$*) $@.new && \
349                 mv $@.new $@
350         $(script-hook/$*)
351
352 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
353
354 ###--------------------------------------------------------------------------
355 ### Building packages from source tarballs.
356
357 SRCDIR                   = $(HOME)/src/profile
358
359 pkg-builddir             = $(SRCDIR)/$1/build
360 pkg-stamp                = $(call pkg-builddir,$1)/$2-stamp
361
362 $(foreach p, $(PACKAGES), $(eval DEP_$p = $(if $(shell \
363         if $($p_CHECK) >/dev/null 2>&1 --version; then echo t; fi),, \
364         $(call pkg-stamp,$p,install))))
365
366 $(PACKAGES:%=$(SRCDIR)/%.tar.gz): $(SRCDIR)/%.tar.gz:
367         $(call v_tag,FETCH)mkdir -p $(SRCDIR) && \
368                 rm -f $@.new && \
369                 $(call get-url,$@.new,$(REPO)/$*.tar.gz) && \
370                 mv $@.new $@
371
372 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,unpack)): \
373                 $(call pkg-stamp,%,unpack): $(SRCDIR)/%.tar.gz
374         $(call v_tag,EXTRACT)rm -rf $(SRCDIR)/$* && \
375                 mkdir $(SRCDIR)/$*.tmp-unpack && \
376                 cd $(SRCDIR)/$*.tmp-unpack && \
377                 gzip -cd ../$*.tar.gz | tar xf - && \
378                 mv * ../$* && \
379                 cd .. && \
380                 rmdir $*.tmp-unpack && \
381                 mkdir $*/build && \
382                 touch $*/build/unpack-stamp
383
384 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,configure)): \
385                 $(call pkg-stamp,%,configure): \
386                 $(call pkg-stamp,%,unpack) \
387                 $$(foreach p, $$($$*_DEPS), $$(DEP_$$p))
388         $(call v_tag,CONFIG)cd $(dir $@) && \
389                 ../configure --prefix=$(HOME) \
390                         PKG_CONFIG_PATH=$(HOME)/lib/pkgconfig \
391                         $($*_CONFIG) >>buildlog 2>&1 && \
392                 touch configure-stamp
393
394 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,build)): \
395                 $(call pkg-stamp,%,build): \
396                 $(call pkg-stamp,%,configure)
397         $(call v_tag,BUILD)cd $(dir $@) && \
398                 $(MAKE) $($*_MAKEFLAGS) >>buildlog 2>&1 && \
399                 touch build-stamp
400
401 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,install)): \
402                 $(call pkg-stamp,%,install): \
403                 $(call pkg-stamp,%,build)
404         $(call v_tag,INSTALL)cd $(dir $@) && \
405                 $(MAKE) $($*_MAKEFLAGS) install >>buildlog 2>&1 && \
406                 touch install-stamp
407         $(package-hook/$*)
408
409 all:: $(foreach p, $(PACKAGES), $(DEP_$p))
410 $(foreach p, $(PACKAGES), $(eval _pkg.$p: $(call pkg-stamp,$p,install)))
411
412 ###----- That's all, folks --------------------------------------------------