Dynamic lib selection and deployment
[anna.git] / SConstruct
1 import os
2 import sys, select
3
4 # Basic paths
5 prefix = ARGUMENTS.get ('prefix', "/usr/local")
6 usr_local_include = os.path.join (prefix, "include")
7 usr_local_lib = os.path.join (prefix, "lib")
8 usr_local_bin = os.path.join (prefix, "bin")
9 opt_bin = "/opt/bin"
10 current_directory = Dir ('.').abspath
11
12 # Anna targets
13 target_usr_local_include = os.path.join (usr_local_include, "anna")
14 target_usr_local_lib = os.path.join (usr_local_lib, "anna")
15 #target_usr_local_bin = usr_local_bin
16 target_opt_bin = os.path.join (opt_bin, "anna")
17
18 # Versioning
19 release = ARGUMENTS.get ('release', 0)
20
21 # Environment
22 env = None
23 rc = os.system("clang++ --version >/dev/null 2>/dev/null")
24 if rc == 0: 
25   print "\nDetected clang++ installed in the system"
26   print "\nSelect compiler:\n  1. g++\n  2. clang++"
27   #option = raw_input("\nInput option [1]: ") or "1"
28   # Read with timeout:
29   print "\nInput option [1]: "
30   option = 1
31   i, o, e = select.select( [sys.stdin], [], [], 60 )
32   if (i): option = sys.stdin.readline().strip()
33   else: print "expired! using default ..."
34   if option == "2":
35     env = Environment(CXX = 'clang++')
36     env.Append (CCFLAGS = '-DIS_CLANG')
37     env.Append (CXXFLAGS = '-Wno-parentheses-equality')
38   else:
39     env = Environment()
40 else:
41   env = Environment()
42
43 #oracle_includes = os.environ["ORACLE_HOME"] + "/include"
44 oracle_includes = "/usr/lib/oracle/12.1/client64/include"
45         
46 # Headers
47 source_include = os.path.join (current_directory, "include")
48 usr_include = [
49   #"/usr/include/oracle/12.1/client64",
50   oracle_includes,
51   "/usr/include/libxml2",
52   #"/usr/include/boost",
53   #"/usr/include/mysql", 
54   #"/usr/include/openssl", 
55 ]
56
57 # Libraries
58 libraries = []
59
60 # Environment
61 #env = Environment ()
62 # CPPPATH will be relative to src/<target>
63 env.Append (CPPPATH = [source_include, usr_local_include, usr_include ])
64 #env.Append (CCFLAGS = '-std=c++0x')
65 # C++11 support:
66 env.Append (CXXFLAGS = '-std=c++11')
67
68 env.Append (LIBS = [''])
69 # scons -Q release=1
70 if int(release):
71   variant='release'
72   env.Append (CCFLAGS = '-O3')
73   env.Append (VARIANT = variant)
74 else:
75   variant='debug'
76   env.Append (CCFLAGS = '-g -O0')
77   env.Append (LIBPATH = os.path.join (current_directory, variant))
78   env.Append (VARIANT = variant)
79
80 variant_dir=variant
81 source = os.path.join (current_directory, "source")
82 sources = Glob(source + '/*')
83 for source in sources:
84   ss = str (source)
85   ss += '/SConstruct'
86   compile_library = SConscript (ss, exports='env')
87   libraries.extend (compile_library)
88
89 env.Default (libraries)
90
91 #
92 ## Run 'scons dynamic' to compile dynamic libraries
93 #
94 dynamic_list = []
95 dynamic = os.path.join (current_directory, "dynamic")
96 # Find SConstruct files:
97 dynamics=[os.path.join(r,f) for r,d,fs in os.walk(dynamic) for f in fs if f.endswith('SConstruct')]
98 for dynamic in dynamics:
99   ss = str (dynamic)
100   bn_ss = os.path.basename(ss)
101   if (bn_ss == "SConstruct"):
102     dynamic_program = SConscript (ss, exports='env')
103     if dynamic_program:
104       dynamic_list.extend (dynamic_program)
105       print dynamic_program [0]
106
107 #Depends (dynamic_list, compile_library)
108    
109 # In order to remove dynamics objects with 'scons -c' we need to default them at built ('scons') procedure:
110 env.Default (dynamic_list)
111 #env.Alias ('dynamic', dynamic_list)
112
113
114 #
115 ## Run 'scons example' to compile examples
116 #
117 example_list = []
118 example = os.path.join (current_directory, "example")
119 examples = Glob(example + '/*/*')
120 for example in examples:
121   ss = str (example)
122   bn_ss = os.path.basename(ss)
123   noExtension = (len(bn_ss.split('.')) == 1)
124   if noExtension:
125     ss += '/SConstruct'
126     example_program = SConscript (ss, exports='env')
127     example_list.extend (example_program)
128     print example_program [0]
129
130 #Depends (example_list, compile_library)
131    
132 # In order to remove examples objects with 'scons -c' we need to default them at built ('scons') procedure:
133 env.Default (example_list)
134 #env.Alias ('example', example_list)
135
136 #
137 # Run 'scons test' to compile unit-tests
138 #
139 test_unit_result = None
140 test_unit_list = []
141 run_tests = []
142
143 test = os.path.join (current_directory, "test")
144 tests = Glob(test + '/*')
145 for test in tests:
146   ss = str (test)
147   ss += '/SConstruct'
148   test_unit_program = SConscript (ss, exports='env')
149   test_unit_list.extend (test_unit_program)
150   print test_unit_program [0]
151   test_unit = Builder (action = '%s --report_level=short > $TARGET' % test_unit_program [0])
152   env ['BUILDERS']['RunTestUnit'] = test_unit
153   test_unit_result = env.RunTestUnit ('%s.output' % test_unit_program [0], 'SConstruct')
154   run_tests.extend (test_unit_result)
155   Depends (test_unit_result, test_unit_program)
156
157 env.Alias ('test', run_tests)
158 # In order to remove test objects with 'scons -c' we need to default them at built ('scons') procedure:
159 env.Default (test_unit_list)
160
161 #
162 # Run 'scons doc' to generate documentation
163 #
164 # Doxygen Builder does not work properly at the moment. We will use an alias/action 
165 #env = Environment(tools = ["default", "doxygen"], toolpath = './docs/doxygen')
166 #env.Doxygen("./docs/doxygen/Doxyfile")
167 # Finally, is enough to execute doxygen which will solve dependences and work for
168 #  only modified files:
169 env.Alias('doc', env.Command('doc.dummy', [], 'cd docs/doxygen; doxygen'))
170
171 # Installation aliases:
172 #
173 #       'sudo scons install-include'         for only headers
174 #       'sudo scons install-lib'             for only libraries
175 #       'sudo scons install-include-and-lib' for headers & libraries
176 #       'sudo scons install-example'         for only example binaries/resources
177 #       'sudo scons install'                 to install the whole suite
178 #
179 # Run 'sudo scons uninstall' to uninstall the suite
180 #
181 # See http://www.scons.org/wiki/InstallTargets and http://www.scons.org/doc/production/HTML/scons-user/c2938.html
182 install_include = env.Install (target_usr_local_include, Glob("include/anna/*"))
183 install_lib =     env.Install (target_usr_local_lib, Glob("source/*/" + variant + "/*.a"))
184 install_dynlib =  env.Install (target_usr_local_lib, Glob("dynamic/launcher/default/" + variant + "/*.so"))
185 install_example = env.Install (target_opt_bin, Glob("example/*/*/" + variant + "/example_*"))
186 postinstall_example = env.Command('./example/postinstall.out', None, './example/postinstall.sh')
187
188 #Default ('install')
189 if test_unit_result:
190   Depends (install_include, test_unit_result)
191   Depends (install_lib, test_unit_result)
192   Depends (install_dynlib, test_unit_result)
193   Depends (install_example, test_unit_result)
194
195 ii  = env.Alias('install-include', [target_usr_local_include])
196 il  = env.Alias('install-lib',     [target_usr_local_lib])
197 idl = env.Alias('install-dynlib',  [target_usr_local_lib])
198 iil = env.Alias('install-include-and-lib', [target_usr_local_include, target_usr_local_lib])
199 iex = env.Alias('install-example', [target_opt_bin, postinstall_example])
200 env.Alias('install', [iil, iex])
201
202 env.Command ("uninstall", None, [ Delete(target_usr_local_include), Delete(target_usr_local_lib), Delete(target_opt_bin) ])
203