Statistics
| Branch: | Tag: | Revision:

one / SConstruct @ ae53d437

History | View | Annotate | Download (7.46 KB)

1
# -------------------------------------------------------------------------- #
2
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)             #
3
#                                                                            #
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
5
# not use this file except in compliance with the License. You may obtain    #
6
# a copy of the License at                                                   #
7
#                                                                            #
8
# http://www.apache.org/licenses/LICENSE-2.0                                 #
9
#                                                                            #
10
# Unless required by applicable law or agreed to in writing, software        #
11
# distributed under the License is distributed on an "AS IS" BASIS,          #
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
13
# See the License for the specific language governing permissions and        #
14
# limitations under the License.                                             #
15
#--------------------------------------------------------------------------- #
16

    
17
import os
18
import sys
19
import shutil
20
sys.path.append("./share/scons")
21
from lex_bison import *
22

    
23
# This is the absolute path where the project is located
24
cwd=os.getcwd()
25

    
26
# Environment that will be applied to each scons child
27
main_env=Environment()
28
main_env['ENV']['PATH']=os.environ['PATH']
29

    
30
# snippet borrowed from http://dev.gentoo.org/~vapier/scons-blows.txt
31
# makes scons aware of build related environment variables
32
if os.environ.has_key('CC'):
33
    main_env['CC'] = os.environ['CC']
34
if os.environ.has_key('CFLAGS'):
35
    main_env['CCFLAGS'] += SCons.Util.CLVar(os.environ['CFLAGS'])
36
if os.environ.has_key('CXX'):
37
    main_env['CXX'] = os.environ['CXX']
38
if os.environ.has_key('CXXFLAGS'):
39
    main_env['CXXFLAGS'] += SCons.Util.CLVar(os.environ['CXXFLAGS'])
40
if os.environ.has_key('LDFLAGS'):
41
    main_env['LINKFLAGS'] += SCons.Util.CLVar(os.environ['LDFLAGS'])
42
else:
43
    os.environ['LDFLAGS']=""
44

    
45
# Add builders for flex and bison
46
add_lex(main_env)
47
add_bison(main_env)
48

    
49
# Include dirs
50
main_env.Append(CPPPATH=[
51
    cwd+'/include',
52
])
53

    
54
# Library dirs
55
main_env.Append(LIBPATH=[
56
    cwd+'/src/common',
57
    cwd+'/src/log',
58
    cwd+'/src/sql',
59
    cwd+'/src/host',
60
    cwd+'/src/cluster',
61
    cwd+'/src/group',
62
    cwd+'/src/mad',
63
    cwd+'/src/nebula',
64
    cwd+'/src/pool',
65
    cwd+'/src/template',
66
    cwd+'/src/vm',
67
    cwd+'/src/vm_template',
68
    cwd+'/src/vmm',
69
    cwd+'/src/lcm',
70
    cwd+'/src/tm',
71
    cwd+'/src/dm',
72
    cwd+'/src/im',
73
    cwd+'/src/image',
74
    cwd+'/src/rm',
75
    cwd+'/src/vnm',
76
    cwd+'/src/hm',
77
    cwd+'/src/um',
78
    cwd+'/src/authm',
79
    cwd+'/src/xml',
80
])
81

    
82
# Compile flags
83
main_env.Append(CPPFLAGS=[
84
    "-g",
85
    "-Wall"
86
])
87

    
88
# Linking flags
89
main_env.Append(LINKFLAGS=['-g', '-pthread'])
90

    
91
#######################
92
# EXTRA CONFIGURATION #
93
#######################
94

    
95
# SQLITE
96
sqlite_dir=ARGUMENTS.get('sqlite_dir', 'none')
97
if sqlite_dir!='none':
98
    main_env.Append(LIBPATH=[sqlite_dir+"/lib"])
99
    main_env.Append(CPPPATH=[sqlite_dir+"/include"])
100

    
101
sqlite=ARGUMENTS.get('sqlite', 'yes')
102
if sqlite=='yes':
103
    main_env.Append(sqlite='yes')
104
    main_env.Append(CPPFLAGS=["-DSQLITE_DB"])
105
    main_env.Append(LIBS=['sqlite3'])
106
else:
107
    main_env.Append(sqlite='no')
108

    
109
# MySQL
110
mysql=ARGUMENTS.get('mysql', 'no')
111
if mysql=='yes':
112
    main_env.Append(mysql='yes')
113
    main_env.Append(CPPFLAGS=["-DMYSQL_DB"])
114
    main_env.Append(LIBS=['mysqlclient'])
115
else:
116
    main_env.Append(mysql='no')
117

    
118
# xmlrpc
119
xmlrpc_dir=ARGUMENTS.get('xmlrpc', 'none')
120
if xmlrpc_dir!='none':
121
    main_env.Append(LIBPATH=[xmlrpc_dir+"/lib"])
122
    main_env.Append(CPPPATH=[xmlrpc_dir+"/include"])
