Makefile: New target VIEW/ZONE.zonediff shows pending differences.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 25 Mar 2015 21:56:12 +0000 (21:56 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 26 Mar 2015 01:02:44 +0000 (01:02 +0000)
Requires Tony Finch's winning nsdiff(1) tool.  See

http://dotat.at/prog/nsdiff/

Makefile

index 01b0953..69191ed 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -78,6 +78,8 @@ distorted_all_ZONES   += 0.4.7.9.0.7.4.0.1.0.0.2.ip6.arpa
 distorted_all_ZONES    += 9.d.1.0.0.0.0.0.8.a.b.0.1.0.0.2.ip6.arpa
 distorted_all_ZONES    += 9.d.1.0.8.a.b.0.1.0.0.2.ip6.arpa
 
+distorted_outside_NSDIFF = -sradius.dmz.distorted.org.uk
+
 ###--------------------------------------------------------------------------
 ### Other zones.
 
@@ -136,6 +138,12 @@ $(foreach s,$(ZONESETS), \
     $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
       $(eval $v/$z.zone: $v/$s.zonestamp))))
 
+## Prepare a mapping from zone names back to their owning zonesets.
+$(foreach s,$(ZONESETS), \
+  $(foreach z,$(sort $(foreach v,$($s_VIEWS), \
+       $($s_all_ZONES) $($s_$v_ZONES))), \
+    $(eval $z_ZONESET = $s)))
+
 ## Now we have to check the individual zone files.
 ALL_ZONECHECKS = $(foreach s,$(ZONESETS), \
        $(foreach v,$($s_VIEWS), \
@@ -148,6 +156,21 @@ $(ALL_ZONECHECKS) : %.check : %.zone
 check: $(ALL_ZONECHECKS)
 .PHONY: check $(ALL_ZONECHECKS)
 
+## If nsdiff(1) is available then we can show what changes we will make if
+## we install the new zone files.
+ALL_ZONEDIFFS = $(foreach s,$(ZONESETS), \
+       $(foreach v,$($s_VIEWS), \
+         $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
+           $v/$z.zonediff)))
+run-nsdiff = nsdiff -d -v "" $2 \
+       $($($(call notdir,$1)_ZONESET)_$(call dir-nosl,$1)_NSDIFF) \
+       $(call notdir,$1) $1.zone
+$(ALL_ZONEDIFFS) : %.zonediff : %.zone
+       $(call v_tag,NSDIFF)$(call run-nsdiff,$*,-q); \
+       rc=$$?; case $$rc in 1) $(call run-nsdiff,$*); rc=$$? ;; esac; \
+       case $$rc in 0 | 1) : ;; *) exit $$? ;; esac
+diff: $(ALL_ZONEDIFFS)
+
 ## Finally we have to install the zone files.
 ALL_INSTALLS = $(foreach s,$(ZONESETS), \
        $(foreach v,$($s_VIEWS), \