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