Commit | Line | Data |
---|---|---|
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 | ||
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 | CHECKZONE = named-checkzone -i full \ | |
21 | -k fail -M fail -n fail -S fail -W fail | |
22 | ||
23 | ###-------------------------------------------------------------------------- | |
24 | ### Utility functions. | |
25 | ||
26 | dir-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. | |
32 | all: | |
33 | .PHONY: all | |
34 | ||
35 | ## Things to clean. | |
36 | CLEANFILES = | |
37 | CLEANDIRS = | |
38 | REALCLEANFILES = $(CLEANFILES) | |
39 | REALCLEANDIRS = $(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. | |
46 | ZONESETS = | |
47 | ||
48 | ###-------------------------------------------------------------------------- | |
49 | ### The distorted.org.uk zones. | |
50 | ||
51 | ZONESETS += distorted | |
52 | ||
4a487d58 | 53 | distorted_VIEWS = inside outside |
ff6c53ad MW |
54 | distorted_outside_NETS = dmz |
55 | distorted_inside_NETS = unsafe | |
5c420db9 MW |
56 | |
57 | distorted_all_ZONES = distorted.org.uk io.distorted.org.uk | |
4a487d58 | 58 | distorted_inside_ZONES = 199.29.172.in-addr.arpa |
5c420db9 MW |
59 | |
60 | ###-------------------------------------------------------------------------- | |
61 | ### The harlequin.org.uk zones. | |
62 | ||
63 | ZONESETS += harlequin | |
64 | ||
4a487d58 | 65 | harlequin_VIEWS = inside outside |
ff6c53ad MW |
66 | harlequin_outside_NETS = dmz |
67 | harlequin_inside_NETS = unsafe | |
5c420db9 MW |
68 | |
69 | harlequin_all_ZONES = harlequin.org.uk | |
70 | ||
71 | ###-------------------------------------------------------------------------- | |
72 | ### Zone construction machinery. | |
73 | ||
74 | ZONE = zone | |
75 | V_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. | |
81 | ALL_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 $@ | |
88 | all: $(ALL_ZONESTAMPS) | |
89 | CLEANFILES += $(sort $(foreach s,$(ZONESETS), \ | |
90 | $(foreach v,$($s_VIEWS), \ | |
91 | $v/*.zonestamp $v/*.zone))) | |
92 | REALCLEANFILES += $(sort $(foreach s,$(ZONESETS), \ | |
93 | $(foreach v,$($s_VIEWS), \ | |
94 | $v/*.serial))) | |
95 | REALCLEANDIRS += $(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. | |
105 | ALL_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' || :; } | |
113 | check: $(ALL_ZONECHECKS) | |
114 | .PHONY: check $(ALL_ZONECHECKS) | |
115 | ||
116 | ## Files to clean. | |
117 | clean: | |
118 | rm -f $(CLEANFILES) | |
119 | [ "$(CLEANDIRS)x" = x ] || rmdir $(CLEANDIRS) || : | |
120 | realclean: | |
121 | rm -f $(REALCLEANFILES) | |
122 | [ "$(REALCLEANDIRS)x" = x ] || rmdir $(REALCLEANDIRS) || : | |
123 | .PHONY: clean realclean | |
124 | ||
125 | ###----- That's all, folks -------------------------------------------------- |