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