[Git][NTPsec/ntpsec][master] Better support for cross compiling
Amar Takhar
gitlab at mg.gitlab.com
Thu Jan 14 18:28:06 UTC 2016
Amar Takhar pushed to branch master at NTPsec / ntpsec
Commits:
b0de1316 by Amar Takhar at 2016-01-14T13:26:52-05:00
Better support for cross compiling
--enable-cross should do the right thing for sizeof(), header, library and run
tests for now.
- - - - -
7 changed files:
- pylib/check_cap.py
- pylib/check_libevent2.py
- pylib/check_mdns.py
- pylib/check_sizeof.py
- pylib/configure.py
- + pylib/tool.py
- pylib/waf.py
Changes:
=====================================
pylib/check_cap.py
=====================================
--- a/pylib/check_cap.py
+++ b/pylib/check_cap.py
@@ -1,3 +1,5 @@
+from tool import check_sanity
+
PCAP_FRAG = """
# include <sys/capability.h>
@@ -12,13 +14,31 @@ int main(void) {
}
"""
+def check_cap_header(ctx):
+ ctx.check_cc(header_name="sys/capability.h", mandatory=False)
+ ctx.check_cc(lib="cap", mandatory=False)
+
+ if ctx.get_define("HAVE_SYS_CAPABILITY_H") and ctx.get_define("HAVE_SYS_PRCTL_H") and ctx.env.LIB_LIBCAP:
+ ctx.env.LIBCAP_HEADER = True
+
+
+def check_cap_run(ctx):
+ if ctx.env.ENABLE_CROSS: # XXX Remove when variant builds exist
+ if ctx.env.LIBCAP_HEADER:
+ ctx.define("HAVE_CAPABILITY", 1)
+ return
-def check_cap(ctx):
ctx.check_cc(
fragment = PCAP_FRAG,
define_name = "HAVE_CAPABILITY",
features = "c",
- use = "CAP",
+ use = "CAP",
msg = "Checking if libcap works",
mandatory = False
)
+
+ check_sanity(ctx, ctx.env.LIBCAP_HEADER, "CAPABILITY")
+
+
+ if ctx.get_define("HAVE_CAPABILITY"):
+ ctx.define("HAVE_LINUX_CAPABILITY", 1)
=====================================
pylib/check_libevent2.py
=====================================
--- a/pylib/check_libevent2.py
+++ b/pylib/check_libevent2.py
@@ -1,4 +1,6 @@
from waflib.Logs import pprint
+from tool import check_sanity
+
LIBEVENT2_FRAG = """
#include <event2/thread.h>
#include <event2/event.h>
@@ -13,19 +15,21 @@ int main(void) {
"""
-def check_libevent2(ctx):
- check_libevent2.false = False
-
- def check(**kwargs):
- if not ctx.check_cc(**kwargs):
- check_libevent2.false = True
-
+def check_libevent2_header(ctx):
+ ctx.check(header_name="event2/event.h", includes=ctx.env.PLATFORM_INCLUDES, mandatory = False)
+ ctx.check(header_name="event2/thread.h", includes=ctx.env.PLATFORM_INCLUDES, mandatory = False)
+ ctx.check(feature="c cshlib", lib="event_core", libpath=ctx.env.PLATFORM_LIBPATH, uselib_store="LIBEVENT_CORE", mandatory = False)
+ ctx.check(feature="c cshlib", lib="event_pthreads", libpath=ctx.env.PLATFORM_LIBPATH, uselib_store="LIBEVENT_PTHREADS", use="LIBEVENT_CORE", mandatory = False)
- check(header_name="event2/event.h", includes=ctx.env.PLATFORM_INCLUDES, mandatory = False)
- check(header_name="event2/thread.h", includes=ctx.env.PLATFORM_INCLUDES, mandatory = False)
- check(feature="c cshlib", lib="event_core", libpath=ctx.env.PLATFORM_LIBPATH, uselib_store="LIBEVENT_CORE", mandatory = False)
- check(feature="c cshlib", lib="event_pthreads", libpath=ctx.env.PLATFORM_LIBPATH, uselib_store="LIBEVENT_PTHREADS", use="LIBEVENT_CORE", mandatory = False)
+ if ctx.get_define("HAVE_EVENT2_THREAD_H") and ctx.get_define("HAVE_EVENT2_EVENT_H") and ctx.env.LIB_LIBEVENT_PTHREADS and ctx.env.LIB_LIBEVENT_CORE:
+ ctx.env.EVENT2_HEADER = True
+def check_libevent2_run(ctx):
+ if ctx.env.ENABLE_CROSS:
+ if ctx.env.EVENT2_HEADER: # XXX Remove when variant builds exist
+ ctx.define("HAVE_LIBEVENT2", 1)
+ ctx.env.LIBEVENT2_ENABLE = True
+ return
ctx.check(
fragment = LIBEVENT2_FRAG,
@@ -38,13 +42,14 @@ def check_libevent2(ctx):
mandatory = False
)
+ check_sanity(ctx, ctx.env.EVENT2_HEADER, "libevent2")
- if check_libevent2.false:
+ if not ctx.get_define("HAVE_LIBEVENT2"):
print("")
pprint("RED", "Warning libevent2 does not work")
pprint("RED", "This means ntpdig will not be built")
pprint("RED", "While not necessary you will lose 'ntpdate' functionality.")
print("")
else:
- ctx.env.LIBEVENT2_ENABLE=True
+ ctx.env.LIBEVENT2_ENABLE = True
ctx.define("HAVE_LIBEVENT2", 1)
=====================================
pylib/check_mdns.py
=====================================
--- a/pylib/check_mdns.py
+++ b/pylib/check_mdns.py
@@ -8,10 +8,20 @@ int main(void) {
}
"""
-def check_mdns(ctx):
+def check_mdns_header(ctx):
ctx.check_cc(lib="dns_sd", libpath=ctx.env.PLATFORM_LIBPATH, mandatory=False)
ctx.check_cc(header_name="dns_sd.h", includes=ctx.env.PLATFORM_INCLUDES, uselib_store="DNS_SD_INCLUDES", mandatory=False)
+ if ctx.get_define("HAVE_DNS_SD_H") and ctx.env.LIB_LIBDNS_SD:
+ ctx.env.DNS_SD_HEADER = True
+
+
+def check_mdns_run(ctx):
+ if ctx.env.ENABLE_CROSS: # XXX Remove when variant builds exist
+ if ctx.env.DNS_SD_HEADER:
+ ctx.define("HAVE_MDNS", 1)
+ return
+
ctx.check_cc(
fragment = MDNS_FRAG,
define_name = "HAVE_MDNS",
@@ -24,6 +34,5 @@ def check_mdns(ctx):
mandatory = False
)
-
if ctx.get_define("HAVE_MDNS"):
ctx.define("ENABLE_MDNS_REGISTRATION", 1)
=====================================
pylib/check_sizeof.py
=====================================
--- a/pylib/check_sizeof.py
+++ b/pylib/check_sizeof.py
@@ -1,4 +1,5 @@
from waflib.Configure import conf
+from waflib import Errors
SIZE_FRAG = """
%s
@@ -9,8 +10,7 @@ int main () {
}
"""
- at conf
-def check_sizeof(ctx, header, sizeof, mandatory=True):
+def check_sizeof_host(ctx, header, sizeof, mandatory=True):
sizeof_ns = sizeof.replace(" ", "_")
name = "SIZEOF_%s" % sizeof_ns.upper()
@@ -30,3 +30,52 @@ def check_sizeof(ctx, header, sizeof, mandatory=True):
mandatory = mandatory,
)
ctx.end_msg(ctx.get_define(name))
+
+
+# Cross compile check. Much slower so we do not run it all the time.
+
+SIZE_FRAG_CROSS = """
+%s
+#include <sys/stat.h>
+int main () {
+ static int test_array [1 - 2 * !(((long int) (sizeof (%s))) <= %d)];
+ test_array [0] = 0;
+ return test_array[0];
+}
+"""
+
+def check_sizeof_cross(ctx, header, sizeof, mandatory=True):
+ sizeof_ns = sizeof.replace(" ", "_")
+ name = "SIZEOF_%s" % sizeof_ns.upper()
+
+ header_snippet = ""
+ if header:
+ ctx.start_msg("Checking sizeof %s (%s)" % (sizeof, header))
+ header_snippet = "#include <%s>" % header
+ else:
+ ctx.start_msg("Checking sizeof %s" % (sizeof))
+
+
+ for size in range(2,13):
+
+ try:
+ ctx.check_cc(
+ fragment = SIZE_FRAG_CROSS % (header_snippet, sizeof, size),
+ execute = False,
+ mandatory = mandatory,
+ )
+ ctx.define(name, size)
+ ctx.end_msg(ctx.get_define(name))
+ return
+ except Errors.ConfigurationError:
+ pass
+
+ raise # never reached.
+
+ at conf
+def check_sizeof(*kwargs):
+ if kwargs[0].env.ENABLE_CROSS:
+ return check_sizeof_cross(*kwargs)
+ else:
+ return check_sizeof_host(*kwargs)
+
=====================================
pylib/configure.py
=====================================
--- a/pylib/configure.py
+++ b/pylib/configure.py
@@ -190,9 +190,8 @@ def cmd_configure(ctx):
#HGM (None, "signed char"),
]
- if not ctx.env.ENABLE_CROSS:
- for header, sizeof in sorted(sizeofs):
- ctx.check_sizeof(header, sizeof)
+ for header, sizeof in sorted(sizeofs):
+ ctx.check_sizeof(header, sizeof)
# The protocol major number
ctx.define("NTP_API", 4)
@@ -336,19 +335,6 @@ def cmd_configure(ctx):
#HGM Can delete pylib/check_timepps.py
ctx.define("HAVE_PPSAPI", 1)
- # Check for libevent and whether it is working.
- from pylib.check_libevent2 import check_libevent2
- check_libevent2(ctx)
-
-
- # Check for Linux capability.
- ctx.check_cc(header_name="sys/capability.h", mandatory=False)
- ctx.check_cc(lib="cap", mandatory=False)
- if ctx.env.LIB_CAP:
- from check_cap import check_cap
- check_cap(ctx)
- if ctx.get_define("HAVE_CAPABILITY") and ctx.get_define("HAVE_SYS_CAPABILITY_H") and ctx.get_define("HAVE_SYS_PRCTL_H"):
- ctx.define("HAVE_LINUX_CAPABILITY", 1)
# Check for Solaris capabilities
if ctx.get_define("HAVE_PRIV_H") and sys.platform == "Solaris":
@@ -405,10 +391,6 @@ def cmd_configure(ctx):
if not ctx.options.disable_dns_retry:
ctx.define("ENABLE_DNS_RETRY", 1)
- if not ctx.options.disable_mdns_registration:
- from check_mdns import check_mdns
- check_mdns(ctx)
-
# There is an ENABLE_AUTOKEY as well, but as that feature
# is not working and likely to be replaced it's not exposed
@@ -502,6 +484,32 @@ def cmd_configure(ctx):
ctx.define("ISC_PLATFORM_USETHREADS", 1)
ctx.define("HAVE_IFLIST_SYSCTL", 1)
+
+
+ # Header checks
+ from pylib.check_cap import check_cap_header
+ check_cap_header(ctx)
+
+ from pylib.check_libevent2 import check_libevent2_header
+ check_libevent2_header(ctx)
+
+ if not ctx.options.disable_mdns_registration:
+ from pylib.check_mdns import check_mdns_header
+ check_mdns_header(ctx)
+
+
+ # Run checks
+ from pylib.check_cap import check_cap_run
+ check_cap_run(ctx)
+
+ from pylib.check_libevent2 import check_libevent2_run
+ check_libevent2_run(ctx)
+
+ if not ctx.options.disable_mdns_registration:
+ from pylib.check_mdns import check_mdns_run
+ check_mdns_run(ctx)
+
+
ctx.start_msg("Writing configuration header:")
ctx.write_config_header("config.h")
ctx.end_msg("config.h", "PINK")
=====================================
pylib/tool.py
=====================================
--- /dev/null
+++ b/pylib/tool.py
@@ -0,0 +1,11 @@
+from waflib.Logs import pprint
+
+def check_sanity(ctx, cond, lib):
+ define = "HAVE_%s" % lib.upper()
+
+ if cond and (not ctx.get_define(define)):
+ pprint("RED", "Warning %s headers detected, binaries do not build/run")
+ elif (not cond) and ctx.get_define(define):
+ pprint("RED", "Warning %s headers not detected, binaries build/run")
+
+
=====================================
pylib/waf.py
=====================================
--- a/pylib/waf.py
+++ b/pylib/waf.py
@@ -79,3 +79,4 @@ def ntp_test(ctx, **kwargs):
args += tg.test_args
tg.ut_exec = args
+
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/b0de1316199d254d65b5d1b09e51e882c8b4016d
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160114/b4419f77/attachment.html>
More information about the vc
mailing list