chiark / gitweb /
Makefile: Replace the m4 crock with a proper GNU Make crock.
[zones] / Makefile
CommitLineData
5c420db9
MW
1### -*-makefile-*-
2###
3### Makefile for the DNS zones I maintain.
4###
5### (c) 2011 Mark Wooding
6
7###--------------------------------------------------------------------------
8### Silent-rules machinery.
9
10V = 0
11v_tag = $(call v_tag_$V,$1)
12v_tag_0 = @printf " %-6s %s\n" "$1" "$@";
13
14V_AT = $(V_AT_$V)
15V_AT_0 = @
16
17###--------------------------------------------------------------------------
18### Programs and options.
19
20CHECKZONE = named-checkzone -i full \
21 -k fail -M fail -n fail -S fail -W fail
22
23###--------------------------------------------------------------------------
24### Utility functions.
25
26dir-nosl = $(patsubst %/,%,$(dir $1))
27
28###--------------------------------------------------------------------------
29### Keeping all of the files straight.
30
31## Establish a default target. We'll sort out what it does later.
32all:
33.PHONY: all
34
35## Things to clean.
36CLEANFILES =
37CLEANDIRS =
38REALCLEANFILES = $(CLEANFILES)
39REALCLEANDIRS = $(CLEANDIRS)
40
41## We work in terms of `zonesets'. Each one corresponds to a Lisp source
42## file to be passed to `zone'. A zoneset has a number of different nets
43## associated with it, in the variable zoneset_NETS, and we must run it
44## through `zone' once for each net. The zoneset will make a number of
45## zones, listed in zoneset_ZONES.
46ZONESETS =
47
48###--------------------------------------------------------------------------
49### The distorted.org.uk zones.
50
51ZONESETS += distorted
52
53distorted_VIEWS = inet fretwank
54distorted_inet_NETS = inet
55distorted_fretwank_NETS = fretwank
56
57distorted_all_ZONES = distorted.org.uk io.distorted.org.uk
58distorted_fretwank_ZONES = 199.29.172.in-addr.arpa
59
60###--------------------------------------------------------------------------
61### The harlequin.org.uk zones.
62
63ZONESETS += harlequin
64
65harlequin_VIEWS = inet fretwank
66harlequin_inet_NETS = inet
67harlequin_fretwank_NETS = fretwank
68
69harlequin_all_ZONES = harlequin.org.uk
70
71###--------------------------------------------------------------------------
72### Zone construction machinery.
73
74ZONE = zone
75V_ZONE = $(call v_tag,ZONE)$(ZONE)
76
77.SECONDEXPANSION: #sorry
78
79## For each net/zoneset pair, we make a stamp file net/zoneset.stamp to
80## remember that we've made the corresponding zones.
81ALL_ZONESTAMPS = $(foreach s,$(ZONESETS), \
82 $(patsubst %,%/$s.zonestamp,$($s_VIEWS)))
83$(ALL_ZONESTAMPS) : %.zonestamp : $$(notdir $$*).lisp hosts.lisp
84 $(V_AT)mkdir -p $(dir $*)
85 $(V_ZONE) -d$(dir $*) -fview/$(call dir-nosl,$*)$(hack \
86 hack) $(addprefix -s, $($(notdir $*)_$(call dir-nosl,$*)_NETS)) $<
87 $(V_AT)touch $@
88all: $(ALL_ZONESTAMPS)
89CLEANFILES += $(sort $(foreach s,$(ZONESETS), \
90 $(foreach v,$($s_VIEWS), \
91 $v/*.zonestamp $v/*.zone)))
92REALCLEANFILES += $(sort $(foreach s,$(ZONESETS), \
93 $(foreach v,$($s_VIEWS), \
94 $v/*.serial)))
95REALCLEANDIRS += $(sort $(foreach s,$(ZONESETS),$($s_VIEWS)))
96
97## Now explain that each generated zone file depends on the corresponding
98## zonestamp. This is where things start getting a little hairy.
99$(foreach s,$(ZONESETS), \
100 $(foreach v,$($s_VIEWS), \
101 $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
102 $(eval $v/$z.zone: $v/$s.zonestamp))))
103
104## Now we have to check the individual zone files.
105ALL_ZONECHECKS = $(foreach s,$(ZONESETS), \
106 $(foreach v,$($s_VIEWS), \
107 $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
108 $v/$z.check)))
109$(ALL_ZONECHECKS) : %.check : %.zone
110 $(call v_tag,CHECK)\
111 { $(CHECKZONE) $(notdir $*) $^ || kill $$$$; } | \
112 { grep -Ev 'loaded serial|OK' || :; }
113check: $(ALL_ZONECHECKS)
114.PHONY: check $(ALL_ZONECHECKS)
115
116## Files to clean.
117clean:
118 rm -f $(CLEANFILES)
119 [ "$(CLEANDIRS)x" = x ] || rmdir $(CLEANDIRS) || :
120realclean:
121 rm -f $(REALCLEANFILES)
122 [ "$(REALCLEANDIRS)x" = x ] || rmdir $(REALCLEANDIRS) || :
123.PHONY: clean realclean
124
125###----- That's all, folks --------------------------------------------------