9 .SECONDEXPANSION
: #sorry
11 ###--------------------------------------------------------------------------
15 quote
= '$(subst ','\'',$1)'#'
17 ## Suss out how to print stuff.
18 print = printf
"%s" $(call quote
,$1)
20 ## Looking configuration things up.
21 mdw-conf
= $(shell bin
/mdw-conf
"$1" "$2")
23 ## Checking symlink targets.
24 symlink-ok-p
= $(shell \
25 case
$$(readlink
2>/dev
/null
$1) in
($2) echo t
;; esac
)
27 ## Silent rules machinery.
31 v_print
= $(call v_print_
$V,$1,$2)
33 printf
" %-8s %s\n" "$1" $(call quote
,$(patsubst $(HOME
)/%,~
/%,$2));
34 v_tag
= $(V_AT
)$(call v_print_
$V,$1,$@
)
36 ## Making directories.
37 %/:; $(call v_tag
,MKDIR
)mkdir
-p
$@
42 ###--------------------------------------------------------------------------
45 ## Figure out where I am.
48 ## Decide on how to fetch things from URLs.
49 ifeq ($(shell (curl
>/dev
/null
2>&1 --version ||
[ $$?
-eq
2 ]) && echo t
),t
)
50 get-url
= curl
-fs
-o
$1 $2
52 get-url
= wget
-q
-O
$1 $2
55 ## Which Emacs should I use?
58 for i in emacs24 emacs23 emacs22 emacs21 emacs
; do \
59 if type
>/dev
/null
2>&1 $$i; then emacs
=$$i; break
; fi
; \
63 ## Whence to obtain externally hosted stuff.
64 REPO
= https
://ftp.distorted.org.uk
/u
/mdw
/profile
66 ## Additional local configuration.
69 ###--------------------------------------------------------------------------
70 ### Some utility rules.
75 ###--------------------------------------------------------------------------
80 EMACSLIB
= $(HOME
)/lib
/emacs
82 EMACS_VERSION
:= $(shell $(EMACS
) 2>&1 -Q
--batch
--eval \
83 '(message "%s %s" emacs-major-version emacs-minor-version)' | \
85 emacs-version-p
= $(shell set
-- $(EMACS_VERSION
); \
86 if
[ $$1 -gt
$1 ] ||
([ $$1 -eq
$1 ] && [ $$2 -ge
$2 ]); then \
90 ELISP
+= make-regexp ew-hols
91 ELISP
+= mdw-gnus-patch
92 ELISP
+= mdw-multiple-cursors
93 ELISP
+= git git-blame vc-git stgit quilt
95 ifeq ($(call emacs-version-p
,24,3),t
)
96 ELISP
+= bracketed-paste
100 dot-emacs_DEPS
= make-regexp
102 SCRIPTLINKS
+= emacsclient-hack movemail-hack sendmail-hack
103 SCRIPTLINKS
+= aspell-hack emerge-hack wakey.sh
105 %.elc
: %.el
$$(foreach e
, $$($$*_DEPS
), $$(DEP_
$$e))
106 $(call v_tag
,EMACS
)if
! $(EMACS
) >$*.build-log
2>&1 \
107 -L el
/ -L
$(EMACSLIB
) \
108 --batch
--no-site-file \
109 --eval
'(kill-emacs (if (byte-compile-file "$<") 0 2))'; then \
110 cat
$*.build-log
; exit
2; \
113 LOCAL_ELISP
= $(filter $(notdir $(wildcard el
/*.el
)), \
114 $(addsuffix .el
, $(ELISP
)))
115 $(foreach e
, $(LOCAL_ELISP
), \
116 $(eval DEP_
$(basename $e) = $(EMACSLIB
)/$(e
:.el
=.elc
)))
117 $(addprefix $(EMACSLIB
)/, $(LOCAL_ELISP
)): $(EMACSLIB
)/%: el
/% |
$(EMACSLIB
)/
118 $(call v_tag
,SYMINK
) \
120 ln
-s
$(HERE
)/$< $@.new
&& \
123 REMOTE_ELISP
= $(filter-out $(notdir $(wildcard el
/*.el
)), \
124 $(addsuffix .el
, $(ELISP
)))
125 $(foreach e
, $(REMOTE_ELISP
), \
126 $(eval DEP_
$(basename $e) = $(if
$(shell \
127 if
$(EMACS
) >/dev
/null
2>&1 --no-site-file
-q
--batch \
130 (kill-emacs (condition-case nil \
131 (progn (load-library "$e") 0) \
132 (error 1))))'; then \
134 fi
),, $(EMACSLIB
)/$(e
:.el
=.elc
))))
135 $(addprefix $(EMACSLIB
)/, $(REMOTE_ELISP
)): $(EMACSLIB
)/%: |
$(EMACSLIB
)/
136 $(call v_tag
,FETCH
) \
137 $(call get-url
,$@.new
,$(REPO
)/$*) && \
140 DOTLINKS
+= .emacs .emacs-calc .vm .gnus.el .ercrc.el
142 all: $(foreach e
, $(ELISP
), $(DEP_
$e))
143 $(foreach e
, $(ELISP
), $(eval _emacs.
$e: $(EMACSLIB
)/$e.elc
))
147 ###--------------------------------------------------------------------------
148 ### Other simpler things.
151 $(call v_tag
,COPY
)cp mdw.conf
$@.new
&& mv
$@.new
$@
154 PACKAGES
+= mlib checkpath
155 mlib_CHECK
= crc-mktab
156 checkpath_CHECK
= tmpdir
157 checkpath_DEPS
= mlib
159 ## Packaging machinery.
160 SCRIPTLINKS
+= mdw-build mdw-sbuild mdw-sbuild-server
161 SCRIPTLINKS
+= update-buildable-branch
162 DOTLINKS
+= .config
/mdw-build.conf
163 .config
/mdw-build.conf_SRC
= mdw-build.conf
166 DOTLINKS
+= .profile .shell-rc .shell-logout
168 DOTLINKS
+= .zprofile .zshrc .zlogout .zshenv
169 DOTLINKS
+= .bash_profile .bash_completion .bash_logout
170 DOTLINKS
+= .bashrc .inputrc
171 .bash_profile_SRC
= bash-profile
172 .bash_completion_SRC
= bash-completion
173 .bash_logout_SRC
= shell-logout
174 .zlogout_SRC
= shell-logout
176 all: zap-stale-zcompdump
178 $(V_AT
)if
[ $(HOME
)/.zcompdump
-ot dot
/zshrc
]; then \
179 $(call v_print
,ZAP
,$(HOME
)/.zcompdump
)rm -f
$(HOME
)/.zcompdump
; \
181 .PHONY
: zap-stale-zcompdump
183 ## The Plan 9 `rc' shell. This needs special hacking, because the Linux port
184 ## and Plan 9 From User Space have incompatible syntax.
185 DOTLINKS
+= lib
/profile
186 lib
/profile_SRC
= rcrc
188 $(HOME
)/.rcrc
: dot
/rcrc
189 $(call v_tag
,SED
)sed
's/; if not/else/' $< >$@.new
&& mv
$@.new
$@
192 DOTSUBST
+= .gitconfig
193 SCRIPTLINKS
+= git-copyright-dates
194 DOTLINKS
+= .cgrc .tigrc
195 .gitconfig_SUBSTS
= \
196 $(call substvar
,releasekey
,$(call mdw-conf
,releasekey
,481334C2
)) \
197 $(call substvar
,email
,$(call mdw-conf
,email
,mdw@distorted.org.uk
))
198 $(HOME
)/.gitconfig
: $(HOME
)/.mdw.conf
201 DOTLINKS
+= .pulse
/daemon.conf
202 DOTSUBST
+= .pulse
/default.pa
203 .pulse
/daemon.conf_SRC
= pulse-daemon.conf
204 .pulse
/default.pa_SRC
= pulse-default.pa.in
207 DOTLINKS
+= .vimrc .mg .zile
210 DOTLINKS
+= .mailrc .signature .muttrc
213 DOTLINKS
+= .cmucl-init.lisp .sbclrc .clisprc.lisp
214 DOTLINKS
+= .eclrc .ccl-init.lisp .abclrc
215 .cmucl-init.lisp_SRC
= lisp-init.lisp
216 .sbclrc_SRC
= lisp-init.lisp
217 .clisprc.lisp_SRC
= lisp-init.lisp
218 .eclrc_SRC
= lisp-init.lisp
219 .ccl-init.lisp_SRC
= lisp-init.lisp
220 .abclrc_SRC
= lisp-init.lisp
221 DOTLINKS
+= .swank.lisp
223 ## IPython, Jupyter, and related annoyances.
224 DOTLINKS
+= .ipython
/profile_default
/ipython_config.py
225 DOTLINKS
+= .ipython
/profile_default
/startup
/50-key-bindings.py
226 DOTLINKS
+= .jupyter
/nbconfig
/notebook.json
227 .ipython
/profile_default
/ipython_config.py_SRC
= ipython-config.py
228 .ipython
/profile_default
/startup
/50-key-bindings.py_SRC
= ipython-key-bindings.py
229 .jupyter
/nbconfig
/notebook.json_SRC
= jupyter-notebook.json
233 DOTLINKS
+= .tclshrc .wishrc
234 .tclshrc_SRC
= tclshrc
235 .wishrc_SRC
= tclshrc
237 ## The `nocss' machinery.
239 all: $(HOME
)/lib
/hacks
/nocss
/libdvdcss.so
.2
240 $(HOME
)/lib
/hacks
/nocss
/libdvdcss.so
.2: |
$$(dir $$@
)
241 $(call v_tag
,TOUCH
)touch
$@
244 all: $(HOME
)/.gnupg
/gpg.conf
245 $(HOME
)/.gnupg
/gpg.conf
: \
246 dot
/gpg.conf.m4
$(wildcard $(HOME
)/.gnupg
/gpg.local.conf
) \
249 $(call v_tag
,M4
)cd
$(dir $@
) && \
251 key
=$$(mdw-conf default-gpg-key nil
) && \
254 *) args
=$${args
+$$args }-DDEFAULT_KEY
=$$key ;; \
256 cd
$(dir $@
) && m4
-P
$$args $(HERE
)/$< >$@.new
&& \
258 DOTLINKS
+= .gnupg
/gpg-agent.conf
259 .gnupg
/gpg-agent.conf_SRC
= gpg-agent.conf
262 SCRIPTLINKS
+= mdw-editor mdw-pager
263 SCRIPTLINKS
+= mdw-conf
264 SCRIPTLINKS
+= svnwrap
265 SCRIPTLINKS
+= guest-console
266 SCRIPTLINKS
+= hyperspec
268 SCRIPTLINKS
+= datasyms
269 SCRIPTLINKS
+= fixsub
270 SCRIPTLINKS
+= check-debsyms
271 SCRIPTLINKS
+= check-blkdev-size
272 SCRIPTLINKS
+= xremote
273 SCRIPTLINKS
+= disorder-play-on-demand remote-disorder
274 SCRIPTLINKS
+= remote-slideshow
276 ## Random odds and ends.
277 DOTLINKS
+= .infokey .sqliterc
278 DOTLINKS
+= .gdbinit .toprc .aspell.conf
279 DOTLINKS
+= .dircolors .colordiffrc .screenrc .tmux.conf
280 DOTLINKS
+= .cvsrc .indent.pro .ditz-config
282 .lftp
/rc_SRC
= lftp-rc
283 DOTLINKS
+= .a2ps
/a2psrc
284 .a2ps
/a2psrc_SRC
= a2psrc
285 DOTSUBST
+= .mykermrc
286 SCRIPTLINKS
+= lesspipe.sh
288 SCRIPTLINKS
+= run-with-shell-env
289 SCRIPTLINKS
+= start-ssh-agent start-ssh-pageant
290 SCRIPTLINKS
+= add-ssh-keys
291 SCRIPTLINKS
+= hacks
/ssh
/ssh
292 hacks
/ssh
/ssh_SRC
= hacks
/ssh
294 DOTLINKS
+= .w3m
/config .elinks
/elinks.conf
295 .w3m
/config_SRC
= w3m-config
296 .elinks
/elinks.conf_SRC
= elinks.conf
298 DOTLINKS
+= .mc
/ini .mc
/panels.ini
300 .mc
/panels.ini_SRC
= mc-panels.ini
302 DOTLINKS
+= .parallel
/config .parallel
/sshloginfile
303 .parallel
/config_SRC
= parallel-config
304 .parallel
/sshloginfile_SRC
= parallel-hosts
307 $(HOME
)/.less
: dot
/lesskey
308 $(V_AT
)rm -f
$(HOME
)/.lesskey
309 $(call v_tag
,LESSKEY
)lesskey
-o
$@
$<
311 ###--------------------------------------------------------------------------
312 ### X11 configuration.
320 DOTLINKS
+= .xinitrc .xsession .xmodmap .vncrc .vncsession
321 DOTLINKS
+= .config
/fontconfig
/fonts.conf
322 .config
/fontconfig
/fonts.conf_SRC
= fonts.conf
323 DOTLINKS
+= .stalonetrayrc
325 DOTLINKS
+= .config
/gnome-session
/sessions
/mdw.session
326 .config
/gnome-session
/sessions
/mdw.session_SRC
= mdw.session
328 DOTLINKS
+= .Eterm
/themes
/Eterm
/theme.cfg
329 DOTLINKS
+= .enlightenment
/keybindings.cfg
330 DOTLINKS
+= .enlightenment-vnc
/keybindings.cfg
331 DOTLINKS
+= .e16
/bindings.cfg
332 .Eterm
/themes
/Eterm
/theme.cfg_SRC
= eterm-theme.cfg
333 .enlightenment
/keybindings.cfg_SRC
= e-keybindings.cfg
334 .enlightenment-vnc
/keybindings.cfg_SRC
= evnc-keybindings.cfg
335 .e16
/bindings.cfg_SRC
= e16-bindings
337 DOTLINKS
+= .gtkrc-2.0
338 DOTLINKS
+= .config
/gtk-3.0
/gtk.css
339 DOTLINKS
+= .config
/gtk-3.0
/settings.ini
340 .config
/gtk-3.0
/gtk.css_SRC
= gtk3.css
341 .config
/gtk-3.0
/settings.ini_SRC
= gtk3-settings.ini
343 DOTLINKS
+= .config
/user-dirs.dirs .config
/user-dirs.locale
344 .config
/user-dirs.dirs_SRC
= user-dirs.dirs
345 .config
/user-dirs.locale_SRC
= user-dirs.locale
347 SCRIPTLINKS
+= xinitcmd lock-screen xshutdown
348 SCRIPTLINKS
+= un-backslashify-selection
349 SCRIPTLINKS
+= xpra-start-xdummy
350 SCRIPTLINKS
+= play-rawk
351 SCRIPTLINKS
+= x2x-privsep
352 SCRIPTLINKS
+= xduplic-terminal
353 SCRIPTLINKS
+= xzoomscr
356 Xdefaults_DEFS
= -DEMACSWD
=$(call mdw-conf
,emacs-width
,77)
357 $(HOME
)/.Xdefaults
: $(HOME
)/.mdw.conf dot
/Xdefaults.pterm
359 ifeq ($(shell case
$${DISPLAY-nil
} in
(:[0-9]*) echo t
;; (*) echo nil
;; esac
),t
)
360 dotfile-hook
/.Xdefaults
= \
361 $(call v_tag
,XRDB
)xrdb
-load
$<
366 ###--------------------------------------------------------------------------
373 all: out
/firefox
/smartup-gestures.config
374 out
/firefox
/smartup-gestures.config
: firefox
/smartup-gestures.json | out
/firefox
/
376 jq
-c .
$< | bincode base64
>$@.new
&& mv
$@.new
$@
378 all: out
/firefox
/stylus.json
379 out
/firefox
/stylus.json
: firefox
/stylus
/ firefox
/stylus
/*.css | out
/firefox
/
380 $(call v_tag
,IMPLODE
)\
381 firefox
/implode-stylus firefox
/stylus
/ >$@.new
&& \
385 ###--------------------------------------------------------------------------
386 ### General symlinking.
388 misclink-source
= $(HERE
)/$(or
$($1_SRC), $1)
390 all: $(addprefix $(HOME
)/, $(MISCLINKS
))
392 $(call symlink-ok-p
,$(HOME
)/$1,$(call misclink-source
,$1))
393 $(addprefix $(HOME
)/, $(subst %,\
%,$(MISCLINKS
))): $(HOME
)/%: \
394 $$(if
$$(call misclink-ok-p
,$$*),,_force
) |
$$(dir $$@
)
395 $(call v_tag
,SYMLINK
) \
397 ln
-s
$(call misclink-source
,$*) $@.new
&& \
401 ###--------------------------------------------------------------------------
402 ### Processing dotfiles.
404 dotfile-source
= $(HERE
)/dot
/$(or
$($1_SRC), $(1:.
%=%)$2)
406 ## Easiest: just make symlinks.
408 $(call symlink-ok-p
,$(HOME
)/$1,$(call dotfile-source
,$1))
409 all: $(addprefix $(HOME
)/, $(DOTLINKS
))
410 $(addprefix $(HOME
)/, $(subst %,\
%,$(DOTLINKS
))): $(HOME
)/%: \
411 $$(if
$$(call dotlink-ok-p
,$$*),,_force
) |
$$(dir $$@
)
412 $(call v_tag
,SYMLINK
) \
414 ln
-s
$(call dotfile-source
,$*) $@.new
&& \
418 ## Hack with the C preprocessor.
419 all: $(addprefix $(HOME
)/, $(DOTCPP
))
420 $(addprefix $(HOME
)/, $(subst %,\
%,$(DOTCPP
))): $(HOME
)/%: \
421 $$(call dotfile-source
,$$*) Makefile |
$$(dir $$@
)
424 cpp -P
-o
$@.new
$($*_DEFS
) $< && \
428 ## Hack by making simple substitutions.
429 substvar
= -e
$(call quote
,s
\a@
$1@
\a$2\ag
)
430 SUBSTS
+= $(call substvar
,home
,$(HOME
))
431 SUBSTS
+= $(call substvar
,profile
,$(HERE
))
432 all: $(addprefix $(HOME
)/, $(DOTSUBST
))
433 $(addprefix $(HOME
)/, $(subst %,\
%,$(DOTSUBST
))): $(HOME
)/%: \
434 $$(call dotfile-source
,$$*,.in
) Makefile |
$$(dir $$@
)
435 $(call v_tag
,SUBST
) \
438 $(relax)### generated by $(HERE)/Makefile; do not edit!" \
439 $(SUBSTS
) $($*_SUBSTS
) \
440 $(call dotfile-source
,$*,.in
) >$@.new
&& \
444 ###--------------------------------------------------------------------------
445 ### Processing script links.
447 script-source
= $(HERE
)/bin
/$(or
$($1_SRC), $1)
449 ifeq ($(prefix-shebang-p
),t
)
450 all: $(addprefix $(HOME
)/bin
/, $(SCRIPTLINKS
))
451 $(addprefix $(HOME
)/bin
/, $(SCRIPTLINKS
)): $(HOME
)/bin
/%: \
452 $$(call script-source
,$$*) Makefile |
$$(dir $$@
)
453 $(call v_tag
,SHEBANG
) \
455 sed
"1s\a\(#! *\)/\a\1$(SHEBANG_PREFIX)/\a" \
456 $(call script-source
,$*) >$@.new
&& \
457 chmod
--reference
=$(call script-source
,$*) $@.new
&& \
462 $(call symlink-ok-p
,$(HOME
)/bin
/$1,$(call script-source
,$1))
463 all: $(addprefix $(HOME
)/bin
/, $(SCRIPTLINKS
))
464 $(addprefix $(HOME
)/bin
/, $(SCRIPTLINKS
)): $(HOME
)/bin
/%: \
465 $$(if
$$(call scriptlink-ok-p
,$$*),,_force
) |
$$(dir $$@
)
466 $(call v_tag
,SYMLINK
) \
468 ln
-s
$(call script-source
,$*) $@.new
&& \
473 all: $(addprefix $(HOME
)/bin
/, $(SCRIPTLINKS
))
475 ###--------------------------------------------------------------------------
476 ### Building packages from source tarballs.
478 SRCDIR
= $(HOME
)/src
/profile
480 pkg-builddir
= $(SRCDIR
)/$1/build
481 pkg-stamp
= $(call pkg-builddir
,$1)/$2-stamp
483 $(foreach p
, $(PACKAGES
), $(eval DEP_
$p = $(if
$(shell \
484 if
$($p_CHECK) >/dev
/null
2>&1 --version
; then echo t
; fi
),, \
485 $(call pkg-stamp
,$p,install))))
487 $(PACKAGES
:%=$(SRCDIR
)/%.
tar.gz
): $(SRCDIR
)/%.
tar.gz
: |
$(SRCDIR
)/
488 $(call v_tag
,FETCH
) \
490 $(call get-url
,$@.new
,$(REPO
)/$*.
tar.gz
) && \
493 $(foreach p
, $(PACKAGES
), $(call pkg-stamp
,$p,unpack
)): \
494 $(call pkg-stamp
,%,unpack
): $(SRCDIR
)/%.
tar.gz
495 $(call v_tag
,EXTRACT
)rm -rf
$(SRCDIR
)/$* && \
496 mkdir
$(SRCDIR
)/$*.tmp-unpack
&& \
497 cd
$(SRCDIR
)/$*.tmp-unpack
&& \
498 gzip
-cd ..
/$*.
tar.gz |
tar xf
- && \
501 rmdir
$*.tmp-unpack
&& \
503 touch
$*/build
/unpack-stamp
505 $(foreach p
, $(PACKAGES
), $(call pkg-stamp
,$p,configure
)): \
506 $(call pkg-stamp
,%,configure
): \
507 $(call pkg-stamp
,%,unpack
) \
508 $$(foreach p
, $$($$*_DEPS
), $$(DEP_
$$p))
509 $(call v_tag
,CONFIG
)cd
$(dir $@
) && \
510 ..
/configure
--prefix=$(HOME
) \
511 PKG_CONFIG_PATH
=$(HOME
)/lib
/pkgconfig \
512 $($*_CONFIG
) >>buildlog
2>&1 && \
513 touch configure-stamp
515 $(foreach p
, $(PACKAGES
), $(call pkg-stamp
,$p,build
)): \
516 $(call pkg-stamp
,%,build
): \
517 $(call pkg-stamp
,%,configure
)
518 $(call v_tag
,BUILD
)cd
$(dir $@
) && \
519 $(MAKE
) $($*_MAKEFLAGS
) >>buildlog
2>&1 && \
522 $(foreach p
, $(PACKAGES
), $(call pkg-stamp
,$p,install)): \
523 $(call pkg-stamp
,%,install): \
524 $(call pkg-stamp
,%,build
)
525 $(call v_tag
,INSTALL
)cd
$(dir $@
) && \
526 $(MAKE
) $($*_MAKEFLAGS
) install >>buildlog
2>&1 && \
530 all: $(foreach p
, $(PACKAGES
), $(DEP_
$p))
531 $(foreach p
, $(PACKAGES
), $(eval _pkg.
$p: $(call pkg-stamp
,$p,install)))
533 ###----- That's all, folks --------------------------------------------------