dot/shell-rc: Write the various control sequences to the terminal explicitly.
[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
154
155## Shells.
156DOTLINKS += .profile .shell-rc .shell-logout
a3857ab2 157DOTLINKS += .shrc
9ba9bb2f
MW
158DOTLINKS += .zprofile .zshrc .zlogout .zshenv
159DOTLINKS += .bash_profile .bash_completion .bash_logout
160DOTLINKS += .bashrc .inputrc
67b1a15a
MW
161.bash_profile_SRC = bash-profile
162.bash_completion_SRC = bash-completion
9ba9bb2f
MW
163.bash_logout_SRC = shell-logout
164.zlogout_SRC = shell-logout
67b1a15a 165
72123a3a
MW
166all::
167 $(V_AT)if [ $(HOME)/.zcompdump -ot dot/zshrc ]; then \
168 $(call v_print,ZAP,$(HOME)/.zcompdump)rm -f $(HOME)/.zcompdump; \
169 fi
170
a3857ab2
MW
171## The Plan 9 `rc' shell. This needs special hacking, because the Linux port
172## and Plan 9 From User Space have incompatible syntax.
173DOTLINKS += lib/profile
174lib/profile_SRC = rcrc
175all:: $(HOME)/.rcrc
176$(HOME)/.rcrc: dot/rcrc
177 $(call v_tag,SED)sed 's/; if not/else/' $< >$@.new && mv $@.new $@
178
67b1a15a
MW
179## Git.
180DOTSUBST += .gitconfig
2e15741e 181SCRIPTLINKS += git-copyright-dates
67b1a15a
MW
182DOTLINKS += .cgrc .tigrc
183.gitconfig_SUBSTS = \
9ca6d190
MW
184 $(call substvar,releasekey,$(call mdw-conf,releasekey,481334C2)) \
185 $(call substvar,email,$(call mdw-conf,email,mdw@distorted.org.uk))
67b1a15a
MW
186$(HOME)/.gitconfig: $(HOME)/.mdw.conf
187
188## PulseAudio.
189DOTLINKS += .pulse/daemon.conf
190DOTSUBST += .pulse/default.pa
191.pulse/daemon.conf_SRC = pulse-daemon.conf
192.pulse/default.pa_SRC = pulse-default.pa.in
193
194## Other editors.
195DOTLINKS += .vimrc .mg .zile
196
197## Mail.
198DOTLINKS += .mailrc .signature .muttrc
199
200## Lisp.
201DOTLINKS += .cmucl-init.lisp .sbclrc .clisprc.lisp .eclrc
202.cmucl-init.lisp_SRC = lisp-init.lisp
203.sbclrc_SRC = lisp-init.lisp
204.clisprc.lisp_SRC = lisp-init.lisp
205.eclrc_SRC = lisp-init.lisp
206DOTLINKS += .swank.lisp
207
208## IPython.
209DOTLINKS += .ipython/profile_default/ipython_config.py
210DOTLINKS += .ipython/profile_default/startup/50-key-bindings.py
211.ipython/profile_default/ipython_config.py_SRC = ipython-config.py
212.ipython/profile_default/startup/50-key-bindings.py_SRC = ipython-key-bindings.py
213
214## Other languages.
215DOTLINKS += .guile
216DOTLINKS += .tclshrc .wishrc
217.tclshrc_SRC = tclshrc
218.wishrc_SRC = tclshrc
219
220## Random scripts.
221SCRIPTLINKS += mdw-editor mdw-pager
222SCRIPTLINKS += mdw-conf
223SCRIPTLINKS += svnwrap
224SCRIPTLINKS += guest-console
225SCRIPTLINKS += hyperspec
878a38bd 226SCRIPTLINKS += datasyms
01a5d0a6 227SCRIPTLINKS += check-debsyms
a98bca79 228SCRIPTLINKS += check-blkdev-size
67b1a15a
MW
229
230## Random odds and ends.
3f7369a9 231DOTLINKS += .infokey .sqliterc
67b1a15a
MW
232DOTLINKS += .gdbinit .toprc .aspell.conf
233DOTLINKS += .dircolors .colordiffrc .screenrc .tmux.conf
234DOTLINKS += .cvsrc .indent.pro .ditz-config
da526ba7
MW
235DOTLINKS += .lftp/rc
236.lftp/rc_SRC = lftp-rc
67b1a15a
MW
237DOTSUBST += .mykermrc
238SCRIPTLINKS += lesspipe.sh
239
240SCRIPTLINKS += run-with-shell-env
241SCRIPTLINKS += start-ssh-agent start-ssh-pageant
242SCRIPTLINKS += add-ssh-keys
243SCRIPTLINKS += hacks/ssh/ssh
244hacks/ssh/ssh_SRC = hacks/ssh
245
246DOTLINKS += .w3m/config .elinks/elinks.conf
247.w3m/config_SRC = w3m-config
248.elinks/elinks.conf_SRC = elinks.conf
249
250DOTLINKS += .mc/ini .mc/panels.ini
251.mc/ini_SRC = mc-ini
252.mc/panels.ini_SRC = mc-panels.ini
253
254DOTLINKS += .parallel/config
255.parallel/config_SRC = parallel-config
256
3f7369a9
MW
257all:: $(HOME)/.less
258$(HOME)/.less: dot/lesskey
259 $(V_AT)rm -f $(HOME)/.lesskey
260 $(call v_tag,LESSKEY)lesskey -o$@ $<
261
67b1a15a
MW
262###--------------------------------------------------------------------------
263### X11 configuration.
264
265ifeq ($X,t)
266
267PACKAGES += xtoys
268xtoys_CHECK = xatom
269xtoys_DEPS = mlib
270
271DOTLINKS += .xinitrc .xsession .xmodmap .vncrc .vncsession
df4bcc77
MW
272DOTLINKS += .config/fontconfig/fonts.conf
273.config/fontconfig/fonts.conf_SRC = fonts.conf
67b1a15a
MW
274DOTLINKS += .stalonetrayrc
275
276DOTLINKS += .putty/sessions/Default%20Settings
277.putty/sessions/Default%20Settings_SRC = putty-defaults
278
279DOTLINKS += .config/gnome-session/sessions/mdw.session
280.config/gnome-session/sessions/mdw.session_SRC = mdw.session
281
282DOTLINKS += .Eterm/themes/Eterm/theme.cfg
283DOTLINKS += .enlightenment/keybindings.cfg
284DOTLINKS += .enlightenment-vnc/keybindings.cfg
285DOTLINKS += .e16/bindings.cfg
286.Eterm/themes/Eterm/theme.cfg_SRC = eterm-theme.cfg
287.enlightenment/keybindings.cfg_SRC = e-keybindings.cfg
288.enlightenment-vnc/keybindings.cfg_SRC = evnc-keybindings.cfg
289.e16/bindings.cfg_SRC = e16-bindings
290
291DOTLINKS += .gtkrc-2.0
292DOTLINKS += .config/gtk-3.0/gtk.css
293DOTLINKS += .config/gtk-3.0/settings.ini
294.config/gtk-3.0/gtk.css_SRC = gtk3.css
295.config/gtk-3.0/settings.ini_SRC = gtk3-settings.ini
296
297SCRIPTLINKS += xinitcmd lock-screen xshutdown
298SCRIPTLINKS += un-backslashify-selection
299SCRIPTLINKS += xpra-start-xdummy
5f9b345a 300SCRIPTLINKS += play-rawk
5078756e 301SCRIPTLINKS += media-keys
6bdf3aad 302SCRIPTLINKS += disorder-notify
67b1a15a
MW
303
304DOTCPP += .Xdefaults
305Xdefaults_DEFS = -DEMACSWD=$(call mdw-conf,emacs-width,77)
306$(HOME)/.Xdefaults: $(HOME)/.mdw.conf
307
ddc97f65
MW
308ifeq ($(shell case $${DISPLAY-nil} in (:[0-9]*) echo t ;; (*) echo nil ;; esac),t)
309dotfile-hook/.Xdefaults = \
310 $(call v_tag,XRDB)xrdb -override $<
311endif
312
67b1a15a
MW
313endif
314
315###--------------------------------------------------------------------------
316### Processing dotfiles.
317
318dotfile-source = $(HERE)/dot/$(or $($1_SRC), $(1:.%=%)$2)
319
4937ba2d 320## Easiest: just make symlinks.
67b1a15a
MW
321dotlink-ok-p = \
322 $(call symlink-ok-p,$(HOME)/$1,$(call dotfile-source,$1))
323all:: $(addprefix $(HOME)/, $(DOTLINKS))
324$(addprefix $(HOME)/, $(subst %,\%,$(DOTLINKS))): $(HOME)/%: \
325 $$(if $$(call dotlink-ok-p,$$*),,_force)
326 $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
327 rm -f $@.new && \
328 ln -s $(call dotfile-source,$*) $@.new && \
329 mv $@.new $@
f6c3a80b 330 $(dotfile-hook/$*)
67b1a15a
MW
331
332## Hack with the C preprocessor.
333all:: $(addprefix $(HOME)/, $(DOTCPP))
334$(addprefix $(HOME)/, $(subst %,\%,$(DOTCPP))): $(HOME)/%: \
335 $$(call dotfile-source,$$*) Makefile
336 $(call v_tag,CPP)mkdir -p $(dir $@) && \
337 rm -f $@.new && \
338 cpp -P -o$@.new $($*_DEFS) $< && \
339 mv $@.new $@
f6c3a80b 340 $(dotfile-hook/$*)
67b1a15a
MW
341
342## Hack by making simple substitutions.
343substvar = -e $(call quote,s\a@$1@\a$2\ag)
344SUBSTS += $(call substvar,home,$(HOME))
345SUBSTS += $(call substvar,profile,$(HERE))
346all:: $(addprefix $(HOME)/, $(DOTSUBST))
347$(addprefix $(HOME)/, $(subst %,\%,$(DOTSUBST))): $(HOME)/%: \
33271a96 348 $$(call dotfile-source,$$*,.in) Makefile
67b1a15a
MW
349 $(call v_tag,SUBST)mkdir -p $(dir $@) && \
350 rm -f $@.new && \
351 sed -e "1i\
352$(relax)### generated by $(HERE)/Makefile; do not edit!" \
353 $(SUBSTS) $($*_SUBSTS) \
354 $(call dotfile-source,$*,.in) >$@.new && \
355 mv $@.new $@
f6c3a80b 356 $(dotfile-hook/$*)
67b1a15a
MW
357
358###--------------------------------------------------------------------------
359### Processing script links.
360
361script-source = $(HERE)/bin/$(or $($1_SRC), $1)
0cd3b798
MW
362
363ifeq ($(prefix-shebang-p),t)
364all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
365$(addprefix $(HOME)/bin/, $(SCRIPTLINKS)): $(HOME)/bin/%: \
366 $$(call script-source,$$*) Makefile
367 $(call v_tag,SHEBANG)mkdir -p $(dir $@) && \
368 rm -f $@.new && \
369 sed "1s\a\(#! *\)/\a\1$(SHEBANG_PREFIX)/\a" \
370 $(call script-source,$*) >$@.new && \
371 chmod --reference=$(call script-source,$*) $@.new && \
372 mv $@.new $@
373 $(script-hook/$*)
374else
67b1a15a
MW
375scriptlink-ok-p = \
376 $(call symlink-ok-p,$(HOME)/bin/$1,$(call script-source,$1))
377all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
378$(addprefix $(HOME)/bin/, $(SCRIPTLINKS)): $(HOME)/bin/%: \
379 $$(if $$(call scriptlink-ok-p,$$*),,_force)
380 $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
381 rm -f $@.new && \
382 ln -s $(call script-source,$*) $@.new && \
383 mv $@.new $@
f6c3a80b 384 $(script-hook/$*)
0cd3b798 385endif
67b1a15a
MW
386
387all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
388
389###--------------------------------------------------------------------------
390### Building packages from source tarballs.
391
392SRCDIR = $(HOME)/src/profile
393
394pkg-builddir = $(SRCDIR)/$1/build
395pkg-stamp = $(call pkg-builddir,$1)/$2-stamp
396
397$(foreach p, $(PACKAGES), $(eval DEP_$p = $(if $(shell \
398 if $($p_CHECK) >/dev/null 2>&1 --version; then echo t; fi),, \
399 $(call pkg-stamp,$p,install))))
400
401$(PACKAGES:%=$(SRCDIR)/%.tar.gz): $(SRCDIR)/%.tar.gz:
402 $(call v_tag,FETCH)mkdir -p $(SRCDIR) && \
403 rm -f $@.new && \
404 $(call get-url,$@.new,$(REPO)/$*.tar.gz) && \
405 mv $@.new $@
406
407$(foreach p, $(PACKAGES), $(call pkg-stamp,$p,unpack)): \
408 $(call pkg-stamp,%,unpack): $(SRCDIR)/%.tar.gz
409 $(call v_tag,EXTRACT)rm -rf $(SRCDIR)/$* && \
410 mkdir $(SRCDIR)/$*.tmp-unpack && \
411 cd $(SRCDIR)/$*.tmp-unpack && \
412 gzip -cd ../$*.tar.gz | tar xf - && \
413 mv * ../$* && \
414 cd .. && \
415 rmdir $*.tmp-unpack && \
416 mkdir $*/build && \
417 touch $*/build/unpack-stamp
418
419$(foreach p, $(PACKAGES), $(call pkg-stamp,$p,configure)): \
420 $(call pkg-stamp,%,configure): \
421 $(call pkg-stamp,%,unpack) \
422 $$(foreach p, $$($$*_DEPS), $$(DEP_$$p))
423 $(call v_tag,CONFIG)cd $(dir $@) && \
424 ../configure --prefix=$(HOME) \
425 PKG_CONFIG_PATH=$(HOME)/lib/pkgconfig \
426 $($*_CONFIG) >>buildlog 2>&1 && \
427 touch configure-stamp
428
429$(foreach p, $(PACKAGES), $(call pkg-stamp,$p,build)): \
430 $(call pkg-stamp,%,build): \
431 $(call pkg-stamp,%,configure)
432 $(call v_tag,BUILD)cd $(dir $@) && \
433 $(MAKE) $($*_MAKEFLAGS) >>buildlog 2>&1 && \
434 touch build-stamp
435
436$(foreach p, $(PACKAGES), $(call pkg-stamp,$p,install)): \
437 $(call pkg-stamp,%,install): \
438 $(call pkg-stamp,%,build)
439 $(call v_tag,INSTALL)cd $(dir $@) && \
440 $(MAKE) $($*_MAKEFLAGS) install >>buildlog 2>&1 && \
441 touch install-stamp
f6c3a80b 442 $(package-hook/$*)
67b1a15a
MW
443
444all:: $(foreach p, $(PACKAGES), $(DEP_$p))
445$(foreach p, $(PACKAGES), $(eval _pkg.$p: $(call pkg-stamp,$p,install)))
446
447###----- That's all, folks --------------------------------------------------