chiark / gitweb /
3758d4a333bcf3ff1a4dd1cf9d36e84f364ad050
[zones] / Makefile.m4
1 ### Makefile for mdw's zones
2 ###
3 ### Preprocessed with m4, for the sake of madness
4
5 m4_divert(-1)
6 ###--------------------------------------------------------------------------
7 ### M4 trickery.
8
9 m4_changequote([, ])
10 m4_define([_dolist], [m4_pushdef([$1])__loop($@)m4_popdef([$1])])
11 m4_define([__loop], [m4_ifelse([$2], [()], ,m4_dnl
12 [m4_define([$1], __first$2)$3[]__loop([$1],(m4_shift$2),[$3])])])
13 m4_define([__first], [$1])
14
15 m4_define([DOMAIN], [m4_dnl
16 m4_pushdef([_undivert], [m4_divert(]m4_divnum[)m4_popdef([_undivert])])m4_dnl
17 m4_divert(10)m4_dnl
18 $1_SUBNETS = _dolist([_subnet], [($2)], [ _subnet])
19 $1_ZONES = _dolist([_zone], [($3)], [ _zone])
20 $1_ZONE_FILES = _dolist([_subnet], [($2)],
21         [_dolist([_zone], [($3)], [ _subnet/_zone.zone])])
22 ALL_SUBNETS += $($1_SUBNETS)
23 ALL_ZONES += $($1_ZONES)
24 ALL_ZONE_FILES += $($1_ZONE_FILES)
25 m4_divert(30)m4_dnl
26 $($1_ZONE_FILES): $1.lisp $(ZONEDEPS)
27         mkdir -p $($1_SUBNETS)m4_dnl
28 _dolist([_subnet], [($2)], [
29         $(ZONE) -d _subnet/ -f subnet/_subnet -s _subnet $1.lisp])
30 _undivert[]m4_dnl
31 ])
32
33 m4_divert(-1)
34 ###--------------------------------------------------------------------------
35 ### Domains.
36
37 DOMAIN([distorted], [inet, fretwank],
38         [distorted.org.uk, dhcp.distorted.org.uk,
39          198.29.172.in-addr.arpa, wireless.198.29.172.in-addr.arpa,
40          199.29.172.in-addr.arpa, dhcp.199.29.172.in-addr.arpa])
41 DOMAIN([harlequin], [inet], [harlequin.org.uk])
42
43 m4_divert(0)
44 ###--------------------------------------------------------------------------
45 ### Make configuration.
46
47 ZONE = zone
48
49 ALL_ZONES =
50 ALL_ZONE_FILES =
51 ALL_SUBNETS =
52
53 PUBLISH = publish
54
55 ZONEDEPS = hosts.lisp
56
57 DOCS = distorted.tex
58 DOC_OUTPUTS = $(foreach suffix,dvi ps,\
59                 $(patsubst %.tex,%.$(suffix),$(DOCS)))
60
61 m4_divert(20)
62 ###--------------------------------------------------------------------------
63 ### Rules
64
65 all: $(ALL_ZONE_FILES) $(DOC_OUTPUTS)
66
67 install: all
68         ##
69         ## Make directories
70         rm -rf $(PUBLISH).new
71         mkdir $(PUBLISH).new
72         cd $(PUBLISH).new && mkdir $(sort $(ALL_SUBNETS))
73         ##
74         ## Copy zone files to output
75         for i in $(ALL_ZONE_FILES); do \
76           cp $$i $(PUBLISH).new/$$i; \
77         done
78         ##
79         ## Make links as necessary
80         cd $(PUBLISH).new; \
81         for i in $(sort $(ALL_SUBNETS)); do \
82           test $$i = inet && continue; \
83           for z in $(sort $(ALL_ZONES)); do \
84             test -f $$i/$$z.zone || ln -s ../inet/$$z.zone $$i/$$z.zone; \
85           done; \
86         done
87         ##
88         ## Switch over
89         rm -rf $(PUBLISH).old
90         mv $(PUBLISH) $(PUBLISH).old
91         mv $(PUBLISH).new $(PUBLISH)
92         ##
93         ## Get nameserver to reload changed zones
94         for i in $(sort $(ALL_SUBNETS)); do \
95           for z in $(sort $(ALL_ZONES)); do \
96             cmp $(PUBLISH)/$$i/$$z.zone $(PUBLISH).old/$$i/$$z.zone \
97                 >/dev/null 2>&1 && continue; \
98             echo -n "$$z ($$i): "; \
99             userv root named-reload $$z $$i; \
100           done; \
101         done
102         ##
103         ## Clear up mess
104         rm -rf $(PUBLISH).old
105
106 %.dvi: %.tex
107         latex $<
108         latex $<
109
110 %.ps: %.dvi
111         dvips -o $@ $<
112
113 m4_divert(40)
114 Makefile: Makefile.m4
115         m4 -P $< >$@.new
116         mv $@.new $@
117
118 clean:
119         rm -f $(ALL_ZONE_FILES) *.toc *.lof *.lot *.log *.dvi *.ps *.aux
120         rmdir $(sort $(ALL_SUBNETS))
121
122 ###----- That's all, folks --------------------------------------------------