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