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