chiark / gitweb /
No longer serving harlequin.org.uk or felixpearce.com.
[zones] / Makefile
CommitLineData
5c420db9
MW
1### -*-makefile-*-
2###
3### Makefile for the DNS zones I maintain.
4###
5### (c) 2011 Mark Wooding
6
7###--------------------------------------------------------------------------
8### Silent-rules machinery.
9
10V = 0
11v_tag = $(call v_tag_$V,$1)
12v_tag_0 = @printf " %-6s %s\n" "$1" "$@";
13
14V_AT = $(V_AT_$V)
15V_AT_0 = @
16
17###--------------------------------------------------------------------------
18### Programs and options.
19
d7af5ae7 20## Zone checking.
5c420db9
MW
21CHECKZONE = named-checkzone -i full \
22 -k fail -M fail -n fail -S fail -W fail
23
d7af5ae7
MW
24## Zone installation.
25MASTER = localhost
38c2de7c
MW
26inside_MASTER = precision
27
d7af5ae7
MW
28ifeq ($(MASTER),localhost)
29ZONEINST = userv zoneconf install
30else
31ZONEINST = ssh zoneconf@$(MASTER)
32endif
33
5c420db9
MW
34###--------------------------------------------------------------------------
35### Utility functions.
36
37dir-nosl = $(patsubst %/,%,$(dir $1))
38
39###--------------------------------------------------------------------------
40### Keeping all of the files straight.
41
42## Establish a default target. We'll sort out what it does later.
43all:
44.PHONY: all
45
46## Things to clean.
47CLEANFILES =
48CLEANDIRS =
49REALCLEANFILES = $(CLEANFILES)
50REALCLEANDIRS = $(CLEANDIRS)
51
52## We work in terms of `zonesets'. Each one corresponds to a Lisp source
53## file to be passed to `zone'. A zoneset has a number of different nets
54## associated with it, in the variable zoneset_NETS, and we must run it
55## through `zone' once for each net. The zoneset will make a number of
56## zones, listed in zoneset_ZONES.
57ZONESETS =
58
59###--------------------------------------------------------------------------
60### The distorted.org.uk zones.
61
62ZONESETS += distorted
63
4a487d58 64distorted_VIEWS = inside outside
38c2de7c 65distorted_outside_NETS = dmz jump
2d396faa 66distorted_inside_NETS = any unsafe colo vpn
5c420db9 67
b420e5ee 68distorted_all_ZONES += distorted.org.uk
74180153 69distorted_all_ZONES += 199.29.172.in-addr.arpa
5c420db9
MW
70
71###--------------------------------------------------------------------------
61097cd6 72### Other zones.
5c420db9 73
8dcb3700
MW
74## binswood.org.uk
75ZONESETS += binswood
76binswood_VIEWS = outside
77binswood_all_ZONES += binswood.org.uk
78binswood_all_ZONES += 27.165.10.in-addr.arpa
79
0885bc47
MW
80## odin.gg
81ZONESETS += odin
82odin_VIEWS = outside
83odin_all_ZONES = odin.gg
84
5c420db9
MW
85###--------------------------------------------------------------------------
86### Zone construction machinery.
87
88ZONE = zone
89V_ZONE = $(call v_tag,ZONE)$(ZONE)
90
91.SECONDEXPANSION: #sorry
92
93## For each net/zoneset pair, we make a stamp file net/zoneset.stamp to
94## remember that we've made the corresponding zones.
95ALL_ZONESTAMPS = $(foreach s,$(ZONESETS), \
96 $(patsubst %,%/$s.zonestamp,$($s_VIEWS)))
97$(ALL_ZONESTAMPS) : %.zonestamp : $$(notdir $$*).lisp hosts.lisp
98 $(V_AT)mkdir -p $(dir $*)
99 $(V_ZONE) -d$(dir $*) -fview/$(call dir-nosl,$*)$(hack \
d7af5ae7
MW
100 hack) $(addprefix -s, \
101 $($(notdir $*)_$(call dir-nosl,$*)_NETS)) $<
5c420db9
MW
102 $(V_AT)touch $@
103all: $(ALL_ZONESTAMPS)
104CLEANFILES += $(sort $(foreach s,$(ZONESETS), \
105 $(foreach v,$($s_VIEWS), \
106 $v/*.zonestamp $v/*.zone)))
107REALCLEANFILES += $(sort $(foreach s,$(ZONESETS), \
108 $(foreach v,$($s_VIEWS), \
109 $v/*.serial)))
110REALCLEANDIRS += $(sort $(foreach s,$(ZONESETS),$($s_VIEWS)))
111
112## Now explain that each generated zone file depends on the corresponding
113## zonestamp. This is where things start getting a little hairy.
114$(foreach s,$(ZONESETS), \
115 $(foreach v,$($s_VIEWS), \
116 $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
117 $(eval $v/$z.zone: $v/$s.zonestamp))))
118
119## Now we have to check the individual zone files.
120ALL_ZONECHECKS = $(foreach s,$(ZONESETS), \
121 $(foreach v,$($s_VIEWS), \
122 $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
123 $v/$z.check)))
124$(ALL_ZONECHECKS) : %.check : %.zone
125 $(call v_tag,CHECK)\
126 { $(CHECKZONE) $(notdir $*) $^ || kill $$$$; } | \
127 { grep -Ev 'loaded serial|OK' || :; }
128check: $(ALL_ZONECHECKS)
129.PHONY: check $(ALL_ZONECHECKS)
130
d7af5ae7
MW
131## Finally we have to install the zone files.
132ALL_INSTALLS = $(foreach s,$(ZONESETS), \
133 $(foreach v,$($s_VIEWS), \
134 $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
135 $v/$z.inst)))
136$(ALL_INSTALLS) : %.inst : %.check
137 $(call v_tag,INST)$(ZONEINST) \
138 $(call dir-nosl,$*) $(notdir $*) <$*.zone
139install: $(ALL_INSTALLS)
140.PHONY: install $(ALL_INSTALLS)
141
5c420db9
MW
142## Files to clean.
143clean:
144 rm -f $(CLEANFILES)
145 [ "$(CLEANDIRS)x" = x ] || rmdir $(CLEANDIRS) || :
146realclean:
147 rm -f $(REALCLEANFILES)
148 [ "$(REALCLEANDIRS)x" = x ] || rmdir $(REALCLEANDIRS) || :
149.PHONY: clean realclean
150
151###----- That's all, folks --------------------------------------------------