3 ### Makefile for the DNS zones I maintain.
5 ### (c) 2011 Mark Wooding
7 ###--------------------------------------------------------------------------
8 ### Silent-rules machinery.
11 v_tag
= $(call v_tag_
$V,$1)
12 v_tag_0
= @printf
" %-6s %s\n" "$1" "$@";
17 ###--------------------------------------------------------------------------
18 ### Programs and options.
21 CHECKZONE
= named-checkzone
-i full \
22 -k fail
-M fail
-n fail
-S fail
-W fail
26 inside_MASTER
= precision
29 ifeq ($(MASTER
),localhost
)
30 ZONEINST
= userv zoneconf
install
32 ZONEINST
= ssh zoneconf@
$(MASTER
)
35 ###--------------------------------------------------------------------------
36 ### Utility functions.
38 dir-nosl
= $(patsubst %/,%,$(dir $1))
40 ###--------------------------------------------------------------------------
41 ### Keeping all of the files straight.
43 ## Establish a default target. We'll sort out what it does later.
50 REALCLEANFILES
= $(CLEANFILES
)
51 REALCLEANDIRS
= $(CLEANDIRS
)
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.
60 ###--------------------------------------------------------------------------
61 ### The distorted.org.uk zones.
65 distorted_VIEWS
= inside outside
66 distorted_outside_NETS
= dmz jump
67 distorted_inside_NETS
= unsafe colo
69 distorted_all_ZONES
+= distorted.org.uk
70 distorted_all_ZONES
+= 199.29.172.in-addr.arpa
72 ###--------------------------------------------------------------------------
73 ### The harlequin.org.uk zones.
77 harlequin_VIEWS
= inside outside
78 harlequin_outside_NETS
= dmz
79 harlequin_inside_NETS
= unsafe
81 harlequin_all_ZONES
= harlequin.org.uk
83 ###--------------------------------------------------------------------------
84 ### The felixpearce.com zones.
86 ZONESETS
+= felixpearce
88 felixpearce_VIEWS
= inside outside
89 felixpearce_outside_NETS
= dmz
90 felixpearce_inside_NETS
= unsafe
92 felixpearce_all_ZONES
= felixpearce.com
94 ###--------------------------------------------------------------------------
95 ### Zone construction machinery.
98 V_ZONE
= $(call v_tag
,ZONE
)$(ZONE
)
100 .SECONDEXPANSION
: #sorry
102 ## For each net/zoneset pair, we make a stamp file net/zoneset.stamp to
103 ## remember that we've made the corresponding zones.
104 ALL_ZONESTAMPS
= $(foreach s
,$(ZONESETS
), \
105 $(patsubst %,%/$s.zonestamp
,$($s_VIEWS)))
106 $(ALL_ZONESTAMPS
) : %.zonestamp
: $$(notdir $$*).lisp hosts.lisp
107 $(V_AT
)mkdir
-p
$(dir $*)
108 $(V_ZONE
) -d
$(dir $*) -fview
/$(call dir-nosl
,$*)$(hack \
109 hack
) $(addprefix -s
, \
110 $($(notdir $*)_
$(call dir-nosl
,$*)_NETS
)) $<
112 all: $(ALL_ZONESTAMPS
)
113 CLEANFILES
+= $(sort $(foreach s
,$(ZONESETS
), \
114 $(foreach v
,$($s_VIEWS), \
115 $v/*.zonestamp
$v/*.zone
)))
116 REALCLEANFILES
+= $(sort $(foreach s
,$(ZONESETS
), \
117 $(foreach v
,$($s_VIEWS), \
119 REALCLEANDIRS
+= $(sort $(foreach s
,$(ZONESETS
),$($s_VIEWS)))
121 ## Now explain that each generated zone file depends on the corresponding
122 ## zonestamp. This is where things start getting a little hairy.
123 $(foreach s
,$(ZONESETS
), \
124 $(foreach v
,$($s_VIEWS), \
125 $(foreach z
,$($s_all_ZONES) $($s_$v_ZONES), \
126 $(eval
$v/$z.zone
: $v/$s.zonestamp
))))
128 ## Now we have to check the individual zone files.
129 ALL_ZONECHECKS
= $(foreach s
,$(ZONESETS
), \
130 $(foreach v
,$($s_VIEWS), \
131 $(foreach z
,$($s_all_ZONES) $($s_$v_ZONES), \
133 $(ALL_ZONECHECKS
) : %.
check : %.zone
135 { $(CHECKZONE
) $(notdir $*) $^ || kill
$$$$; } | \
136 { grep
-Ev
'loaded serial|OK' ||
:; }
137 check: $(ALL_ZONECHECKS
)
138 .PHONY
: check $(ALL_ZONECHECKS
)
140 ## Finally we have to install the zone files.
141 ALL_INSTALLS
= $(foreach s
,$(ZONESETS
), \
142 $(foreach v
,$($s_VIEWS), \
143 $(foreach z
,$($s_all_ZONES) $($s_$v_ZONES), \
145 $(ALL_INSTALLS
) : %.inst
: %.
check
146 $(call v_tag
,INST
)$(ZONEINST
) \
147 $(call dir-nosl
,$*) $(notdir $*) <$*.zone
148 install: $(ALL_INSTALLS
)
149 .PHONY
: install $(ALL_INSTALLS
)
154 [ "$(CLEANDIRS)x" = x
] || rmdir
$(CLEANDIRS
) ||
:
156 rm -f
$(REALCLEANFILES
)
157 [ "$(REALCLEANDIRS)x" = x
] || rmdir
$(REALCLEANDIRS
) ||
:
158 .PHONY
: clean realclean
160 ###----- That's all, folks --------------------------------------------------