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