1 # Copyright the NTPsec project contributors
3 # SPDX-License-Identifier: BSD-2-Clause
5 from waflib
.Configure
import conf
6 from waflib
import Errors
12 printf("%%lu", sizeof(%s));
18 def check_sizeof_host(ctx
, header
, sizeof
, mandatory
=True):
19 sizeof_ns
= sizeof
.replace(" ", "_")
20 name
= "NTP_SIZEOF_%s" % sizeof_ns
.upper()
24 ctx
.start_msg("Checking sizeof %s (%s)" % (sizeof
, header
))
25 header_snippet
= "#include <%s>" % header
27 ctx
.start_msg("Checking sizeof %s" % (sizeof
))
30 fragment
=SIZE_FRAG
% (header_snippet
, sizeof
),
36 comment
="Size of %s from <%s>" % (sizeof
, header
)
38 ctx
.end_msg(ctx
.get_define(name
))
41 # Cross compile check. Much slower so we do not run it all the time.
47 static int test_array [1 - 2 * !(((long int) (sizeof (%s))) <= %d)];
54 def check_sizeof_cross(ctx
, header
, sizeof
, mandatory
=True):
55 sizeof_ns
= sizeof
.replace(" ", "_")
56 name
= "NTP_SIZEOF_%s" % sizeof_ns
.upper()
60 ctx
.start_msg("Checking sizeof %s (%s)" % (sizeof
, header
))
61 header_snippet
= "#include <%s>" % header
63 ctx
.start_msg("Checking sizeof %s" % (sizeof
))
65 for size
in range(2, 99):
69 fragment
=SIZE_FRAG_CROSS
% (header_snippet
, sizeof
, size
),
74 ctx
.define(name
, size
, comment
="Size of %s from <%s>"
76 ctx
.end_msg(ctx
.get_define(name
))
78 except Errors
.ConfigurationError
:
81 raise # never reached.
85 def check_sizeof(*kwargs
):
86 if kwargs
[0].env
.ENABLE_CROSS
:
87 check_sizeof_cross(*kwargs
)
89 check_sizeof_host(*kwargs
)
92 # timex slots are documented as long
93 # #if (__TIMESIZE == 64 && __WORDSIZE == 32)
94 # they turn into long long
95 # This fails to build in the normal case.
96 # So we set NTP_TIMEX_LONG_LONG to 0
98 #include <sys/time.h> /* for NetBSD */
99 #include <sys/timex.h>
103 long long *foo = &dummy.jitter;
104 *foo = 1; /* supress unused warning */
105 if (*foo) printf("1");
110 def check_timex(ctx
):
111 name
= "NTP_TIMEX_LONG_LONG"
112 ctx
.start_msg("Checking for long long in struct timex" )
115 fragment
=SIZE_FRAG_TIMEX
,
117 execute
=not ctx
.env
.ENABLE_CROSS
,
121 comment
="struct timex has long long"
123 ctx
.end_msg(ctx
.get_define(name
))