chiark / gitweb /
dot/inputrc: Make C-u delete the whole line.
[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_tag                    = $(call v_tag_$V,$1,$2)
25 v_tag_0                  = @printf "  %-8s %s\n" "$1" $(call quote,$@);
26 V_AT                     = $(V_AT_$V)
27 V_AT_0                   = @
28
29 ## Hack.
30 relax                    =
31
32 ###--------------------------------------------------------------------------
33 ### Configuration.
34
35 ## Figure out where I am.
36 HERE                     = $(shell pwd)
37
38 ## Decide on how to fetch things from URLs.
39 ifeq ($(shell (curl >/dev/null 2>&1 --version || [ $$? -eq 2 ]) && echo t),t)
40   get-url                = curl -fs -o $1 $2
41 else
42   get-url                = wget -q -O $1 $2
43 endif
44
45 ## Which Emacs should I use?
46 EMACS                   := $(shell \
47         emacs=nil; \
48         for i in emacs24 emacs23 emacs22 emacs21 emacs; do \
49           if type >/dev/null 2>&1 $$i; then echo $$i; break; fi; \
50         done)
51
52 ## Whence to obtain externally hosted stuff.
53 REPO                     = https://ftp.distorted.org.uk/u/mdw/profile
54
55 ## Additional local configuration.
56 -include local.mk
57
58 ###--------------------------------------------------------------------------
59 ### Some utility rules.
60
61 _force:
62 .PHONY: _force
63
64 ###--------------------------------------------------------------------------
65 ### Emacs.
66
67 EMACSLIB                 = $(HOME)/lib/emacs
68
69 ELISP                   += make-regexp ew-hols
70 ELISP                   += mdw-gnus-patch
71 ELISP                   += mdw-multiple-cursors
72 ELISP                   += git git-blame vc-git stgit quilt
73 ELISP                   += bracketed-paste
74
75 ELISP                   += dot-emacs
76 dot-emacs_DEPS           = make-regexp
77
78 SCRIPTLINKS             += emacsclient-hack movemail-hack sendmail-hack
79 SCRIPTLINKS             += aspell-hack emerge-hack
80
81 %.elc: %.el $$(foreach e, $$($$*_DEPS), $$(DEP_$$e))
82         $(call v_tag,EMACS)if ! $(EMACS) >$*.build-log 2>&1 \
83                 -L el/ -L $(EMACSLIB) \
84                 --batch --no-site-file \
85                 --eval '(byte-compile-file "$<")'; then \
86           cat $*.build-log; exit 2; \
87         fi
88
89 LOCAL_ELISP              = $(filter $(notdir $(wildcard el/*.el)), \
90                                 $(addsuffix .el, $(ELISP)))
91 $(foreach e, $(LOCAL_ELISP), \
92         $(eval DEP_$(basename $e) = $(EMACSLIB)/$(e:.el=.elc)))
93 $(addprefix $(EMACSLIB)/, $(LOCAL_ELISP)): $(EMACSLIB)/%: el/%
94         $(call v_tag,SYMINK)mkdir -p $(EMACSLIB) && \
95                 rm -f $@.new && \
96                 ln -s $(HERE)/$< $@.new && \
97                 mv $@.new $@
98
99 REMOTE_ELISP             = $(filter-out $(notdir $(wildcard el/*.el)), \
100                                 $(addsuffix .el, $(ELISP)))
101 $(foreach e, $(REMOTE_ELISP), \
102         $(eval DEP_$(basename $e) = $(if $(shell \
103                 if $(EMACS) >/dev/null 2>&1 --no-site-file -q --batch \
104                         --eval ' \
105                           (progn \
106                             (kill-emacs (condition-case nil \
107                                             (progn (load-library "$e") 0) \
108                                           (error 1))))'; then \
109                   echo t; \
110                 fi),, $(EMACSLIB)/$(e:.el=.elc))))
111 $(addprefix $(EMACSLIB)/, $(REMOTE_ELISP)): $(EMACSLIB)/%:
112         $(call v_tag,FETCH)mkdir -p $(EMACSLIB) && \
113                 $(call get-url,$@.new,$(REPO)/$*) && \
114                 mv $@.new $@
115
116 DOTLINKS                += .emacs .emacs-calc .vm .gnus.el .ercrc.el
117
118 all:: $(foreach e, $(ELISP), $(DEP_$e))
119 $(foreach e, $(ELISP), $(eval _emacs.$e: $(EMACSLIB)/$e.elc))
120
121 ###--------------------------------------------------------------------------
122 ### Other simpler things.
123
124 $(HOME)/.mdw.conf:
125         $(call v_tag,COPY)cp mdw.conf $@.new && mv $@.new $@
126
127 ## Utility packages.
128 PACKAGES                += mlib checkpath
129 mlib_CHECK               = crc-mktab
130 checkpath_CHECK          = tmpdir
131 checkpath_DEPS           = mlib
132
133 ## Packaging machinery.
134 SCRIPTLINKS             += mdw-build mdw-sbuild mdw-sbuild-server
135 SCRIPTLINKS             += update-buildable-branch
136
137 ## Shells.
138 DOTLINKS                += .profile .shell-rc .shell-logout
139 DOTLINKS                += .shrc .rcrc
140 DOTLINKS                += .zprofile .zshrc .zshenv
141 DOTLINKS                += .bash_profile .bash_completion .bashrc .inputrc
142 .bash_profile_SRC        = bash-profile
143 .bash_completion_SRC     = bash-completion
144
145 ## Git.
146 DOTSUBST                += .gitconfig
147 DOTLINKS                += .cgrc .tigrc
148 .gitconfig_SUBSTS        = \
149         $(call substvar,releasekey,$(call mdw-conf,release-key,481334C2))
150 $(HOME)/.gitconfig: $(HOME)/.mdw.conf
151
152 ## PulseAudio.
153 DOTLINKS                += .pulse/daemon.conf
154 DOTSUBST                += .pulse/default.pa
155 .pulse/daemon.conf_SRC   = pulse-daemon.conf
156 .pulse/default.pa_SRC    = pulse-default.pa.in
157
158 ## Other editors.
159 DOTLINKS                += .vimrc .mg .zile
160
161 ## Mail.
162 DOTLINKS                += .mailrc .signature .muttrc
163
164 ## Lisp.
165 DOTLINKS                += .cmucl-init.lisp .sbclrc .clisprc.lisp .eclrc
166 .cmucl-init.lisp_SRC     = lisp-init.lisp
167 .sbclrc_SRC              = lisp-init.lisp
168 .clisprc.lisp_SRC        = lisp-init.lisp
169 .eclrc_SRC               = lisp-init.lisp
170 DOTLINKS                += .swank.lisp
171
172 ## IPython.
173 DOTLINKS                += .ipython/profile_default/ipython_config.py
174 DOTLINKS                += .ipython/profile_default/startup/50-key-bindings.py
175 .ipython/profile_default/ipython_config.py_SRC = ipython-config.py
176 .ipython/profile_default/startup/50-key-bindings.py_SRC = ipython-key-bindings.py
177
178 ## Other languages.
179 DOTLINKS                += .guile
180 DOTLINKS                += .tclshrc .wishrc
181 .tclshrc_SRC             = tclshrc
182 .wishrc_SRC              = tclshrc
183
184 ## Random scripts.
185 SCRIPTLINKS             += mdw-editor mdw-pager
186 SCRIPTLINKS             += mdw-conf
187 SCRIPTLINKS             += svnwrap
188 SCRIPTLINKS             += guest-console
189 SCRIPTLINKS             += hyperspec
190
191 ## Random odds and ends.
192 DOTLINKS                += .lesskey .infokey .sqliterc
193 DOTLINKS                += .gdbinit .toprc .aspell.conf
194 DOTLINKS                += .dircolors .colordiffrc .screenrc .tmux.conf
195 DOTLINKS                += .cvsrc .indent.pro .ditz-config
196 DOTSUBST                += .mykermrc
197 SCRIPTLINKS             += lesspipe.sh
198
199 SCRIPTLINKS             += run-with-shell-env
200 SCRIPTLINKS             += start-ssh-agent start-ssh-pageant
201 SCRIPTLINKS             += add-ssh-keys
202 SCRIPTLINKS             += hacks/ssh/ssh
203 hacks/ssh/ssh_SRC        = hacks/ssh
204
205 DOTLINKS                += .w3m/config .elinks/elinks.conf
206 .w3m/config_SRC          = w3m-config
207 .elinks/elinks.conf_SRC  = elinks.conf
208
209 DOTLINKS                += .mc/ini .mc/panels.ini
210 .mc/ini_SRC              = mc-ini
211 .mc/panels.ini_SRC       = mc-panels.ini
212
213 DOTLINKS                += .parallel/config
214 .parallel/config_SRC     = parallel-config
215
216 ###--------------------------------------------------------------------------
217 ### X11 configuration.
218
219 ifeq ($X,t)
220
221 PACKAGES                += xtoys
222 xtoys_CHECK              = xatom
223 xtoys_DEPS               = mlib
224
225 DOTLINKS                += .xinitrc .xsession .xmodmap .vncrc .vncsession
226 DOTLINKS                += .fonts.conf
227 DOTLINKS                += .stalonetrayrc
228
229 DOTLINKS                += .putty/sessions/Default%20Settings
230 .putty/sessions/Default%20Settings_SRC = putty-defaults
231
232 DOTLINKS                += .config/gnome-session/sessions/mdw.session
233 .config/gnome-session/sessions/mdw.session_SRC = mdw.session
234
235 DOTLINKS                += .Eterm/themes/Eterm/theme.cfg
236 DOTLINKS                += .enlightenment/keybindings.cfg
237 DOTLINKS                += .enlightenment-vnc/keybindings.cfg
238 DOTLINKS                += .e16/bindings.cfg
239 .Eterm/themes/Eterm/theme.cfg_SRC = eterm-theme.cfg
240 .enlightenment/keybindings.cfg_SRC = e-keybindings.cfg
241 .enlightenment-vnc/keybindings.cfg_SRC = evnc-keybindings.cfg
242 .e16/bindings.cfg_SRC    = e16-bindings
243
244 DOTLINKS                += .gtkrc-2.0
245 DOTLINKS                += .config/gtk-3.0/gtk.css
246 DOTLINKS                += .config/gtk-3.0/settings.ini
247 .config/gtk-3.0/gtk.css_SRC = gtk3.css
248 .config/gtk-3.0/settings.ini_SRC = gtk3-settings.ini
249
250 SCRIPTLINKS             += xinitcmd lock-screen xshutdown
251 SCRIPTLINKS             += un-backslashify-selection
252 SCRIPTLINKS             += xpra-start-xdummy
253
254 DOTCPP                  += .Xdefaults
255 Xdefaults_DEFS           = -DEMACSWD=$(call mdw-conf,emacs-width,77)
256 $(HOME)/.Xdefaults: $(HOME)/.mdw.conf
257
258 endif
259
260 ###--------------------------------------------------------------------------
261 ### Processing dotfiles.
262
263 dotfile-source           = $(HERE)/dot/$(or $($1_SRC), $(1:.%=%)$2)
264
265 ## Easiest: just make symlinks.
266 dotlink-ok-p             = \
267         $(call symlink-ok-p,$(HOME)/$1,$(call dotfile-source,$1))
268 all:: $(addprefix $(HOME)/, $(DOTLINKS))
269 $(addprefix $(HOME)/, $(subst %,\%,$(DOTLINKS))): $(HOME)/%: \
270                 $$(if $$(call dotlink-ok-p,$$*),,_force)
271         $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
272                 rm -f $@.new && \
273                 ln -s $(call dotfile-source,$*) $@.new && \
274                 mv $@.new $@
275
276 ## Hack with the C preprocessor.
277 all:: $(addprefix $(HOME)/, $(DOTCPP))
278 $(addprefix $(HOME)/, $(subst %,\%,$(DOTCPP))): $(HOME)/%: \
279                 $$(call dotfile-source,$$*) Makefile
280         $(call v_tag,CPP)mkdir -p $(dir $@) && \
281                 rm -f $@.new && \
282                 cpp -P -o$@.new $($*_DEFS) $< && \
283                 mv $@.new $@
284
285 ## Hack by making simple substitutions.
286 substvar                 = -e $(call quote,s\a@$1@\a$2\ag)
287 SUBSTS                  += $(call substvar,home,$(HOME))
288 SUBSTS                  += $(call substvar,profile,$(HERE))
289 all:: $(addprefix $(HOME)/, $(DOTSUBST))
290 $(addprefix $(HOME)/, $(subst %,\%,$(DOTSUBST))): $(HOME)/%: \
291                 $$(call dotsubst-source,$$*,.in) Makefile
292         $(call v_tag,SUBST)mkdir -p $(dir $@) && \
293                 rm -f $@.new && \
294                 sed -e "1i\
295 $(relax)### generated by $(HERE)/Makefile; do not edit!" \
296                         $(SUBSTS) $($*_SUBSTS) \
297                         $(call dotfile-source,$*,.in) >$@.new && \
298                 mv $@.new $@
299
300 ###--------------------------------------------------------------------------
301 ### Processing script links.
302
303 script-source            = $(HERE)/bin/$(or $($1_SRC), $1)
304 scriptlink-ok-p          = \
305         $(call symlink-ok-p,$(HOME)/bin/$1,$(call script-source,$1))
306 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
307 $(addprefix $(HOME)/bin/, $(SCRIPTLINKS)): $(HOME)/bin/%: \
308                 $$(if $$(call scriptlink-ok-p,$$*),,_force)
309         $(call v_tag,SYMLINK)mkdir -p $(dir $@) && \
310                 rm -f $@.new && \
311                 ln -s $(call script-source,$*) $@.new && \
312                 mv $@.new $@
313
314 all:: $(addprefix $(HOME)/bin/, $(SCRIPTLINKS))
315
316 ###--------------------------------------------------------------------------
317 ### Building packages from source tarballs.
318
319 SRCDIR                   = $(HOME)/src/profile
320
321 pkg-builddir             = $(SRCDIR)/$1/build
322 pkg-stamp                = $(call pkg-builddir,$1)/$2-stamp
323
324 $(foreach p, $(PACKAGES), $(eval DEP_$p = $(if $(shell \
325         if $($p_CHECK) >/dev/null 2>&1 --version; then echo t; fi),, \
326         $(call pkg-stamp,$p,install))))
327
328 $(PACKAGES:%=$(SRCDIR)/%.tar.gz): $(SRCDIR)/%.tar.gz:
329         $(call v_tag,FETCH)mkdir -p $(SRCDIR) && \
330                 rm -f $@.new && \
331                 $(call get-url,$@.new,$(REPO)/$*.tar.gz) && \
332                 mv $@.new $@
333
334 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,unpack)): \
335                 $(call pkg-stamp,%,unpack): $(SRCDIR)/%.tar.gz
336         $(call v_tag,EXTRACT)rm -rf $(SRCDIR)/$* && \
337                 mkdir $(SRCDIR)/$*.tmp-unpack && \
338                 cd $(SRCDIR)/$*.tmp-unpack && \
339                 gzip -cd ../$*.tar.gz | tar xf - && \
340                 mv * ../$* && \
341                 cd .. && \
342                 rmdir $*.tmp-unpack && \
343                 mkdir $*/build && \
344                 touch $*/build/unpack-stamp
345
346 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,configure)): \
347                 $(call pkg-stamp,%,configure): \
348                 $(call pkg-stamp,%,unpack) \
349                 $$(foreach p, $$($$*_DEPS), $$(DEP_$$p))
350         $(call v_tag,CONFIG)cd $(dir $@) && \
351                 ../configure --prefix=$(HOME) \
352                         PKG_CONFIG_PATH=$(HOME)/lib/pkgconfig \
353                         $($*_CONFIG) >>buildlog 2>&1 && \
354                 touch configure-stamp
355
356 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,build)): \
357                 $(call pkg-stamp,%,build): \
358                 $(call pkg-stamp,%,configure)
359         $(call v_tag,BUILD)cd $(dir $@) && \
360                 $(MAKE) $($*_MAKEFLAGS) >>buildlog 2>&1 && \
361                 touch build-stamp
362
363 $(foreach p, $(PACKAGES), $(call pkg-stamp,$p,install)): \
364                 $(call pkg-stamp,%,install): \
365                 $(call pkg-stamp,%,build)
366         $(call v_tag,INSTALL)cd $(dir $@) && \
367                 $(MAKE) $($*_MAKEFLAGS) install >>buildlog 2>&1 && \
368                 touch install-stamp
369
370 all:: $(foreach p, $(PACKAGES), $(DEP_$p))
371 $(foreach p, $(PACKAGES), $(eval _pkg.$p: $(call pkg-stamp,$p,install)))
372
373 ###----- That's all, folks --------------------------------------------------