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 ifeq ($(MASTER
),localhost
)
27 ZONEINST
= userv zoneconf
install
29 ZONEINST
= ssh zoneconf@
$(MASTER
)
32 ###--------------------------------------------------------------------------
33 ### Utility functions.
35 dir-nosl
= $(patsubst %/,%,$(dir $1))
37 ###--------------------------------------------------------------------------
38 ### Keeping all of the files straight.
40 ## Establish a default target. We'll sort out what it does later.
47 REALCLEANFILES
= $(CLEANFILES
)
48 REALCLEANDIRS
= $(CLEANDIRS
)
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.
57 ###--------------------------------------------------------------------------
58 ### The distorted.org.uk zones.
62 distorted_VIEWS
= inside outside
63 distorted_outside_NETS
= dmz
64 distorted_inside_NETS
= unsafe
66 distorted_all_ZONES
= distorted.org.uk io.distorted.org.uk
67 distorted_inside_ZONES
= 199.29.172.in-addr.arpa
69 ###--------------------------------------------------------------------------
70 ### The harlequin.org.uk zones.
74 harlequin_VIEWS
= inside outside
75 harlequin_outside_NETS
= dmz
76 harlequin_inside_NETS
= unsafe
78 harlequin_all_ZONES
= harlequin.org.uk
80 ###--------------------------------------------------------------------------
81 ### Zone construction machinery.
84 V_ZONE
= $(call v_tag
,ZONE
)$(ZONE
)
86 .SECONDEXPANSION
: #sorry
88 ## For each net/zoneset pair, we make a stamp file net/zoneset.stamp to
89 ## remember that we've made the corresponding zones.
90 ALL_ZONESTAMPS
= $(foreach s
,$(ZONESETS
), \
91 $(patsubst %,%/$s.zonestamp
,$($s_VIEWS)))
92 $(ALL_ZONESTAMPS
) : %.zonestamp
: $$(notdir $$*).lisp hosts.lisp
93 $(V_AT
)mkdir
-p
$(dir $*)
94 $(V_ZONE
) -d
$(dir $*) -fview
/$(call dir-nosl
,$*)$(hack \
95 hack
) $(addprefix -s
, \
96 $($(notdir $*)_
$(call dir-nosl
,$*)_NETS
)) $<
98 all: $(ALL_ZONESTAMPS
)
99 CLEANFILES
+= $(sort $(foreach s
,$(ZONESETS
), \
100 $(foreach v
,$($s_VIEWS), \
101 $v/*.zonestamp
$v/*.zone
)))
102 REALCLEANFILES
+= $(sort $(foreach s
,$(ZONESETS
), \
103 $(foreach v
,$($s_VIEWS), \
105 REALCLEANDIRS
+= $(sort $(foreach s
,$(ZONESETS
),$($s_VIEWS)))
107 ## Now explain that each generated zone file depends on the corresponding
108 ## zonestamp. This is where things start getting a little hairy.
109 $(foreach s
,$(ZONESETS
), \
110 $(foreach v
,$($s_VIEWS), \
111 $(foreach z
,$($s_all_ZONES) $($s_$v_ZONES), \
112 $(eval
$v/$z.zone
: $v/$s.zonestamp
))))
114 ## Now we have to check the individual zone files.
115 ALL_ZONECHECKS
= $(foreach s
,$(ZONESETS
), \
116 $(foreach v
,$($s_VIEWS), \
117 $(foreach z
,$($s_all_ZONES) $($s_$v_ZONES), \
119 $(ALL_ZONECHECKS
) : %.
check : %.zone
121 { $(CHECKZONE
) $(notdir $*) $^ || kill
$$$$; } | \
122 { grep
-Ev
'loaded serial|OK' ||
:; }
123 check: $(ALL_ZONECHECKS
)
124 .PHONY
: check $(ALL_ZONECHECKS
)
126 ## Finally we have to install the zone files.
127 ALL_INSTALLS
= $(foreach s
,$(ZONESETS
), \
128 $(foreach v
,$($s_VIEWS), \
129 $(foreach z
,$($s_all_ZONES) $($s_$v_ZONES), \
131 $(ALL_INSTALLS
) : %.inst
: %.
check
132 $(call v_tag
,INST
)$(ZONEINST
) \
133 $(call dir-nosl
,$*) $(notdir $*) <$*.zone
134 install: $(ALL_INSTALLS
)
135 .PHONY
: install $(ALL_INSTALLS
)
140 [ "$(CLEANDIRS)x" = x
] || rmdir
$(CLEANDIRS
) ||
:
142 rm -f
$(REALCLEANFILES
)
143 [ "$(REALCLEANDIRS)x" = x
] || rmdir
$(REALCLEANDIRS
) ||
:
144 .PHONY
: clean realclean
146 ###----- That's all, folks --------------------------------------------------