minor fixes for clang++
[senf.git] / SConfigure
1 # -*- python -*-
2
3 import glob
4
5 Import('env')
6
7 ###########################################################################
8 # Custom configuration checks
9
10 @env.ConfTest()
11 def CheckSTLCopyN(context):
12     context.Message("Checking for 'copy_n' implementation... ")
13     versions = [ ('<algorithm>',     'std::copy_n',       'STD'),
14                  ('<ext/algorithm>', '__gnu_cxx::copy_n', 'GNUCXX') ]
15     for include, name, define in versions:
16         ret = context.TryCompile("#include %s\n"
17                                  "int main(int,char**) { int *a (NULL); int *b (NULL); %s(a,0,b); }\n"
18                                  % (include, name),
19                                  ".cc")
20         if ret:
21             context.Result(name)
22             context.sconf.Define("HAVE_%s_COPYN" % define,
23                                  1,
24                                  "Define one of "
25                                  + ", ".join(("HAVE_%s_COPYN" % elt[2] for elt in versions)))
26             return ret
27
28     context.Result(False)
29     return False
30
31
32 @env.ConfTest()
33 def CheckTempBufferStrategy(context):
34     context.Message("Checking for optimal temporary buffer strategy... ")
35
36     def check():
37       # locals
38       ret = context.TryCompile("void test(int n){int a[n];}",".cc")
39       if ret: return "locals"
40
41       # alloca
42       ret = context.TryCompile("#include <alloca.h>\n"
43                                "void test(int a){void *b(alloca(a));}",
44                                ".cc")
45       if ret: return "alloca"
46
47       # fallback: new
48       return "new"
49
50     ret = check()
51     context.Result(ret)
52     context.sconf.Define("SENF_BUFFER_USE_%s" % ret.upper(),
53                          1,
54                          "Define one of SENF_BUFFER_USE_LOCALS, SENF_BUFFER_USE_ALLOCA, "
55                          "SENF_BUFFER_USE_NEW")
56     return ret
57
58 @env.ConfTest()
59 def CheckValgrind(context):
60     context.Message( "Checking for valgrind... " )
61     ret = context.TryAction(['$VALGRIND --version >$TARGET'])
62     context.Result( ret[1].strip() or False )
63     return ret[0]
64
65 @env.ConfTest()
66 def CheckValgrindWildcards(context):
67     context.Message( "Checking whether valgrind supports '...' wildcards in suppressions... " )
68     ret = context.TryAction(['$VALGRIND --suppressions=$SOURCE /bin/true'],
69                             "{\n test_suppression\n Memcheck:Addr4\n ...\n fun:foo\n}\n",
70                             ".sup")
71     context.Result( ret[0] )
72     return ret[0]
73
74 ###########################################################################
75
76 conf = env.Configure(clean=False, help=False, config_h="#/senf/autoconf.hh")
77
78 # Boost
79 res = conf.CheckBoostVersion(fail=True)
80 res = conf.CheckBoostVariants()
81 res = conf.CheckCXXHeader("boost/spirit/include/classic.hpp")
82 res = conf.CheckCXXHeader("boost/bimap.hpp"); \
83     conf.env.Replace(NEED_BOOST_EXT = not res)
84
85 # Compiler support
86 res = conf.CheckTempBufferStrategy()
87
88 # Standard library stuff
89 res = conf.CheckCHeader("execinfo.h")
90 res = conf.FindCHeader("timerfd.h", [ 'sys', 'linux' ])
91 res = conf.CheckFunc("timerfd_create")
92 res = conf.CheckSymbolWithExpression(
93     "le16toh", "le16toh(0)", "#include <senf/Packets/80211Bundle/radiotap/platform.h>")
94 res = conf.CheckSymbolWithExpression(
95     "le32toh", "le32toh(0)", "#include <senf/Packets/80211Bundle/radiotap/platform.h>")
96 res = conf.CheckByteorder()
97 res = conf.CheckSTLCopyN(); \
98     conf.env.Fail(condition=not res, message="No 'copy_n' implementation found")
99
100 # valgrind
101 res = conf.CheckValgrind() and conf.CheckValgrindWildcards(); \
102     conf.env.Replace(HAVE_VALGRIND = res)
103
104 ###########################################################################
105
106 # run configure scripts from external modules 
107 Export('conf')
108
109 sconscripts = sorted(glob.glob("senf/Ext/*/SConfigure"))
110 if sconscripts:
111     SConscript(sconscripts)
112
113 ###########################################################################
114
115 env = conf.Finish()
116