chiark / gitweb /
felixpearce.lisp: A records for web service.
[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 ifeq ($(MASTER),localhost)
27 ZONEINST                 = userv zoneconf install
28 else
29 ZONEINST                 = ssh zoneconf@$(MASTER)
30 endif
31
32 ###--------------------------------------------------------------------------
33 ### Utility functions.
34
35 dir-nosl = $(patsubst %/,%,$(dir $1))
36
37 ###--------------------------------------------------------------------------
38 ### Keeping all of the files straight.
39
40 ## Establish a default target.  We'll sort out what it does later.
41 all:
42 .PHONY: all
43
44 ## Things to clean.
45 CLEANFILES               =
46 CLEANDIRS                =
47 REALCLEANFILES           = $(CLEANFILES)
48 REALCLEANDIRS            = $(CLEANDIRS)
49
50 ## We work in terms of `zonesets'.  Each one corresponds to a Lisp source
51 ## file to be passed to `zone'.  A zoneset has a number of different nets
52 ## associated with it, in the variable zoneset_NETS, and we must run it
53 ## through `zone' once for each net.  The zoneset will make a number of
54 ## zones, listed in zoneset_ZONES.
55 ZONESETS                 =
56
57 ###--------------------------------------------------------------------------
58 ### The distorted.org.uk zones.
59
60 ZONESETS                += distorted
61
62 distorted_VIEWS          = inside outside
63 distorted_outside_NETS   = dmz
64 distorted_inside_NETS    = unsafe
65
66 distorted_all_ZONES      = distorted.org.uk io.distorted.org.uk
67 distorted_inside_ZONES   = 199.29.172.in-addr.arpa
68
69 ###--------------------------------------------------------------------------
70 ### The harlequin.org.uk zones.
71
72 ZONESETS                += harlequin
73
74 harlequin_VIEWS          = inside outside
75 harlequin_outside_NETS   = dmz
76 harlequin_inside_NETS    = unsafe
77
78 harlequin_all_ZONES      = harlequin.org.uk
79
80 ###--------------------------------------------------------------------------
81 ### The felixpearce.com zones.
82
83 ZONESETS                += felixpearce
84
85 felixpearce_VIEWS        = inside outside
86 felixpearce_outside_NETS = dmz
87 felixpearce_inside_NETS  = unsafe
88
89 felixpearce_all_ZONES    = felixpearce.com
90
91 ###--------------------------------------------------------------------------
92 ### Zone construction machinery.
93
94 ZONE                     = zone
95 V_ZONE                   = $(call v_tag,ZONE)$(ZONE)
96
97 .SECONDEXPANSION: #sorry
98
99 ## For each net/zoneset pair, we make a stamp file net/zoneset.stamp to
100 ## remember that we've made the corresponding zones.
101 ALL_ZONESTAMPS = $(foreach s,$(ZONESETS), \
102         $(patsubst %,%/$s.zonestamp,$($s_VIEWS)))
103 $(ALL_ZONESTAMPS) : %.zonestamp : $$(notdir $$*).lisp hosts.lisp
104         $(V_AT)mkdir -p $(dir $*)
105         $(V_ZONE) -d$(dir $*) -fview/$(call dir-nosl,$*)$(hack \
106                 hack) $(addprefix -s, \
107                 $($(notdir $*)_$(call dir-nosl,$*)_NETS)) $<
108         $(V_AT)touch $@
109 all: $(ALL_ZONESTAMPS)
110 CLEANFILES += $(sort $(foreach s,$(ZONESETS), \
111                        $(foreach v,$($s_VIEWS), \
112                          $v/*.zonestamp $v/*.zone)))
113 REALCLEANFILES += $(sort $(foreach s,$(ZONESETS), \
114                            $(foreach v,$($s_VIEWS), \
115                              $v/*.serial)))
116 REALCLEANDIRS += $(sort $(foreach s,$(ZONESETS),$($s_VIEWS)))
117
118 ## Now explain that each generated zone file depends on the corresponding
119 ## zonestamp.  This is where things start getting a little hairy.
120 $(foreach s,$(ZONESETS), \
121   $(foreach v,$($s_VIEWS), \
122     $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
123       $(eval $v/$z.zone: $v/$s.zonestamp))))
124
125 ## Now we have to check the individual zone files.
126 ALL_ZONECHECKS = $(foreach s,$(ZONESETS), \
127         $(foreach v,$($s_VIEWS), \
128           $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
129             $v/$z.check)))
130 $(ALL_ZONECHECKS) : %.check : %.zone
131         $(call v_tag,CHECK)\
132                 { $(CHECKZONE) $(notdir $*) $^ || kill $$$$; } | \
133                 { grep -Ev 'loaded serial|OK' || :; }
134 check: $(ALL_ZONECHECKS)
135 .PHONY: check $(ALL_ZONECHECKS)
136
137 ## Finally we have to install the zone files.
138 ALL_INSTALLS = $(foreach s,$(ZONESETS), \
139         $(foreach v,$($s_VIEWS), \
140           $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
141             $v/$z.inst)))
142 $(ALL_INSTALLS) : %.inst : %.check
143         $(call v_tag,INST)$(ZONEINST) \
144                 $(call dir-nosl,$*) $(notdir $*) <$*.zone
145 install: $(ALL_INSTALLS)
146 .PHONY: install $(ALL_INSTALLS)
147
148 ## Files to clean.
149 clean:
150         rm -f $(CLEANFILES)
151         [ "$(CLEANDIRS)x" = x ] || rmdir $(CLEANDIRS) || :
152 realclean:
153         rm -f $(REALCLEANFILES)
154         [ "$(REALCLEANDIRS)x" = x ] || rmdir $(REALCLEANDIRS) || :
155 .PHONY: clean realclean
156
157 ###----- That's all, folks --------------------------------------------------