5 ###########################################################################
6 # Custom configuration checks
9 def CheckSTLCopyN(context):
10 context.Message("Checking for 'copy_n' implementation... ")
11 versions = [ ('<algorithm>', 'std::copy_n', 'STD'),
12 ('<ext/algorithm>', '__gnu_cxx::copy_n', 'GNUCXX') ]
13 for include, name, define in versions:
14 ret = context.TryCompile("#include %s\n"
15 "int main(int,char**) { int *a,*b; %s(a,0,b); }\n"
20 context.sconf.Define("HAVE_%s_COPYN" % define,
23 + ", ".join(("HAVE_%s_COPYN" % elt[2] for elt in versions)))
31 def CheckTempBufferStrategy(context):
32 context.Message("Checking for optimal temporary buffer strategy... ")
36 ret = context.TryCompile("void test(int n){int a[n];}",".cc")
37 if ret: return "locals"
40 ret = context.TryCompile("#include <alloca.h>\n"
41 "void test(int a){void *b(alloca(a));}"
43 if ret: return "alloca"
50 context.sconf.Define("SENF_BUFFER_USE_%s" % ret.upper(),
52 "Define one of SENF_BUFFER_USE_LOCALS, SENF_BUFFER_USE_ALLOCA, "
53 "SENF_BUFFER_USE_NEW")
57 def CheckValgrind(context):
58 context.Message( "Checking for valgrind... " )
59 ret = context.TryAction(['$VALGRIND --version >$TARGET'])
60 context.Result( ret[1].strip() or False )
64 def CheckValgrindWildcards(context):
65 context.Message( "Checking whether valgrind supports '...' wildcards in suppressions... " )
66 ret = context.TryAction(['$VALGRIND --suppressions=$SOURCE /bin/true'],
67 "{\n test_suppression\n Memcheck:Addr4\n ...\n fun:foo\n}\n",
69 context.Result( ret[0] )
73 def CheckExpression(context, name, expression, header="", language="C"):
76 lang, suffix, msg = SCons.Conftest._lang2suffix(language)
78 context.Message("Cannot check for header file %s: \n" % header_name)
82 text = ("#include <assert.h>\n"
87 "}\n") % (header, expression)
89 context.Message("Checking for valid %s expression %s... " % (lang, expression))
90 ret = context.TryLink(text, suffix)
95 key = re.sub('[^A-Z0-9_]', '_', key)
96 context.sconf.Define("HAVE_%s" % key,
98 "Define to 1 if the expression `%s' is valid on your system"
103 ###########################################################################
105 conf = env.Configure(clean=False, help=False, config_h="#/senf/autoconf.hh")
108 res = conf.CheckBoostVersion(fail=True)
109 res = conf.CheckBoostVariants()
110 res = conf.CheckCXXHeader("boost/spirit/include/classic.hpp")
111 res = conf.CheckCXXHeader("boost/bimap.hpp"); \
112 conf.env.Replace(NEED_BOOST_EXT = not res)
115 res = conf.CheckTempBufferStrategy()
117 # Standard library stuff
118 res = conf.CheckFunc("timerfd_create")
119 res = conf.CheckExpression("le16toh", "le16toh(0)",
120 "#include <senf/Packets/80211Bundle/radiotap/platform.h>")
121 res = conf.CheckExpression("le32toh", "le32toh(0)",
122 "#include <senf/Packets/80211Bundle/radiotap/platform.h>")
123 res = conf.CheckSTLCopyN(); \
124 conf.env.Fail(condition=not res, message="No 'copy_n' implementation found")
127 res = conf.CheckValgrind() and conf.CheckValgrindWildcards(); \
128 conf.env.Replace(HAVE_VALGRIND = res)