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