dot/emacs: Don't use a gratuitously different label on icons.
[profile] / Makefile
... / ...
CommitLineData
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
24V_AT = $(V_AT_$V)
25V_AT_0 = @
26v_print = $(call v_print_$V,$1,$2)
27v_print_0 = \
28 printf " %-8s %s\n" "$1" $(call quote,$(patsubst $(HOME)/%,~/%,$2));
29v_tag = $(V_AT)$(call v_print_$V,$1,$@)
30
31## Hack.
32relax =
33
34###--------------------------------------------------------------------------
35### Configuration.
36
37## Figure out where I am.
38HERE := $(shell pwd)
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 \
51 if type >/dev/null 2>&1 $$i; then emacs=$$i; break; fi; \
52 done; \
53 echo $$emacs)
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
70ifneq ($(EMACS),nil)
71
72EMACSLIB = $(HOME)/lib/emacs
73
74EMACS_VERSION := $(shell $(EMACS) 2>&1 -Q --batch --eval \
75 '(message "%s %s" emacs-major-version emacs-minor-version)' | \
76 tail -n1)
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
82ELISP += make-regexp ew-hols
83ELISP += mdw-gnus-patch
84ELISP += mdw-multiple-cursors
85ELISP += git git-blame vc-git stgit quilt
86
87ifeq ($(call emacs-version-p,24,3),t)
88ELISP += bracketed-paste
89endif
90
91ELISP += dot-emacs
92dot-emacs_DEPS = make-regexp
93
94SCRIPTLINKS += emacsclient-hack movemail-hack sendmail-hack
95SCRIPTLINKS += aspell-hack emerge-hack wakey.sh
96
97%.elc: %.el $$(foreach e, $$($$*_DEPS), $$(DEP_$$e))
98 $(call v_tag,EMACS)if ! $(EMACS) >$*.build-log 2>&1 \
99 -L el/ -L $(EMACSLIB) \
100 --batch --no-site-file \
101 --eval '(byte-compile-file "$<")'; then \
102 cat $*.build-log; exit 2; \
103 fi
104
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)))
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)), \
116 $(addsuffix .el, $(ELISP)))
117$(foreach e, $(REMOTE_ELISP), \
118 $(eval DEP_$(basename $e) = $(if $(shell \
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))
135$(foreach e, $(ELISP), $(eval _emacs.$e: $(EMACSLIB)/$e.elc))
136
137endif
138
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
157DOTLINKS += .shrc
158DOTLINKS += .zprofile .zshrc .zlogout .zshenv
159DOTLINKS += .bash_profile .bash_completion .bash_logout
160DOTLINKS += .bashrc .inputrc
161.bash_profile_SRC = bash-profile
162.bash_completion_SRC = bash-completion
163.bash_logout_SRC = shell-logout
164.zlogout_SRC = shell-logout
165
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
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
179## Git.
180DOTSUBST += .gitconfig
181SCRIPTLINKS += git-copyright-dates
182DOTLINKS += .cgrc .tigrc
183.gitconfig_SUBSTS = \
184 $(call substvar,releasekey,$(call mdw-conf,releasekey,481334C2)) \
185 $(call substvar,email,$(call mdw-conf,email,mdw@distorted.org.uk))
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
226SCRIPTLINKS += datasyms
227SCRIPTLINKS += fixsub
228SCRIPTLINKS += check-debsyms
229SCRIPTLINKS += check-blkdev-size
230
231## Random odds and ends.
232DOTLINKS += .infokey .sqliterc
233DOTLINKS += .gdbinit .toprc .aspell.conf
234DOTLINKS += .dircolors .colordiffrc .screenrc .tmux.conf
235DOTLINKS += .cvsrc .indent.pro .ditz-config
236DOTLINKS += .lftp/rc
237.lftp/rc_SRC = lftp-rc
238DOTSUBST += .mykermrc
239SCRIPTLINKS += lesspipe.sh
240
241SCRIPTLINKS += run-with-shell-env
242SCRIPTLINKS += start-ssh-agent start-ssh-pageant
243SCRIPTLINKS += add-ssh-keys
244SCRIPTLINKS += hacks/ssh/ssh
245hacks/ssh/ssh_SRC = hacks/ssh
246
247DOTLINKS += .w3m/config .elinks/elinks.conf
248.w3m/config_SRC = w3m-config
249.elinks/elinks.conf_SRC = elinks.conf
250
251DOTLINKS += .mc/ini .mc/panels.ini
252.mc/ini_SRC = mc-ini
253.mc/panels.ini_SRC = mc-panels.ini
254
255DOTLINKS += .parallel/config
256.parallel/config_SRC = parallel-config
257
258all:: $(HOME)/.less
259$(HOME)/.less: dot/lesskey
260 $(V_AT)rm -f $(HOME)/.lesskey
261 $(call v_tag,LESSKEY)lesskey -o$@ $<
262
263###--------------------------------------------------------------------------
264### X11 configuration.
265
266ifeq ($X,t)
267
268PACKAGES += xtoys
269xtoys_CHECK = xatom
270xtoys_DEPS = mlib
271
272DOTLINKS += .xinitrc .xsession .xmodmap .vncrc .vncsession
273DOTLINKS += .config/fontconfig/fonts.conf
274.config/fontconfig/fonts.conf_SRC = fonts.conf
275DOTLINKS += .stalonetrayrc
276
277DOTLINKS += .putty/sessions/Default%20Settings
278.putty/sessions/Default%20Settings_SRC = putty-defaults
279
280DOTLINKS += .config/gnome-session/sessions/mdw.session
281.config/gnome-session/sessions/mdw.session_SRC = mdw.session
282
283DOTLINKS += .Eterm/themes/Eterm/theme.cfg
284DOTLINKS += .enlightenment/keybindings.cfg
285DOTLINKS += .enlightenment-vnc/keybindings.cfg
286DOTLINKS += .e16/bindings.cfg
287.Eterm/themes/Eterm/theme.cfg_SRC = eterm-theme.cfg
288.enlightenment/keybindings.cfg_SRC = e-keybindings.cfg
289.enlightenment-vnc/keybindings.cfg_SRC = evnc-keybindings.cfg
290.e16/bindings.cfg_SRC = e16-bindings
291
292DOTLINKS += .gtkrc-2.0
293DOTLINKS += .config/gtk-3.0/gtk.css
294DOTLINKS += .config/gtk-3.0/settings.ini
295.config/gtk-3.0/gtk.css_SRC = gtk3.css
296.config/gtk-3.0/settings.ini_SRC = gtk3-settings.ini
297
298SCRIPTLINKS += xinitcmd lock-screen xshutdown
299SCRIPTLINKS += un-backslashify-selection
300SCRIPTLINKS += xpra-start-xdummy
301SCRIPTLINKS += play-rawk
302SCRIPTLINKS += media-keys
303SCRIPTLINKS += disorder-notify
304
305DOTCPP += .Xdefaults
306Xdefaults_DEFS = -DEMACSWD=$(call mdw-conf,emacs-width,77)
307$(HOME)/.Xdefaults: $(HOME)/.mdw.conf
308
309ifeq ($(shell case $${DISPLAY-nil} in (:[0-9]*) echo t ;; (*) echo nil ;; esac),t)
310dotfile-hook/.Xdefaults = \
311 $(call v_tag,XRDB)xrdb -override $<
312endif
313
314endif
315
316###--------------------------------------------------------------------------
317### Processing dotfiles.
318
319dotfile-source = $(HERE)/dot/$(or $($1_SRC), $(1:.%=%)$2)
320
321## Easiest: just make symlinks.
322dotlink-ok-p = \
323 $(call symlink-ok-p,$(HOME)/$1,$(call dotfile-source,$1))
324all:: $(addprefix $(HOME)/, $(DOTLINKS))
325$(addprefix $(HOME)/, $(subst %,\%,$(DOTLINKS))): $(HOME)/%: \
326 $$(if $$(call dotlink-ok-p,$$*),,_force)
327 $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
328 rm -f $@.new && \
329 ln -s $(call dotfile-source,$*) $@.new && \
330 mv $@.new $@
331 $(dotfile-hook/$*)
332
333## Hack with the C preprocessor.
334all:: $(addprefix $(HOME)/, $(DOTCPP))
335$(addprefix $(HOME)/, $(subst %,\%,$(DOTCPP))): $(HOME)/%: \
336 $$(call dotfile-source,$$*) Makefile
337 $(call v_tag,CPP)mkdir -p $(dir $@) && \
338 rm -f $@.new && \
339 cpp -P -o$@.new $($*_DEFS) $< && \
340 mv $@.new $@
341 $(dotfile-hook/$*)
342
343## Hack by making simple substitutions.
344substvar = -e $(call quote,s\a@$1@\a$2\ag)
345SUBSTS += $(call substvar,home,$(HOME))
346SUBSTS += $(call substvar,profile,$(HERE))
347all:: $(addprefix $(HOME)/, $(DOTSUBST))
348$(addprefix $(HOME)/, $(subst %,\%,$(DOTSUBST))): $(HOME)/%: \
349 $$(call dotfile-source,$$*,.in) Makefile
350 $(call v_tag,SUBST)mkdir -p $(dir $@) && \
351 rm -f $@.new && \
352 sed -e "1i\
353$(relax)### generated by $(HERE)/Makefile; do not edit!" \
354 $(SUBSTS) $($*_SUBSTS) \
355 $(call dotfile-source,$*,.in) >$@.new && \
356 mv $@.new $@
357 $(dotfile-hook/$*)
358
359###--------------------------------------------------------------------------
360### Processing script links.
361
362script-source = $(HERE)/bin/$(or $($1_SRC), $1)
363
364ifeq ($(prefix-shebang-p),t)
365all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
366$(addprefix $(HOME)/bin/, $(SCRIPTLINKS)): $(HOME)/bin/%: \
367 $$(call script-source,$$*) Makefile
368 $(call v_tag,SHEBANG)mkdir -p $(dir $@) && \
369 rm -f $@.new && \
370 sed "1s\a\(#! *\)/\a\1$(SHEBANG_PREFIX)/\a" \
371 $(call script-source,$*) >$@.new && \
372 chmod --reference=$(call script-source,$*) $@.new && \
373 mv $@.new $@
374 $(script-hook/$*)
375else
376scriptlink-ok-p = \
377 $(call symlink-ok-p,$(HOME)/bin/$1,$(call script-source,$1))
378all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
379$(addprefix $(HOME)/bin/, $(SCRIPTLINKS)): $(HOME)/bin/%: \
380 $$(if $$(call scriptlink-ok-p,$$*),,_force)
381 $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
382 rm -f $@.new && \
383 ln -s $(call script-source,$*) $@.new && \
384 mv $@.new $@
385 $(script-hook/$*)
386endif
387
388all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
389
390###--------------------------------------------------------------------------
391### Building packages from source tarballs.
392
393SRCDIR = $(HOME)/src/profile
394
395pkg-builddir = $(SRCDIR)/$1/build
396pkg-stamp = $(call pkg-builddir,$1)/$2-stamp
397
398$(foreach p, $(PACKAGES), $(eval DEP_$p = $(if $(shell \
399 if $($p_CHECK) >/dev/null 2>&1 --version; then echo t; fi),, \
400 $(call pkg-stamp,$p,install))))
401
402$(PACKAGES:%=$(SRCDIR)/%.tar.gz): $(SRCDIR)/%.tar.gz:
403 $(call v_tag,FETCH)mkdir -p $(SRCDIR) && \
404 rm -f $@.new && \
405 $(call get-url,$@.new,$(REPO)/$*.tar.gz) && \
406 mv $@.new $@
407
408$(foreach p, $(PACKAGES), $(call pkg-stamp,$p,unpack)): \
409 $(call pkg-stamp,%,unpack): $(SRCDIR)/%.tar.gz
410 $(call v_tag,EXTRACT)rm -rf $(SRCDIR)/$* && \
411 mkdir $(SRCDIR)/$*.tmp-unpack && \
412 cd $(SRCDIR)/$*.tmp-unpack && \
413 gzip -cd ../$*.tar.gz | tar xf - && \
414 mv * ../$* && \
415 cd .. && \
416 rmdir $*.tmp-unpack && \
417 mkdir $*/build && \
418 touch $*/build/unpack-stamp
419
420$(foreach p, $(PACKAGES), $(call pkg-stamp,$p,configure)): \
421 $(call pkg-stamp,%,configure): \
422 $(call pkg-stamp,%,unpack) \
423 $$(foreach p, $$($$*_DEPS), $$(DEP_$$p))
424 $(call v_tag,CONFIG)cd $(dir $@) && \
425 ../configure --prefix=$(HOME) \
426 PKG_CONFIG_PATH=$(HOME)/lib/pkgconfig \
427 $($*_CONFIG) >>buildlog 2>&1 && \
428 touch configure-stamp
429
430$(foreach p, $(PACKAGES), $(call pkg-stamp,$p,build)): \
431 $(call pkg-stamp,%,build): \
432 $(call pkg-stamp,%,configure)
433 $(call v_tag,BUILD)cd $(dir $@) && \
434 $(MAKE) $($*_MAKEFLAGS) >>buildlog 2>&1 && \
435 touch build-stamp
436
437$(foreach p, $(PACKAGES), $(call pkg-stamp,$p,install)): \
438 $(call pkg-stamp,%,install): \
439 $(call pkg-stamp,%,build)
440 $(call v_tag,INSTALL)cd $(dir $@) && \
441 $(MAKE) $($*_MAKEFLAGS) install >>buildlog 2>&1 && \
442 touch install-stamp
443 $(package-hook/$*)
444
445all:: $(foreach p, $(PACKAGES), $(DEP_$p))
446$(foreach p, $(PACKAGES), $(eval _pkg.$p: $(call pkg-stamp,$p,install)))
447
448###----- That's all, folks --------------------------------------------------