chiark / gitweb /
dot/a2psrc: Basic configuration for `a2ps', which is stupid by default.
[profile] / Makefile
1 ## -*-makefile-*-
2
3 all::
4 .PHONY: all
5
6 clean::
7 .PHONY: clean
8
9 .SECONDEXPANSION: #sorry
10
11 ###--------------------------------------------------------------------------
12 ### Utilities.
13
14 ##
15 quote                    = '$(subst ','\'',$1)'#'
16
17 ## Suss out how to print stuff.
18 print                    = printf "%s" $(call quote,$1)
19
20 ## Looking configuration things up.
21 mdw-conf                 = $(shell bin/mdw-conf "$1" "$2")
22
23 ## Checking symlink targets.
24 symlink-ok-p             = $(shell \
25         case $$(readlink 2>/dev/null $1) in ($2) echo t ;; esac)
26
27 ## Silent rules machinery.
28 V                        = 0
29 V_AT                     = $(V_AT_$V)
30 V_AT_0                   = @
31 v_print                  = $(call v_print_$V,$1,$2)
32 v_print_0                = \
33         printf "  %-8s %s\n" "$1" $(call quote,$(patsubst $(HOME)/%,~/%,$2));
34 v_tag                    = $(V_AT)$(call v_print_$V,$1,$@)
35
36 ## Hack.
37 relax                    =
38
39 ###--------------------------------------------------------------------------
40 ### Configuration.
41
42 ## Figure out where I am.
43 HERE                    := $(shell pwd)
44
45 ## Decide on how to fetch things from URLs.
46 ifeq ($(shell (curl >/dev/null 2>&1 --version || [ $$? -eq 2 ]) && echo t),t)
47   get-url                = curl -fs -o $1 $2
48 else
49   get-url                = wget -q -O $1 $2
50 endif
51
52 ## Which Emacs should I use?
53 EMACS                   := $(shell \
54         emacs=nil; \
55         for i in emacs24 emacs23 emacs22 emacs21 emacs; do \
56           if type >/dev/null 2>&1 $$i; then emacs=$$i; break; fi; \
57         done; \
58         echo $$emacs)
59
60 ## Whence to obtain externally hosted stuff.
61 REPO                     = https://ftp.distorted.org.uk/u/mdw/profile
62
63 ## Additional local configuration.
64 -include local.mk
65
66 ###--------------------------------------------------------------------------
67 ### Some utility rules.
68
69 _force:
70 .PHONY: _force
71
72 ###--------------------------------------------------------------------------
73 ### Emacs.
74
75 ifneq ($(EMACS),nil)
76
77 EMACSLIB                 = $(HOME)/lib/emacs
78
79 EMACS_VERSION           := $(shell $(EMACS) 2>&1 -Q --batch --eval \
80         '(message "%s %s" emacs-major-version emacs-minor-version)' | \
81         tail -n1)
82 emacs-version-p          = $(shell set -- $(EMACS_VERSION); \
83         if [ $$1 -gt $1 ] || ([ $$1 -eq $1 ] && [ $$2 -ge $2 ]); then \
84           echo t; \
85         fi)
86
87 ELISP                   += make-regexp ew-hols
88 ELISP                   += mdw-gnus-patch
89 ELISP                   += mdw-multiple-cursors
90 ELISP                   += git git-blame vc-git stgit quilt
91
92 ifeq ($(call emacs-version-p,24,3),t)
93 ELISP                   += bracketed-paste
94 endif
95
96 ELISP                   += dot-emacs
97 dot-emacs_DEPS           = make-regexp
98
99 SCRIPTLINKS             += emacsclient-hack movemail-hack sendmail-hack
100 SCRIPTLINKS             += aspell-hack emerge-hack wakey.sh
101
102 %.elc: %.el $$(foreach e, $$($$*_DEPS), $$(DEP_$$e))
103         $(call v_tag,EMACS)if ! $(EMACS) >$*.build-log 2>&1 \
104                 -L el/ -L $(EMACSLIB) \
105                 --batch --no-site-file \
106                 --eval '(byte-compile-file "$<")'; then \
107           cat $*.build-log; exit 2; \
108         fi
109
110 LOCAL_ELISP              = $(filter $(notdir $(wildcard el/*.el)), \
111                                 $(addsuffix .el, $(ELISP)))
112 $(foreach e, $(LOCAL_ELISP), \
113         $(eval DEP_$(basename $e) = $(EMACSLIB)/$(e:.el=.elc)))
114 $(addprefix $(EMACSLIB)/, $(LOCAL_ELISP)): $(EMACSLIB)/%: el/%
115         $(call v_tag,SYMINK)mkdir -p $(EMACSLIB) && \
116                 rm -f $@.new && \
117                 ln -s $(HERE)/$< $@.new && \
118                 mv $@.new $@
119
120 REMOTE_ELISP             = $(filter-out $(notdir $(wildcard el/*.el)), \
121                                 $(addsuffix .el, $(ELISP)))
122 $(foreach e, $(REMOTE_ELISP), \
123         $(eval DEP_$(basename $e) = $(if $(shell \
124                 if $(EMACS) >/dev/null 2>&1 --no-site-file -q --batch \
125                         --eval ' \
126                           (progn \
127                             (kill-emacs (condition-case nil \
128                                             (progn (load-library "$e") 0) \
129                                           (error 1))))'; then \
130                   echo t; \
131                 fi),, $(EMACSLIB)/$(e:.el=.elc))))
132 $(addprefix $(EMACSLIB)/, $(REMOTE_ELISP)): $(EMACSLIB)/%:
133         $(call v_tag,FETCH)mkdir -p $(EMACSLIB) && \
134                 $(call get-url,$@.new,$(REPO)/$*) && \
135                 mv $@.new $@
136
137 DOTLINKS                += .emacs .emacs-calc .vm .gnus.el .ercrc.el
138
139 all:: $(foreach e, $(ELISP), $(DEP_$e))
140 $(foreach e, $(ELISP), $(eval _emacs.$e: $(EMACSLIB)/$e.elc))
141
142 endif
143
144 ###--------------------------------------------------------------------------
145 ### Other simpler things.
146
147 $(HOME)/.mdw.conf:
148         $(call v_tag,COPY)cp mdw.conf $@.new && mv $@.new $@
149
150 ## Utility packages.
151 PACKAGES                += mlib checkpath
152 mlib_CHECK               = crc-mktab
153 checkpath_CHECK          = tmpdir
154 checkpath_DEPS           = mlib
155
156 ## Packaging machinery.
157 SCRIPTLINKS             += mdw-build mdw-sbuild mdw-sbuild-server
158 SCRIPTLINKS             += update-buildable-branch
159 DOTLINKS                += .config/mdw-build.conf
160 .config/mdw-build.conf_SRC = mdw-build.conf
161
162 ## Shells.
163 DOTLINKS                += .profile .shell-rc .shell-logout
164 DOTLINKS                += .shrc
165 DOTLINKS                += .zprofile .zshrc .zlogout .zshenv
166 DOTLINKS                += .bash_profile .bash_completion .bash_logout
167 DOTLINKS                += .bashrc .inputrc
168 .bash_profile_SRC        = bash-profile
169 .bash_completion_SRC     = bash-completion
170 .bash_logout_SRC         = shell-logout
171 .zlogout_SRC             = shell-logout
172
173 all::
174         $(V_AT)if [ $(HOME)/.zcompdump -ot dot/zshrc ]; then \
175           $(call v_print,ZAP,$(HOME)/.zcompdump)rm -f $(HOME)/.zcompdump; \
176         fi
177
178 ## The Plan 9 `rc' shell.  This needs special hacking, because the Linux port
179 ## and Plan 9 From User Space have incompatible syntax.
180 DOTLINKS                += lib/profile
181 lib/profile_SRC          = rcrc
182 all:: $(HOME)/.rcrc
183 $(HOME)/.rcrc: dot/rcrc
184         $(call v_tag,SED)sed 's/; if not/else/' $< >$@.new && mv $@.new $@
185
186 ## Git.
187 DOTSUBST                += .gitconfig
188 SCRIPTLINKS             += git-copyright-dates
189 DOTLINKS                += .cgrc .tigrc
190 .gitconfig_SUBSTS        = \
191         $(call substvar,releasekey,$(call mdw-conf,releasekey,481334C2)) \
192         $(call substvar,email,$(call mdw-conf,email,mdw@distorted.org.uk))
193 $(HOME)/.gitconfig: $(HOME)/.mdw.conf
194
195 ## PulseAudio.
196 DOTLINKS                += .pulse/daemon.conf
197 DOTSUBST                += .pulse/default.pa
198 .pulse/daemon.conf_SRC   = pulse-daemon.conf
199 .pulse/default.pa_SRC    = pulse-default.pa.in
200
201 ## Other editors.
202 DOTLINKS                += .vimrc .mg .zile
203
204 ## Mail.
205 DOTLINKS                += .mailrc .signature .muttrc
206
207 ## Lisp.
208 DOTLINKS                += .cmucl-init.lisp .sbclrc .clisprc.lisp
209 DOTLINKS                += .eclrc .ccl-init.lisp .abclrc
210 .cmucl-init.lisp_SRC     = lisp-init.lisp
211 .sbclrc_SRC              = lisp-init.lisp
212 .clisprc.lisp_SRC        = lisp-init.lisp
213 .eclrc_SRC               = lisp-init.lisp
214 .ccl-init.lisp_SRC       = lisp-init.lisp
215 .abclrc_SRC              = lisp-init.lisp
216 DOTLINKS                += .swank.lisp
217
218 ## IPython.
219 DOTLINKS                += .ipython/profile_default/ipython_config.py
220 DOTLINKS                += .ipython/profile_default/startup/50-key-bindings.py
221 .ipython/profile_default/ipython_config.py_SRC = ipython-config.py
222 .ipython/profile_default/startup/50-key-bindings.py_SRC = ipython-key-bindings.py
223
224 ## Other languages.
225 DOTLINKS                += .guile
226 DOTLINKS                += .tclshrc .wishrc
227 .tclshrc_SRC             = tclshrc
228 .wishrc_SRC              = tclshrc
229
230 ## Jukebox things.
231 MISCLINKS               += lib/perl/DisOrder.pm
232 lib/perl/DisOrder.pm_SRC = pl/DisOrder.pm
233 SCRIPTLINKS             += disorder-switch-config
234 SCRIPTLINKS             += disorder-autoplay
235 SCRIPTLINKS             += disorder-notify
236
237 ## Random scripts.
238 SCRIPTLINKS             += mdw-editor mdw-pager
239 SCRIPTLINKS             += mdw-conf
240 SCRIPTLINKS             += svnwrap
241 SCRIPTLINKS             += guest-console
242 SCRIPTLINKS             += hyperspec
243 SCRIPTLINKS             += bdl
244 SCRIPTLINKS             += datasyms
245 SCRIPTLINKS             += fixsub
246 SCRIPTLINKS             += check-debsyms
247 SCRIPTLINKS             += check-blkdev-size
248
249 ## Random odds and ends.
250 DOTLINKS                += .infokey .sqliterc
251 DOTLINKS                += .gdbinit .toprc .aspell.conf
252 DOTLINKS                += .dircolors .colordiffrc .screenrc .tmux.conf
253 DOTLINKS                += .cvsrc .indent.pro .ditz-config
254 DOTLINKS                += .lftp/rc
255 .lftp/rc_SRC             = lftp-rc
256 DOTLINKS                += .a2ps/a2psrc
257 .a2ps/a2psrc_SRC         = a2psrc
258 DOTSUBST                += .mykermrc
259 SCRIPTLINKS             += lesspipe.sh
260
261 SCRIPTLINKS             += run-with-shell-env
262 SCRIPTLINKS             += start-ssh-agent start-ssh-pageant
263 SCRIPTLINKS             += add-ssh-keys
264 SCRIPTLINKS             += hacks/ssh/ssh
265 hacks/ssh/ssh_SRC        = hacks/ssh
266
267 DOTLINKS                += .w3m/config .elinks/elinks.conf
268 .w3m/config_SRC          = w3m-config
269 .elinks/elinks.conf_SRC  = elinks.conf
270
271 DOTLINKS                += .mc/ini .mc/panels.ini
272 .mc/ini_SRC              = mc-ini
273 .mc/panels.ini_SRC       = mc-panels.ini
274
275 DOTLINKS                += .parallel/config .parallel/sshloginfile
276 .parallel/config_SRC     = parallel-config
277 .parallel/sshloginfile_SRC = parallel-hosts
278
279 all:: $(HOME)/.less
280 $(HOME)/.less: dot/lesskey
281         $(V_AT)rm -f $(HOME)/.lesskey
282         $(call v_tag,LESSKEY)lesskey -o$@ $<
283
284 ###--------------------------------------------------------------------------
285 ### X11 configuration.
286
287 ifeq ($X,t)
288
289 PACKAGES                += xtoys
290 xtoys_CHECK              = xatom
291 xtoys_DEPS               = mlib
292
293 DOTLINKS                += .xinitrc .xsession .xmodmap .vncrc .vncsession
294 DOTLINKS                += .config/fontconfig/fonts.conf
295 .config/fontconfig/fonts.conf_SRC = fonts.conf
296 DOTLINKS                += .stalonetrayrc
297
298 DOTLINKS                += .config/gnome-session/sessions/mdw.session
299 .config/gnome-session/sessions/mdw.session_SRC = mdw.session
300
301 DOTLINKS                += .Eterm/themes/Eterm/theme.cfg
302 DOTLINKS                += .enlightenment/keybindings.cfg
303 DOTLINKS                += .enlightenment-vnc/keybindings.cfg
304 DOTLINKS                += .e16/bindings.cfg
305 .Eterm/themes/Eterm/theme.cfg_SRC = eterm-theme.cfg
306 .enlightenment/keybindings.cfg_SRC = e-keybindings.cfg
307 .enlightenment-vnc/keybindings.cfg_SRC = evnc-keybindings.cfg
308 .e16/bindings.cfg_SRC    = e16-bindings
309
310 DOTLINKS                += .gtkrc-2.0
311 DOTLINKS                += .config/gtk-3.0/gtk.css
312 DOTLINKS                += .config/gtk-3.0/settings.ini
313 .config/gtk-3.0/gtk.css_SRC = gtk3.css
314 .config/gtk-3.0/settings.ini_SRC = gtk3-settings.ini
315
316 DOTLINKS                += .config/user-dirs.dirs .config/user-dirs.locale
317 .config/user-dirs.dirs_SRC = user-dirs.dirs
318 .config/user-dirs.locale_SRC = user-dirs.locale
319
320 SCRIPTLINKS             += xinitcmd lock-screen xshutdown
321 SCRIPTLINKS             += un-backslashify-selection
322 SCRIPTLINKS             += xpra-start-xdummy
323 SCRIPTLINKS             += play-rawk
324 SCRIPTLINKS             += xduplic-terminal
325
326 DOTCPP                  += .Xdefaults
327 Xdefaults_DEFS           = -DEMACSWD=$(call mdw-conf,emacs-width,77)
328 $(HOME)/.Xdefaults: $(HOME)/.mdw.conf dot/Xdefaults.pterm
329
330 ifeq ($(shell case $${DISPLAY-nil} in (:[0-9]*) echo t ;; (*) echo nil ;; esac),t)
331 dotfile-hook/.Xdefaults = \
332         $(call v_tag,XRDB)xrdb -load $<
333 endif
334
335 endif
336
337 ###--------------------------------------------------------------------------
338 ### Firefox things.
339
340 ifeq ($(FIREFOX),t)
341
342 out/:
343         $(call v_tag,MKDIR)mkdir $@
344
345 out/firefox/: | out/
346         $(call v_tag,MKDIR)mkdir $@
347
348 clean::; rm -rf out/
349
350 all:: out/firefox/smartup-gestures.config
351 out/firefox/smartup-gestures.config: firefox/smartup-gestures.json | out/firefox/
352         $(call v_tag,BLOB)\
353                 jq -c . $< | bincode base64 >$@.new && mv $@.new $@
354
355 all:: out/firefox/stylus.json
356 out/firefox/stylus.json: firefox/stylus/ firefox/stylus/*.css | out/firefox/
357         $(call v_tag,IMPLODE)\
358                 firefox/implode-stylus firefox/stylus/ >$@.new && \
359                         mv $@.new $@
360 endif
361
362 ###--------------------------------------------------------------------------
363 ### General symlinking.
364
365 misclink-source          = $(HERE)/$(or $($1_SRC), $1)
366
367 all:: $(addprefix $(HOME)/, $(MISCLINKS))
368 misclink-ok-p            = \
369         $(call symlink-ok-p,$(HOME)/$1,$(call misclink-source,$1))
370 $(addprefix $(HOME)/, $(subst %,\%,$(MISCLINKS))): $(HOME)/%: \
371                 $$(if $$(call misclink-ok-p,$$*),,_force)
372         $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
373                 rm -f $@.new && \
374                 ln -s $(call misclink-source,$*) $@.new && \
375                 mv $@.new $@
376         $(symlink-hook/$*)
377
378 ###--------------------------------------------------------------------------
379 ### Processing dotfiles.
380
381 dotfile-source           = $(HERE)/dot/$(or $($1_SRC), $(1:.%=%)$2)
382
383 ## Easiest: just make symlinks.
384 dotlink-ok-p             = \
385         $(call symlink-ok-p,$(HOME)/$1,$(call dotfile-source,$1))
386 all:: $(addprefix $(HOME)/, $(DOTLINKS))
387 $(addprefix $(HOME)/, $(subst %,\%,$(DOTLINKS))): $(HOME)/%: \
388                 $$(if $$(call dotlink-ok-p,$$*),,_force)
389         $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
390                 rm -f $@.new && \
391                 ln -s $(call dotfile-source,$*) $@.new && \
392                 mv $@.new $@
393         $(dotfile-hook/$*)
394
395 ## Hack with the C preprocessor.
396 all:: $(addprefix $(HOME)/, $(DOTCPP))
397 $(addprefix $(HOME)/, $(subst %,\%,$(DOTCPP))): $(HOME)/%: \
398                 $$(call dotfile-source,$$*) Makefile
399         $(call v_tag,CPP)mkdir -p $(dir $@) && \
400                 rm -f $@.new && \
401                 cpp -P -o$@.new $($*_DEFS) $< && \
402                 mv $@.new $@
403         $(dotfile-hook/$*)
404
405 ## Hack by making simple substitutions.
406 substvar                 = -e $(call quote,s\a@$1@\a$2\ag)
407 SUBSTS                  += $(call substvar,home,$(HOME))
408 SUBSTS                  += $(call substvar,profile,$(HERE))
409 all:: $(addprefix $(HOME)/, $(DOTSUBST))
410 $(addprefix $(HOME)/, $(subst %,\%,$(DOTSUBST))): $(HOME)/%: \
411                 $$(call dotfile-source,$$*,.in) Makefile
412         $(call v_tag,SUBST)mkdir -p $(dir $@) && \
413                 rm -f $@.new && \
414                 sed -e "1i\
415 $(relax)### generated by $(HERE)/Makefile; do not edit!" \
416                         $(SUBSTS) $($*_SUBSTS) \
417                         $(call dotfile-source,$*,.in) >$@.new && \
418                 mv $@.new $@
419         $(dotfile-hook/$*)
420
421 ###--------------------------------------------------------------------------
422 ### Processing script links.
423
424 script-source            = $(HERE)/bin/$(or $($1_SRC), $1)
425
426 ifeq ($(prefix-shebang-p),t)
427 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
428 $(addprefix $(HOME)/bin/, $(SCRIPTLINKS)): $(HOME)/bin/%: \
429                 $$(call script-source,$$*) Makefile
430         $(call v_tag,SHEBANG)mkdir -p $(dir $@) && \
431                 rm -f $@.new && \
432                 sed "1s\a\(#! *\)/\a\1$(SHEBANG_PREFIX)/\a" \
433                         $(call script-source,$*) >$@.new && \
434                 chmod --reference=$(call script-source,$*) $@.new && \
435                 mv $@.new $@
436         $(script-hook/$*)
437 else
438 scriptlink-ok-p          = \
439         $(call symlink-ok-p,$(HOME)/bin/$1,$(call script-source,$1))
440 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
441 $(addprefix $(HOME)/bin/, $(SCRIPTLINKS)): $(HOME)/bin/%: \
442                 $$(if $$(call scriptlink-ok-p,$$*),,_force)
443         $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
444                 rm -f $@.new && \
445                 ln -s $(call script-source,$*) $@.new && \
446                 mv $@.new $@
447         $(script-hook/$*)
448 endif
449
450 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
451
452 ###--------------------------------------------------------------------------
453 ### Building packages from source tarballs.
454
455 SRCDIR                   = $(HOME)/src/profile
456
457 pkg-builddir             = $(SRCDIR)/$1/build
458 pkg-stamp                = $(call pkg-builddir,$1)/$2-stamp
459
460 $(foreach p, $(PACKAGES), $(eval DEP_$p = $(if $(shell \
461         if $($p_CHECK) >/dev/null 2>&1 --version; then echo t; fi),, \
462         $(call pkg-stamp,$p,install))))
463
464 $(PACKAGES:%=$(SRCDIR)/%.tar.gz): $(SRCDIR)/%.tar.gz:
465         $(call v_tag,FETCH)mkdir -p $(SRCDIR) && \
466                 rm -f $@.new && \
467                 $(call get-url,$@.new,$(REPO)/$*.tar.gz) && \
468                 mv $@.new $@
469
470 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,unpack)): \
471                 $(call pkg-stamp,%,unpack): $(SRCDIR)/%.tar.gz
472         $(call v_tag,EXTRACT)rm -rf $(SRCDIR)/$* && \
473                 mkdir $(SRCDIR)/$*.tmp-unpack && \
474                 cd $(SRCDIR)/$*.tmp-unpack && \
475                 gzip -cd ../$*.tar.gz | tar xf - && \
476                 mv * ../$* && \
477                 cd .. && \
478                 rmdir $*.tmp-unpack && \
479                 mkdir $*/build && \
480                 touch $*/build/unpack-stamp
481
482 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,configure)): \
483                 $(call pkg-stamp,%,configure): \
484                 $(call pkg-stamp,%,unpack) \
485                 $$(foreach p, $$($$*_DEPS), $$(DEP_$$p))
486         $(call v_tag,CONFIG)cd $(dir $@) && \
487                 ../configure --prefix=$(HOME) \
488                         PKG_CONFIG_PATH=$(HOME)/lib/pkgconfig \
489                         $($*_CONFIG) >>buildlog 2>&1 && \
490                 touch configure-stamp
491
492 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,build)): \
493                 $(call pkg-stamp,%,build): \
494                 $(call pkg-stamp,%,configure)
495         $(call v_tag,BUILD)cd $(dir $@) && \
496                 $(MAKE) $($*_MAKEFLAGS) >>buildlog 2>&1 && \
497                 touch build-stamp
498
499 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,install)): \
500                 $(call pkg-stamp,%,install): \
501                 $(call pkg-stamp,%,build)
502         $(call v_tag,INSTALL)cd $(dir $@) && \
503                 $(MAKE) $($*_MAKEFLAGS) install >>buildlog 2>&1 && \
504                 touch install-stamp
505         $(package-hook/$*)
506
507 all:: $(foreach p, $(PACKAGES), $(DEP_$p))
508 $(foreach p, $(PACKAGES), $(eval _pkg.$p: $(call pkg-stamp,$p,install)))
509
510 ###----- That's all, folks --------------------------------------------------