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