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
28 ifeq ($(MASTER
),localhost
)
29 ZONEINST
= userv zoneconf
install
31 ZONEINST
= ssh zoneconf@
$(MASTER
)
34 ###--------------------------------------------------------------------------
35 ### Utility functions.
37 dir-nosl
= $(patsubst %/,%,$(dir $1))
39 ###--------------------------------------------------------------------------
40 ### Keeping all of the files straight.
42 ## Establish a default target. We'll sort out what it does later.
49 REALCLEANFILES
= $(CLEANFILES
)
50 REALCLEANDIRS
= $(CLEANDIRS
)
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.
59 ###--------------------------------------------------------------------------
60 ### The distorted.org.uk zones.
64 distorted_VIEWS
= inside outside
65 distorted_outside_NETS
= dmz jump
66 distorted_inside_NETS
= any unsafe colo vpn
68 distorted_all_ZONES
+= distorted.org.uk
69 distorted_all_ZONES
+= 199.29.172.in-addr.arpa
71 ###--------------------------------------------------------------------------
76 binswood_VIEWS
= outside
77 binswood_all_ZONES
+= binswood.org.uk
78 binswood_all_ZONES
+= 27.165.10.in-addr.arpa
83 odin_all_ZONES
= odin.gg
85 ###--------------------------------------------------------------------------
86 ### Zone construction machinery.
89 V_ZONE
= $(call v_tag
,ZONE
)$(ZONE
)
91 .SECONDEXPANSION
: #sorry
93 ## For each net/zoneset pair, we make a stamp file net/zoneset.stamp to
94 ## remember that we've made the corresponding zones.
95 ALL_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 \
100 hack
) $(addprefix -s
, \
101 $($(notdir $*)_
$(call dir-nosl
,$*)_NETS
)) $<
103 all: $(ALL_ZONESTAMPS
)
104 CLEANFILES
+= $(sort $(foreach s
,$(ZONESETS
), \
105 $(foreach v
,$($s_VIEWS), \
106 $v/*.zonestamp
$v/*.zone
)))
107 REALCLEANFILES
+= $(sort $(foreach s
,$(ZONESETS
), \
108 $(foreach v
,$($s_VIEWS), \
110 REALCLEANDIRS
+= $(sort $(foreach s
,$(ZONESETS
),$($s_VIEWS)))
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
))))
119 ## Now we have to check the individual zone files.
120 ALL_ZONECHECKS
= $(foreach s
,$(ZONESETS
), \
121 $(foreach v
,$($s_VIEWS), \
122 $(foreach z
,$($s_all_ZONES) $($s_$v_ZONES), \
124 $(ALL_ZONECHECKS
) : %.
check : %.zone
126 { $(CHECKZONE
) $(notdir $*) $^ || kill
$$$$; } | \
127 { grep
-Ev
'loaded serial|OK' ||
:; }
128 check: $(ALL_ZONECHECKS
)
129 .PHONY
: check $(ALL_ZONECHECKS
)
131 ## Finally we have to install the zone files.
132 ALL_INSTALLS
= $(foreach s
,$(ZONESETS
), \
133 $(foreach v
,$($s_VIEWS), \
134 $(foreach z
,$($s_all_ZONES) $($s_$v_ZONES), \
136 $(ALL_INSTALLS
) : %.inst
: %.
check
137 $(call v_tag
,INST
)$(ZONEINST
) \
138 $(call dir-nosl
,$*) $(notdir $*) <$*.zone
139 install: $(ALL_INSTALLS
)
140 .PHONY
: install $(ALL_INSTALLS
)
145 [ "$(CLEANDIRS)x" = x
] || rmdir
$(CLEANDIRS
) ||
:
147 rm -f
$(REALCLEANFILES
)
148 [ "$(REALCLEANDIRS)x" = x
] || rmdir
$(REALCLEANDIRS
) ||
:
149 .PHONY
: clean realclean
151 ###----- That's all, folks --------------------------------------------------