Reorganize SCons build system
[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, 
75                      help=False, 
76                      config_h="#/senf/autoconf.hh")
77
78 # Boost
79 res = conf.CheckBoostVersion()
80 if not res : conf.Fail("Boost includes not found")
81
82 res = conf.CheckBoostVariants()
83
84 res = conf.CheckCXXHeader("boost/bimap.hpp")
85 conf.env.Replace(NEED_BOOST_EXT = not res)
86
87 res = conf.CheckCXXHeader("boost/spirit/include/classic.hpp")
88     
89 # Compiler support
90 res = conf.CheckTempBufferStrategy()
91
92 # Standard library stuff
93 res = conf.CheckSTLCopyN()
94 if not res : conf.Fail("No 'copy_n' implementation found")
95
96 res = conf.CheckFunc("timerfd_create")
97
98 # valgrind
99 res = conf.CheckValgrind() \
100   and conf.CheckValgrindWildcards()
101 conf.env.Replace(HAVE_VALGRIND = res)
102
103 env = conf.Finish()