Makefile: Replace the m4 crock with a proper GNU Make crock.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 18 Jun 2011 19:59:20 +0000 (20:59 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Tue, 19 Jul 2011 20:49:54 +0000 (21:49 +0100)
The m4 was an unmaintainable pile of horribleness.  It needed
replacing.  The only question is: have I replaced it with something
even worse?

An important new feature of the Makefile is that we can be interested in
different zones in each view.  Previously, there was a list containing
the zones defined by the zoneset, and each view had to have the same
zones in it.  There's now a list ZONESET_all_ZONES containing zones
common to all views in a zoneset, but there's also a variable
ZONESET_VIEW_ZONES for the zones which are specific to each view.

We've also made the separation between preferred subnets and views
clearer.  Although we're still using the same names for both right now,
this will change soon.  There's now a list of preferred subnets for each
view, and the feature keyword has changed to :VIEW/name.

This is important because the new publication machinery will object if
we try to feed it zones which it doesn't know about.

We also drop the various dynamic zones from publication, because they
always had to be maintained manually anyway.

.gitignore
Makefile [new file with mode: 0644]
Makefile.m4 [deleted file]
distorted.lisp
harlequin.lisp

index 2184fad..41f5617 100644 (file)
@@ -1,4 +1,5 @@
 *.serial
+*.zonestamp
 *.zone
 publish
 *.aux
@@ -8,4 +9,3 @@ publish
 *.lof
 *.lot
 *.toc
-Makefile
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..b8dbcb7
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,125 @@
+### -*-makefile-*-
+###
+### Makefile for the DNS zones I maintain.
+###
+### (c) 2011 Mark Wooding
+
+###--------------------------------------------------------------------------
+### Silent-rules machinery.
+
+V                       = 0
+v_tag                   = $(call v_tag_$V,$1)
+v_tag_0                         = @printf "  %-6s %s\n" "$1" "$@";
+
+V_AT                    = $(V_AT_$V)
+V_AT_0                  = @
+
+###--------------------------------------------------------------------------
+### Programs and options.
+
+CHECKZONE               = named-checkzone -i full \
+                               -k fail -M fail -n fail -S fail -W fail
+
+###--------------------------------------------------------------------------
+### Utility functions.
+
+dir-nosl = $(patsubst %/,%,$(dir $1))
+
+###--------------------------------------------------------------------------
+### Keeping all of the files straight.
+
+## Establish a default target.  We'll sort out what it does later.
+all:
+.PHONY: all
+
+## Things to clean.
+CLEANFILES              =
+CLEANDIRS               =
+REALCLEANFILES          = $(CLEANFILES)
+REALCLEANDIRS           = $(CLEANDIRS)
+
+## We work in terms of `zonesets'.  Each one corresponds to a Lisp source
+## file to be passed to `zone'.  A zoneset has a number of different nets
+## associated with it, in the variable zoneset_NETS, and we must run it
+## through `zone' once for each net.  The zoneset will make a number of
+## zones, listed in zoneset_ZONES.
+ZONESETS                =
+
+###--------------------------------------------------------------------------
+### The distorted.org.uk zones.
+
+ZONESETS               += distorted
+
+distorted_VIEWS                 = inet fretwank
+distorted_inet_NETS     = inet
+distorted_fretwank_NETS         = fretwank
+
+distorted_all_ZONES     = distorted.org.uk io.distorted.org.uk
+distorted_fretwank_ZONES = 199.29.172.in-addr.arpa
+
+###--------------------------------------------------------------------------
+### The harlequin.org.uk zones.
+
+ZONESETS               += harlequin
+
+harlequin_VIEWS                 = inet fretwank
+harlequin_inet_NETS     = inet
+harlequin_fretwank_NETS         = fretwank
+
+harlequin_all_ZONES     = harlequin.org.uk
+
+###--------------------------------------------------------------------------
+### Zone construction machinery.
+
+ZONE                    = zone
+V_ZONE                  = $(call v_tag,ZONE)$(ZONE)
+
+.SECONDEXPANSION: #sorry
+
+## For each net/zoneset pair, we make a stamp file net/zoneset.stamp to
+## remember that we've made the corresponding zones.
+ALL_ZONESTAMPS = $(foreach s,$(ZONESETS), \
+       $(patsubst %,%/$s.zonestamp,$($s_VIEWS)))
+$(ALL_ZONESTAMPS) : %.zonestamp : $$(notdir $$*).lisp hosts.lisp
+       $(V_AT)mkdir -p $(dir $*)
+       $(V_ZONE) -d$(dir $*) -fview/$(call dir-nosl,$*)$(hack \
+               hack) $(addprefix -s, $($(notdir $*)_$(call dir-nosl,$*)_NETS)) $<
+       $(V_AT)touch $@
+all: $(ALL_ZONESTAMPS)
+CLEANFILES += $(sort $(foreach s,$(ZONESETS), \
+                      $(foreach v,$($s_VIEWS), \
+                        $v/*.zonestamp $v/*.zone)))
+REALCLEANFILES += $(sort $(foreach s,$(ZONESETS), \
+                          $(foreach v,$($s_VIEWS), \
+                            $v/*.serial)))
+REALCLEANDIRS += $(sort $(foreach s,$(ZONESETS),$($s_VIEWS)))
+
+## Now explain that each generated zone file depends on the corresponding
+## zonestamp.  This is where things start getting a little hairy.
+$(foreach s,$(ZONESETS), \
+  $(foreach v,$($s_VIEWS), \
+    $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
+      $(eval $v/$z.zone: $v/$s.zonestamp))))
+
+## Now we have to check the individual zone files.
+ALL_ZONECHECKS = $(foreach s,$(ZONESETS), \
+       $(foreach v,$($s_VIEWS), \
+         $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
+           $v/$z.check)))
+$(ALL_ZONECHECKS) : %.check : %.zone
+       $(call v_tag,CHECK)\
+               { $(CHECKZONE) $(notdir $*) $^ || kill $$$$; } | \
+               { grep -Ev 'loaded serial|OK' || :; }
+check: $(ALL_ZONECHECKS)
+.PHONY: check $(ALL_ZONECHECKS)
+
+## Files to clean.
+clean:
+       rm -f $(CLEANFILES)
+       [ "$(CLEANDIRS)x" = x ] || rmdir $(CLEANDIRS) || :
+realclean:
+       rm -f $(REALCLEANFILES)
+       [ "$(REALCLEANDIRS)x" = x ] || rmdir $(REALCLEANDIRS) || :
+.PHONY: clean realclean
+
+###----- That's all, folks --------------------------------------------------
diff --git a/Makefile.m4 b/Makefile.m4
deleted file mode 100644 (file)
index 8ec905a..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-### Makefile for mdw's zones
-###
-### Preprocessed with m4, for the sake of madness
-
-m4_divert(-1)
-###--------------------------------------------------------------------------
-### M4 trickery.
-
-m4_changequote([, ])
-m4_define([_dolist], [m4_pushdef([$1])__loop($@)m4_popdef([$1])])
-m4_define([__loop], [m4_ifelse([$2], [()], ,m4_dnl
-[m4_define([$1], __first$2)$3[]__loop([$1],(m4_shift$2),[$3])])])
-m4_define([__first], [$1])
-
-m4_define([DOMAIN], [m4_dnl
-m4_pushdef([_undivert], [m4_divert(]m4_divnum[)m4_popdef([_undivert])])m4_dnl
-m4_divert(10)m4_dnl
-$1_SUBNETS = _dolist([_subnet], [($2)], [ _subnet])
-$1_ZONES = _dolist([_zone], [($3)], [ _zone])
-$1_ZONE_FILES = _dolist([_subnet], [($2)],
-       [_dolist([_zone], [($3)], [ _subnet/_zone.zone])])
-ALL_SUBNETS += $($1_SUBNETS)
-ALL_ZONES += $($1_ZONES)
-ALL_ZONE_FILES += $($1_ZONE_FILES)
-ALL_CLEAN_FILES += _dolist([_subnet], [($2)], [ _subnet/*])
-m4_divert(30)m4_dnl
-$($1_ZONE_FILES): $1.lisp $(ZONEDEPS)
-       mkdir -p $($1_SUBNETS)m4_dnl
-_dolist([_subnet], [($2)], [
-       $(ZONE) -d _subnet/ -f subnet/_subnet -s _subnet $1.lisp])
-_undivert[]m4_dnl
-])
-
-m4_divert(-1)
-###--------------------------------------------------------------------------
-### Domains.
-
-DOMAIN([distorted], [inet, fretwank],
-       [distorted.org.uk, io.distorted.org.uk, dhcp.distorted.org.uk,
-        204.49.62.in-addr.arpa, 198.29.172.in-addr.arpa,
-        199.29.172.in-addr.arpa, dhcp.199.29.172.in-addr.arpa])
-DOMAIN([harlequin], [inet, fretwank], [harlequin.org.uk])
-
-m4_divert(0)
-###--------------------------------------------------------------------------
-### Make configuration.
-
-ZONE = zone
-
-ALL_ZONES =
-ALL_ZONE_FILES =
-ALL_CLEAN_FILES =
-ALL_SUBNETS =
-
-PUBLISH = publish
-
-ZONEDEPS = hosts.lisp
-
-DOCS = distorted.tex
-DOC_OUTPUTS = $(foreach suffix,dvi ps,\
-               $(patsubst %.tex,%.$(suffix),$(DOCS)))
-
-m4_divert(20)
-###--------------------------------------------------------------------------
-### Rules
-
-all: $(ALL_ZONE_FILES)
-doc: $(DOC_OUTPUTS)
-
-install: all
-       ##
-       ## Make directories
-       rm -rf $(PUBLISH).new
-       mkdir $(PUBLISH).new
-       cd $(PUBLISH).new && mkdir $(sort $(ALL_SUBNETS))
-       ##
-       ## Copy zone files to output
-       for i in $(ALL_ZONE_FILES); do \
-         cp $$i $(PUBLISH).new/$$i; \
-       done
-       ##
-       ## Make links as necessary
-       cd $(PUBLISH).new; \
-       for i in $(sort $(ALL_SUBNETS)); do \
-         test $$i = inet && continue; \
-         for z in $(sort $(ALL_ZONES)); do \
-           test -f $$i/$$z.zone || ln -s ../inet/$$z.zone $$i/$$z.zone; \
-         done; \
-       done
-       ##
-       ## Switch over
-       rm -rf $(PUBLISH).old
-       mv $(PUBLISH) $(PUBLISH).old
-       mv $(PUBLISH).new $(PUBLISH)
-       ##
-       ## Get nameserver to reload changed zones
-       for i in $(sort $(ALL_SUBNETS)); do \
-         for z in $(sort $(ALL_ZONES)); do \
-           cmp $(PUBLISH)/$$i/$$z.zone $(PUBLISH).old/$$i/$$z.zone \
-               >/dev/null 2>&1 && continue; \
-           echo -n "$$z ($$i): "; \
-           userv root named-reload $$z $$i; \
-         done; \
-       done
-       ##
-       ## Clear up mess
-       rm -rf $(PUBLISH).old
-
-%.dvi: %.tex
-       latex $<
-       latex $<
-
-%.ps: %.dvi
-       dvips -o $@ $<
-
-m4_divert(40)
-Makefile: Makefile.m4
-       m4 -P $< >$@.new
-       mv $@.new $@
-
-clean:
-       rm -f $(ALL_ZONE_FILES) $(ALL_CLEAN_FILES) \
-               *.toc *.lof *.lot *.log *.dvi *.ps *.aux
-       rmdir $(sort $(ALL_SUBNETS))
-
-###----- That's all, folks --------------------------------------------------
index 416d98b..07f1ea8 100644 (file)
 (defzone distorted.org.uk
   ;;
   ;; Nameservers.
-  :ns #+subnet/fretwank ((vampire.ns :ip vampire))
-      #-subnet/fretwank ((mythic-beasts-1.ns :ip mythic-ns1)
-                        (mythic-beasts-2.ns :ip mythic-ns2)
-                        (chiark.ns :ip chiark.greenend.org.uk)
-                        (radius.ns :ip radius.inet)
-                        (vampire.ns :ip vampire.inet))
+  :ns #+view/fretwank ((vampire.ns :ip vampire))
+      #-view/fretwank ((mythic-beasts-1.ns :ip mythic-ns1)
+                      (mythic-beasts-2.ns :ip mythic-ns2)
+                      (chiark.ns :ip chiark.greenend.org.uk)
+                      (radius.ns :ip radius.inet)
+                      (vampire.ns :ip vampire.inet))
   ;;
   ;; Mail servers.
   ((@ mail lists bugs cryptomail)
   (mz (its :a mz))
   ;;
   ;; Delegations.
-  #+subnet/fretwank (dhcp :ns (vampire.ns))
+  #+view/fretwank (dhcp :ns (vampire.ns))
   (io :ns ((ns.io :ip dns-frontend))))
 
 ;;;--------------------------------------------------------------------------
 (defrevzone trusted
   :ns ((vampire.ns :ip vampire))
   :reverse trusted
-  #+subnet/fretwank (dhcp :ns (metalzone.ns vampire.ns))
-  #+subnet/fretwank (@ :cidr-delegation
-                      (dhcp
-                       (dhcp 199.29.172.dhcp.199.29.172.in-addr.arpa))))
+  #+view/fretwank (dhcp :ns (metalzone.ns vampire.ns))
+  #+view/fretwank (@ :cidr-delegation
+                    (dhcp
+                     (dhcp 199.29.172.dhcp.199.29.172.in-addr.arpa))))
 
 (defrevzone untrusted
   :ns ((vampire.ns :ip vampire))
index 3090579..c7f9682 100644 (file)
 (defzone harlequin.org.uk
   ;;
   ;; Nameservers
-  :ns #+subnet/fretwank ((vampire.ns :ip vampire))
-      #-subnet/fretwank ((mythic-beasts-1.ns :ip mythic-ns1)
-                        (mythic-beasts-2.ns :ip mythic-ns2)
-                        (radius.ns :ip radius.demon)
-                        (vampire.ns :ip vampire.demon))
+  :ns #+view/fretwank ((vampire.ns :ip vampire))
+      #-view/fretwank ((mythic-beasts-1.ns :ip mythic-ns1)
+                      (mythic-beasts-2.ns :ip mythic-ns2)
+                      (radius.ns :ip radius.demon)
+                      (vampire.ns :ip vampire.demon))
   ;;
   ;; Mail servers
   :mx ((mail :ip mail))