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