Packets/80211Bundle: Fix missing le16toh/le32toh on older libc
[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 @env.ConfTest()
73 def CheckExpression(context, name, expression, header="", language="C"):
74     import SCons.Conftest
75
76     lang, suffix, msg = SCons.Conftest._lang2suffix(language)
77     if msg:
78         context.Message("Cannot check for header file %s: \n" % header_name)
79         context.Result(msg)
80         return False
81
82     text = ("#include <assert.h>\n"
83             "%s\n"
84             "int main() {\n"
85             "%s;\n"
86             "return 0;\n"
87             "}\n") % (header, expression)
88
89     context.Message("Checking for valid %s expression %s... " % (lang, expression))
90     ret = context.TryLink(text, suffix)
91     context.Result(ret)
92     if ret:
93         import re
94         key = name.upper()
95         key = re.sub('[^A-Z0-9_]', '_', key)
96         context.sconf.Define("HAVE_%s" % key,
97                              1,
98                              "Define to 1 if the expression `%s' is valid on your system"
99                              % expression)
100
101     return ret
102
103 ###########################################################################
104
105 conf = env.Configure(clean=False, help=False, config_h="#/senf/autoconf.hh")
106
107 # Boost
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)
113
114 # Compiler support
115 res = conf.CheckTempBufferStrategy()
116
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")
125
126 # valgrind
127 res = conf.CheckValgrind() and conf.CheckValgrindWildcards(); \
128     conf.env.Replace(HAVE_VALGRIND = res)
129
130 env = conf.Finish()