123

    
124
# build lex/bison
125
build_parsers=ARGUMENTS.get('parsers', 'no')
126
if build_parsers=='yes':
127
    main_env.Append(parsers='yes')
128
else:
129
    main_env.Append(parsers='no')
130

    
131
if not main_env.GetOption('clean'):
132
    try:
133
        if mysql=='yes':
134
            main_env.ParseConfig('mysql_config --cflags --libs')
135
    except Exception, e:
136
        print ""
137
        print "mysql_config was not found in the path"
138
        print ""
139
        print "Check that mysql development package is installed and"
140
        print "mysql_config is in the path. If your mysql config tool"
141
        print "is called mysql5_config make a symlink as mysql_config"
142
        print "to a directory in the path."
143
        print ""
144
        exit(-1)
145

    
146

    
147
    try:
148
        main_env.ParseConfig(("LDFLAGS='%s' share/scons/get_xmlrpc_config"+
149
            " server") % (os.environ['LDFLAGS'],))
150
        main_env.ParseConfig(("LDFLAGS='%s' share/scons/get_xmlrpc_config"+
151
            " client") % (os.environ['LDFLAGS'],))
152

    
153
    except Exception, e:
154
        print ""
155
        print "Error searching for xmlrpc-c libraries. Please check this"+\
156
            " things:"
157
        print ""
158
        print " * You have installed development libraries for xmlrpc-c. One"+\
159
            " way to check"
160
        print "   this is calling xmlrpc-c-config that is provided with the"+\
161
            " development"
162
        print "   package."
163
        print " * Check that the version of xmlrpc-c is at least 1.06. You"+\
164
            " can do this also"
165
        print "   calling:"
166
        print "   $ xmlrpc-c-config --version"
167
        print " * If all this requirements are already met please send log"+\
168
            " files located in"
169
        print "   .xmlrpc_test to the mailing list."
170
        print ""
171
        exit(-1)
172
else:
173
    main_env.Replace(mysql='yes')
174
    shutil.rmtree('.xmlrpc_test', True)
175
    shutil.rmtree('src/nebula/.xmlrpc_test', True)
176
    shutil.rmtree('src/scheduler/.xmlrpc_test', True)
177

    
178

    
179
# libxml2
180
main_env.ParseConfig('xml2-config --libs --cflags')
181

    
182

    
183
# SCONS scripts to build
184
build_scripts=[
185
    'src/sql/SConstruct',
186
    'src/log/SConstruct',
187
    'src/common/SConstruct',
188
    'src/template/SConstruct',
189
    'src/host/SConstruct',
190
    'src/cluster/SConstruct',
191
    'src/group/SConstruct',
192
    'src/mad/SConstruct',
193
    'src/nebula/SConstruct',
194
    'src/pool/SConstruct',
195
    'src/vm/SConstruct',
196
    'src/vm_template/SConstruct',
197
    'src/vmm/SConstruct',
198
    'src/lcm/SConstruct',
199
    'src/rm/SConstruct',
200
    'src/tm/SConstruct',
201
    'src/im/SConstruct',
202
    'src/image/SConstruct',
203
    'src/dm/SConstruct',
204
    'src/scheduler/SConstruct',
205
    'src/vnm/SConstruct',
206
    'src/hm/SConstruct',
207
    'src/um/SConstruct',
208
    'src/authm/SConstruct',
209
    'src/xml/SConstruct',
210
]
211

    
212
# Testing
213
testing=ARGUMENTS.get('tests', 'no')
214

    
215
if testing=='yes':
216
    main_env.Append(testing='yes')
217

    
218
    main_env.ParseConfig('cppunit-config --cflags --libs')
219

    
220
    main_env.Append(CPPPATH=[
221
        cwd+'/include/test',
222
        '/usr/include/cppunit/' #not provided by cppunit-config command
223
    ])
224

    
225
    main_env.Append(LIBPATH=[
226
        cwd+'/src/test',
227
    ])
228

    
229
    main_env.Append(LIBS=[
230
        'nebula_test_common',
231
    ])
232

    
233
    build_scripts.extend([
234
        'src/authm/test/SConstruct',
235
        'src/common/test/SConstruct',
236
        'src/host/test/SConstruct',
237
        'src/cluster/test/SConstruct',
238
        'src/group/test/SConstruct',
239
        'src/image/test/SConstruct',
240
        'src/lcm/test/SConstruct',
241
        'src/pool/test/SConstruct',
242
        'src/template/test/SConstruct',
243
        'src/test/SConstruct',
244
        'src/um/test/SConstruct',
245
        'src/vm/test/SConstruct',
246
        'src/vnm/test/SConstruct',
247
        'src/xml/test/SConstruct',
248
        'src/vm_template/test/SConstruct',
249
    ])
250
else:
251
    main_env.Append(testing='no')
252

    
253

    
254
for script in build_scripts:
255
    env=main_env.Clone()
256
    SConscript(script, exports='env')