Packets/80211Bundle: Fix byteorder issues for radiotap parser
[senf.git] / SConfigure
1 # -*- python -*-
2
3 Import('env')
4
5 ###########################################################################
6 # Custom configuration checks
7
8 @env.ConfTest()
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"
16                                  % (include, name),
17                                  ".cc")
18         if ret:
19             context.Result(name)
20             context.sconf.Define("HAVE_%s_COPYN" % define,
21                                  1,
22                                  "Define one of "
23                                  + ", ".join(("HAVE_%s_COPYN" % elt[2] for elt in versions)))
24             return ret
25
26     context.Result(False)
27     return False
28
29
30 @env.ConfTest()
31 def CheckTempBufferStrategy(context):
32     context.Message("Checking for optimal temporary buffer strategy... ")
33
34     def check():
35       # locals
36       ret = context.TryCompile("void test(int n){int a[n];}",".cc")
37       if ret: return "locals"
38
39       # alloca
40       ret = context.TryCompile("#include <alloca.h>\n"
41                                "void test(int a){void *b(alloca(a));}"
42                                ".cc")
43       if ret: return "alloca"
44
45       # fallback: new
46       return "new"
47
48     ret = check()
49     context.Result(ret)
50     context.sconf.Define("SENF_BUFFER_USE_%s" % ret.upper(),
51                          1,
52                          "Define one of SENF_BUFFER_USE_LOCALS, SENF_BUFFER_USE_ALLOCA, "
53                          "SENF_BUFFER_USE_NEW")
54     return ret
55
56 @env.ConfTest()
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 )
61     return ret[0]
62
63 @env.ConfTest()
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",
68                             ".sup")
69     context.Result( ret[0] )
70     return ret[0]
71
72 ###########################################################################
73
74 conf = env.Configure(clean=False, help=False, config_h="#/senf/autoconf.hh")
75
76 # Boost
77 res = conf.CheckBoostVersion(fail=True)
78 res = conf.CheckBoostVariants()
79 res = conf.CheckCXXHeader("boost/spirit/include/classic.hpp")
80 res = conf.CheckCXXHeader("boost/bimap.hpp"); \
81     conf.env.Replace(NEED_BOOST_EXT = not res)
82
83 # Compiler support
84 res = conf.CheckTempBufferStrategy()
85
86 # Standard library stuff
87 res = conf.CheckFunc("timerfd_create")
88 res = conf.CheckSymbolWithExpression(
89     "le16toh", "le16toh(0)", "#include <senf/Packets/80211Bundle/radiotap/platform.h>")
90 res = conf.CheckSymbolWithExpression(
91     "le32toh", "le32toh(0)", "#include <senf/Packets/80211Bundle/radiotap/platform.h>")
92 res = conf.CheckByteorder()
93 res = conf.CheckSTLCopyN(); \
94     conf.env.Fail(condition=not res, message="No 'copy_n' implementation found")
95
96 # valgrind
97 res = conf.CheckValgrind() and conf.CheckValgrindWildcards(); \
98     conf.env.Replace(HAVE_VALGRIND = res)
99
100 env = conf.Finish()