[ntpsec commit] Refactor configuration logic so bulky probes are not in the main line.

Eric S. Raymond esr at ntpsec.org
Wed Sep 30 21:37:29 UTC 2015


Module:    ntpsec
Branch:    master
Commit:    e3444d00e9cb29ee02eaa2627cfd15e6b0416143
Changeset: http://git.ntpsec.org/ntpsec/commit/?id=e3444d00e9cb29ee02eaa2627cfd15e6b0416143

Author:    Eric S. Raymond <esr at thyrsus.com>
Date:      Wed Sep 30 17:36:48 2015 -0400

Refactor configuration logic so bulky probes are not in the main line.

---

 pylib/configure.py | 26 +++-----------------------
 pylib/probes.py    | 31 +++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/pylib/configure.py b/pylib/configure.py
index 2f6aae4..cf84765 100644
--- a/pylib/configure.py
+++ b/pylib/configure.py
@@ -1,5 +1,6 @@
 from waflib.Configure import conf
 from util import msg, msg_setting
+from probes import *
 import sys, os
 
 
@@ -135,18 +136,7 @@ def cmd_configure(ctx):
 
 	ctx.define("OPENSSL_VERSION_TEXT", "#XXX: Fixme")
 
-	ctx.check_cc(
-		fragment="""
-#include <netinet/in.h>
-int main() {
-	struct ip_mreq ipmr;
-	ipmr.imr_interface.s_addr = 0;
-	return 0;
-}
-""",
-		define_name="MCAST",
-		msg = "Checking for multicast capability",
-		mandatory = False)
+	probe_multicast(ctx, "MCAST", "Checking for multicast capability")
 
 	ctx.define("TYPEOF_IP_MULTICAST_LOOP", "u_char", quote=False) #XXX: check for mcast type
 
@@ -256,18 +246,8 @@ int main() {
 			# Sanity check...
 			print "Compilation check failed but include exists!"
 
-	# XXX: This needs fixing.
 	for header in ["timepps.h", "sys/timepps.h"]:
-		ctx.check_cc(
-			fragment="""
-#include <inttypes.h>
-#include <%s>
-int main() { return 0; }
-""" % header,
-					define_name="HAVE_%s" % header.replace(".","_").replace("/","_").upper(),
-					msg = "Checking for %s" % header,
-					mandatory = False
-		)
+		probe_header_with_prerequisites(ctx, header, ["inttypes.h"])
 
 	if ctx.get_define("HAVE_TIMEPPS_H") or ctx.get_define("HAVE_SYS_TIMEPPS_H"):
 		ctx.define("HAVE_PPSAPI", 1)
diff --git a/pylib/probes.py b/pylib/probes.py
new file mode 100644
index 0000000..6e279b1
--- /dev/null
+++ b/pylib/probes.py
@@ -0,0 +1,31 @@
+"""
+This module exists to contin custom probe functions so they don't clutter
+up the logic in the main configure.py.
+"""
+
+def probe_header_with_prerequisites(ctx, header, prerequisites):
+	"Check that a header (with its prerequisites) compiles."
+	src = ""
+        for hdr in prerequisites + [header]:
+        	src += "#include <%s>\n" % hdr
+        src += "int main() { return 0; }\n"
+	ctx.check_cc(
+		fragment=src,
+		define_name="HAVE_%s" % header.replace(".","_").replace("/","_").upper(),
+		msg = "Checking for %s" % header,
+		mandatory = False)
+
+def probe_multicast(ctx, symbol, legend):
+	"Probe for IP multicast capability."
+	ctx.check_cc(
+		fragment="""
+#include <netinet/in.h>
+int main() {
+	struct ip_mreq ipmr;
+	ipmr.imr_interface.s_addr = 0;
+	return 0;
+}
+""",
+		define_name=symbol,
+		msg = legend,
+		mandatory = False)



More information about the vc mailing list