Suuports clang compiler
[anna.git] / SConstruct
1 import os
2
3 # Basic paths
4 prefix = ARGUMENTS.get ('prefix', "/usr/local")
5 usr_local_include = os.path.join (prefix, "include")
6 usr_local_lib = os.path.join (prefix, "lib")
7 usr_local_bin = os.path.join (prefix, "bin")
8 opt_bin = "/opt/bin"
9 current_directory = Dir ('.').abspath
10
11 # Anna targets
12 target_usr_local_include = os.path.join (usr_local_include, "anna")
13 target_usr_local_lib = os.path.join (usr_local_lib, "anna")
14 #target_usr_local_bin = usr_local_bin
15 target_opt_bin = os.path.join (opt_bin, "anna")
16
17 # Versioning
18 release = ARGUMENTS.get ('release', 0)
19
20 # Environment
21
22 # Using clang, uncomment following:
23 env = Environment(CXX = 'clang++')
24 env.Append (CCFLAGS = '-DIS_CLANG')
25 env.Append (CXXFLAGS = '-Wno-parentheses-equality')
26
27 # Using c++, uncomment following:
28 #env = Environment ()
29
30 #oracle_includes = os.environ["ORACLE_HOME"] + "/include"
31 oracle_includes = "/usr/lib/oracle/12.1/client64/include"
32         
33 # Headers
34 source_include = os.path.join (current_directory, "include")
35 usr_include = [
36   #"/usr/include/oracle/12.1/client64",
37   oracle_includes,
38   "/usr/include/libxml2",
39   #"/usr/include/boost",
40   #"/usr/include/mysql", 
41   #"/usr/include/openssl", 
42 ]
43
44 # Libraries
45 libraries = []
46
47 # Environment
48 #env = Environment ()
49 # CPPPATH will be relative to src/<target>
50 env.Append (CPPPATH = [source_include, usr_local_include, usr_include ])
51 #env.Append (CCFLAGS = '-std=c++0x')
52 # C++11 support:
53 env.Append (CXXFLAGS = '-std=c++11')
54
55 env.Append (LIBS = [''])
56 # scons -Q release=1
57 if int(release):
58   variant='release'
59   env.Append (CCFLAGS = '-O3')
60   env.Append (VARIANT = variant)
61 else:
62   variant='debug'
63   env.Append (CCFLAGS = '-g -O0')
64   env.Append (LIBPATH = os.path.join (current_directory, variant))
65   env.Append (VARIANT = variant)
66
67 variant_dir=variant
68 source = os.path.join (current_directory, "source")
69 sources = Glob(source + '/*')
70 for source in sources:
71   ss = str (source)
72   ss += '/SConstruct'
73   compile_library = SConscript (ss, exports='env')
74   libraries.extend (compile_library)
75
76 env.Default (libraries)
77
78 #
79 ## Run 'scons example' to compile examples
80 #
81 example_list = []
82 example = os.path.join (current_directory, "example")
83 examples = Glob(example + '/*/*')
84 for example in examples:
85   ss = str (example)
86   bn_ss = os.path.basename(ss)
87   noExtension = (len(bn_ss.split('.')) == 1)
88   if noExtension:
89     ss += '/SConstruct'
90     example_program = SConscript (ss, exports='env')
91     example_list.extend (example_program)
92     print example_program [0]
93
94 #Depends (example_list, compile_library)
95    
96 # In order to remove examples objects with 'scons -c' we need to default them at built ('scons') procedure:
97 env.Default (example_list)
98 #env.Alias ('example', example_list)
99
100
101 #
102 # Run 'scons test' to compile unit-tests
103 #
104 test_unit_list = []
105 run_tests = []
106
107 test = os.path.join (current_directory, "test")
108 tests = Glob(test + '/*')
109 for test in tests:
110   ss = str (test)
111   ss += '/SConstruct'
112   test_unit_program = SConscript (ss, exports='env')
113   test_unit_list.extend (test_unit_program)
114   print test_unit_program [0]
115   test_unit = Builder (action = '%s --report_level=short > $TARGET' % test_unit_program [0])
116   env ['BUILDERS']['RunTestUnit'] = test_unit
117   test_unit_result = env.RunTestUnit ('%s.output' % test_unit_program [0], 'SConstruct')
118   run_tests.extend (test_unit_result)
119   Depends (test_unit_result, test_unit_program)
120
121 env.Alias ('test', run_tests)
122 # In order to remove test objects with 'scons -c' we need to default them at built ('scons') procedure:
123 env.Default (test_unit_list)
124
125 #
126 # Run 'scons doc' to generate documentation
127 #
128 # Doxygen Builder does not work properly at the moment. We will use an alias/action 
129 #env = Environment(tools = ["default", "doxygen"], toolpath = './docs/doxygen')
130 #env.Doxygen("./docs/doxygen/Doxyfile")
131 # Finally, is enough to execute doxygen which will solve dependences and work for
132 #  only modified files:
133 env.Alias('doc', env.Command('doc.dummy', [], 'cd docs/doxygen; doxygen'))
134
135 #
136 # Run 'sudo scons install' to install the suite:
137 #
138 #       'sudo scons install-include' for only headers
139 #       'sudo scons install-lib'     for only libraries
140 #       'sudo scons install-bin'     for only binaries
141 #
142 # Run 'sudo scons uninstall' to uninstall the suite
143 #
144 # See http://www.scons.org/wiki/InstallTargets and http://www.scons.org/doc/production/HTML/scons-user/c2938.html
145 install_include = env.Install (target_usr_local_include, Glob("include/anna/*"))
146 install_lib =     env.Install (target_usr_local_lib, Glob("source/*/" + variant + "/*.a"))
147 install_example = env.Install (target_opt_bin, Glob("example/*/*/" + variant + "/example_*"))
148 #Default ('install')
149 Depends (install_include, test_unit_result)
150 Depends (install_lib, test_unit_result)
151 Depends (install_example, test_unit_result)
152
153 iil = env.Alias('install-include-and-lib', [target_usr_local_include, target_usr_local_lib])
154 iex = env.Alias('install-example', target_opt_bin)
155 env.Alias('install', [iil, iex])
156
157 env.Command ("uninstall", None, [ Delete(target_usr_local_include), Delete(target_usr_local_lib), Delete(target_opt_bin) ])
158