2009-01-19 21:05:46 +03:00
# -------------------------------------------------------------------------- #
2013-01-24 19:18:30 +04:00
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
2009-01-19 21:05:46 +03:00
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
2008-06-17 20:27:32 +04:00
import os
import sys
2009-04-23 21:01:52 +04:00
import shutil
2008-06-17 20:27:32 +04:00
sys . path . append ( " ./share/scons " )
from lex_bison import *
# This is the absolute path where the project is located
cwd = os . getcwd ( )
# Environment that will be applied to each scons child
main_env = Environment ( )
main_env [ ' ENV ' ] [ ' PATH ' ] = os . environ [ ' PATH ' ]
2010-08-19 14:32:50 +04:00
# snippet borrowed from http://dev.gentoo.org/~vapier/scons-blows.txt
# makes scons aware of build related environment variables
if os . environ . has_key ( ' CC ' ) :
main_env [ ' CC ' ] = os . environ [ ' CC ' ]
if os . environ . has_key ( ' CFLAGS ' ) :
main_env [ ' CCFLAGS ' ] + = SCons . Util . CLVar ( os . environ [ ' CFLAGS ' ] )
if os . environ . has_key ( ' CXX ' ) :
main_env [ ' CXX ' ] = os . environ [ ' CXX ' ]
if os . environ . has_key ( ' CXXFLAGS ' ) :
main_env [ ' CXXFLAGS ' ] + = SCons . Util . CLVar ( os . environ [ ' CXXFLAGS ' ] )
if os . environ . has_key ( ' LDFLAGS ' ) :
main_env [ ' LINKFLAGS ' ] + = SCons . Util . CLVar ( os . environ [ ' LDFLAGS ' ] )
2011-01-13 13:50:38 +03:00
else :
os . environ [ ' LDFLAGS ' ] = " "
2010-08-19 14:32:50 +04:00
2008-06-17 20:27:32 +04:00
# Add builders for flex and bison
add_lex ( main_env )
add_bison ( main_env )
# Include dirs
main_env . Append ( CPPPATH = [
2008-07-10 15:24:48 +04:00
cwd + ' /include ' ,
2008-06-17 20:27:32 +04:00
] )
# Library dirs
main_env . Append ( LIBPATH = [
2008-07-10 15:24:48 +04:00
cwd + ' /src/common ' ,
2010-05-14 17:30:28 +04:00
cwd + ' /src/log ' ,
2010-05-07 16:45:27 +04:00
cwd + ' /src/sql ' ,
2008-07-10 15:24:48 +04:00
cwd + ' /src/host ' ,
2012-02-24 18:53:53 +04:00
cwd + ' /src/cluster ' ,
2012-02-09 20:56:47 +04:00
cwd + ' /src/datastore ' ,
2011-05-10 20:45:15 +04:00
cwd + ' /src/group ' ,
2008-07-10 15:24:48 +04:00
cwd + ' /src/mad ' ,
cwd + ' /src/nebula ' ,
cwd + ' /src/pool ' ,
cwd + ' /src/template ' ,
cwd + ' /src/vm ' ,
2011-03-30 21:03:49 +04:00
cwd + ' /src/vm_template ' ,
2008-07-10 15:24:48 +04:00
cwd + ' /src/vmm ' ,
cwd + ' /src/lcm ' ,
2009-04-23 21:24:12 +04:00
cwd + ' /src/tm ' ,
2008-07-10 15:24:48 +04:00
cwd + ' /src/dm ' ,
cwd + ' /src/im ' ,
2010-05-25 20:19:22 +04:00
cwd + ' /src/image ' ,
2008-07-10 15:24:48 +04:00
cwd + ' /src/rm ' ,
2008-11-13 19:21:17 +03:00
cwd + ' /src/vnm ' ,
2009-04-04 03:34:33 +04:00
cwd + ' /src/hm ' ,
2009-07-09 18:34:34 +04:00
cwd + ' /src/um ' ,
2010-05-28 02:29:23 +04:00
cwd + ' /src/authm ' ,
2011-06-27 21:11:34 +04:00
cwd + ' /src/acl ' ,
2011-02-23 13:17:45 +03:00
cwd + ' /src/xml ' ,
2012-06-08 17:41:59 +04:00
cwd + ' /src/document ' ,
2008-06-17 20:27:32 +04:00
] )
# Compile flags
main_env . Append ( CPPFLAGS = [
2008-07-10 15:24:48 +04:00
" -g " ,
2010-11-19 19:37:03 +03:00
" -Wall "
2008-06-17 20:27:32 +04:00
] )
# Linking flags
2010-10-13 22:32:58 +04:00
main_env . Append ( LINKFLAGS = [ ' -g ' , ' -pthread ' ] )
2008-06-17 20:27:32 +04:00
#######################
# EXTRA CONFIGURATION #
#######################
# SQLITE
2010-05-07 16:45:27 +04:00
sqlite_dir = ARGUMENTS . get ( ' sqlite_dir ' , ' none ' )
2008-06-17 20:27:32 +04:00
if sqlite_dir != ' none ' :
2012-07-27 23:56:41 +04:00
main_env . Append ( LIBPATH = [ sqlite_dir + " /lib " , sqlite_dir + " /lib64 " ] )
2008-06-17 20:27:32 +04:00
main_env . Append ( CPPPATH = [ sqlite_dir + " /include " ] )
2010-05-07 16:45:27 +04:00
sqlite = ARGUMENTS . get ( ' sqlite ' , ' yes ' )
if sqlite == ' yes ' :
main_env . Append ( sqlite = ' yes ' )
main_env . Append ( CPPFLAGS = [ " -DSQLITE_DB " ] )
2011-01-28 01:12:48 +03:00
main_env . Append ( LIBS = [ ' sqlite3 ' ] )
2010-05-07 16:45:27 +04:00
else :
main_env . Append ( sqlite = ' no ' )
2010-05-05 21:26:35 +04:00
# MySQL
mysql = ARGUMENTS . get ( ' mysql ' , ' no ' )
if mysql == ' yes ' :
main_env . Append ( mysql = ' yes ' )
2010-05-07 16:45:27 +04:00
main_env . Append ( CPPFLAGS = [ " -DMYSQL_DB " ] )
2011-01-28 01:12:48 +03:00
main_env . Append ( LIBS = [ ' mysqlclient ' ] )
2010-05-05 21:26:35 +04:00
else :
main_env . Append ( mysql = ' no ' )
2008-06-17 20:27:32 +04:00
2013-02-11 22:06:20 +04:00
# SysLog
syslog = ARGUMENTS . get ( ' syslog ' , ' no ' )
if syslog == ' yes ' :
main_env . Append ( syslog = ' yes ' )
main_env . Append ( CPPFLAGS = [ " -DSYSLOG_LOG " ] )
main_env . Append ( LIBS = [ ' pthread ' , ' log4cpp ' ] )
else :
main_env . Append ( syslog = ' no ' )
2013-01-25 20:32:12 +04:00
2008-06-17 20:27:32 +04:00
# xmlrpc
xmlrpc_dir = ARGUMENTS . get ( ' xmlrpc ' , ' none ' )
if xmlrpc_dir != ' none ' :
2012-07-27 23:56:41 +04:00
main_env . Append ( LIBPATH = [ xmlrpc_dir + " /lib " , xmlrpc_dir + " /lib64 " ] )
2008-06-17 20:27:32 +04:00
main_env . Append ( CPPPATH = [ xmlrpc_dir + " /include " ] )
# build lex/bison
build_parsers = ARGUMENTS . get ( ' parsers ' , ' no ' )
if build_parsers == ' yes ' :
2008-07-10 15:24:48 +04:00
main_env . Append ( parsers = ' yes ' )
2008-06-17 20:27:32 +04:00
else :
2008-07-10 15:24:48 +04:00
main_env . Append ( parsers = ' no ' )
2012-10-23 18:21:44 +04:00
# Context pakages
context_packages = ARGUMENTS . get ( ' context ' , ' no ' )
if context_packages == ' no ' :
main_env . Append ( context = [ ] )
elif context_packages == ' all ' :
main_env . Append ( context = [ ' deb ' , ' rpm ' ] )
else :
main_env . Append ( context = context_packages . split ( ' , ' ) )
2012-10-24 21:18:48 +04:00
# Rubygem generation
main_env . Append ( rubygems = ARGUMENTS . get ( ' rubygems ' , ' no ' ) )
2009-04-23 20:30:59 +04:00
if not main_env . GetOption ( ' clean ' ) :
2011-04-13 17:24:45 +04:00
try :
if mysql == ' yes ' :
main_env . ParseConfig ( ' mysql_config --cflags --libs ' )
except Exception , e :
print " "
print " mysql_config was not found in the path "
print " "
print " Check that mysql development package is installed and "
print " mysql_config is in the path. If your mysql config tool "
print " is called mysql5_config make a symlink as mysql_config "
print " to a directory in the path. "
print " "
exit ( - 1 )
2009-04-23 20:30:59 +04:00
try :
2010-12-22 20:22:12 +03:00
main_env . ParseConfig ( ( " LDFLAGS= ' %s ' share/scons/get_xmlrpc_config " +
" server " ) % ( os . environ [ ' LDFLAGS ' ] , ) )
main_env . ParseConfig ( ( " LDFLAGS= ' %s ' share/scons/get_xmlrpc_config " +
" client " ) % ( os . environ [ ' LDFLAGS ' ] , ) )
2010-05-07 16:45:27 +04:00
2009-04-23 20:30:59 +04:00
except Exception , e :
print " "
2009-04-23 21:38:46 +04:00
print " Error searching for xmlrpc-c libraries. Please check this " + \
2009-04-23 21:24:12 +04:00
" things: "
2009-04-23 20:30:59 +04:00
print " "
2009-04-23 21:38:46 +04:00
print " * You have installed development libraries for xmlrpc-c. One " + \
2009-04-23 21:24:12 +04:00
" way to check "
2009-04-23 21:38:46 +04:00
print " this is calling xmlrpc-c-config that is provided with the " + \
2009-04-23 21:24:12 +04:00
" development "
2009-04-23 20:30:59 +04:00
print " package. "
2009-04-23 21:38:46 +04:00
print " * Check that the version of xmlrpc-c is at least 1.06. You " + \
" can do this also "
2009-04-23 20:30:59 +04:00
print " calling: "
print " $ xmlrpc-c-config --version "
2009-04-23 21:38:46 +04:00
print " * If all this requirements are already met please send log " + \
2009-04-23 21:24:12 +04:00
" files located in "
2009-04-23 20:30:59 +04:00
print " .xmlrpc_test to the mailing list. "
print " "
exit ( - 1 )
2009-04-23 21:01:52 +04:00
else :
2010-08-17 14:17:29 +04:00
main_env . Replace ( mysql = ' yes ' )
2009-04-23 21:01:52 +04:00
shutil . rmtree ( ' .xmlrpc_test ' , True )
shutil . rmtree ( ' src/nebula/.xmlrpc_test ' , True )
shutil . rmtree ( ' src/scheduler/.xmlrpc_test ' , True )
2008-06-17 20:27:32 +04:00
2010-07-29 14:53:36 +04:00
# libxml2
main_env . ParseConfig ( ' xml2-config --libs --cflags ' )
2008-06-17 20:27:32 +04:00
# SCONS scripts to build
build_scripts = [
2010-05-07 16:45:27 +04:00
' src/sql/SConstruct ' ,
2010-05-14 17:30:28 +04:00
' src/log/SConstruct ' ,
2008-06-17 20:27:32 +04:00
' src/common/SConstruct ' ,
' src/template/SConstruct ' ,
' src/host/SConstruct ' ,
2012-02-24 18:53:53 +04:00
' src/cluster/SConstruct ' ,
2012-02-09 20:56:47 +04:00
' src/datastore/SConstruct ' ,
2011-05-10 20:45:15 +04:00
' src/group/SConstruct ' ,
2008-06-17 20:27:32 +04:00
' src/mad/SConstruct ' ,
2011-11-29 19:37:01 +04:00
' src/mad/utils/SConstruct ' ,
2008-06-17 20:27:32 +04:00
' src/nebula/SConstruct ' ,
' src/pool/SConstruct ' ,
' src/vm/SConstruct ' ,
2011-03-30 21:03:49 +04:00
' src/vm_template/SConstruct ' ,
2008-06-17 20:27:32 +04:00
' src/vmm/SConstruct ' ,
' src/lcm/SConstruct ' ,
' src/rm/SConstruct ' ,
' src/tm/SConstruct ' ,
' src/im/SConstruct ' ,
2010-05-25 20:19:22 +04:00
' src/image/SConstruct ' ,
2008-06-17 20:27:32 +04:00
' src/dm/SConstruct ' ,
2010-05-14 18:53:31 +04:00
' src/scheduler/SConstruct ' ,
2009-04-04 03:34:33 +04:00
' src/vnm/SConstruct ' ,
' src/hm/SConstruct ' ,
2009-07-09 18:34:34 +04:00
' src/um/SConstruct ' ,
2010-05-28 02:29:23 +04:00
' src/authm/SConstruct ' ,
2011-06-27 21:11:34 +04:00
' src/acl/SConstruct ' ,
2011-02-23 13:17:45 +03:00
' src/xml/SConstruct ' ,
2012-06-08 17:41:59 +04:00
' src/document/SConstruct ' ,
2012-05-24 16:43:43 +04:00
' share/man/SConstruct ' ,
2012-05-24 17:03:13 +04:00
' src/sunstone/locale/languages/SConstruct ' ,
2013-02-11 21:51:15 +04:00
' share/scripts/context-packages/SConstruct ' ,
2012-10-24 21:18:48 +04:00
' share/rubygems/SConstruct '
2008-06-17 20:27:32 +04:00
]
2011-01-28 01:12:48 +03:00
# Testing
testing = ARGUMENTS . get ( ' tests ' , ' no ' )
2011-01-26 19:05:43 +03:00
if testing == ' yes ' :
2011-01-28 01:12:48 +03:00
main_env . Append ( testing = ' yes ' )
main_env . ParseConfig ( ' cppunit-config --cflags --libs ' )
2011-01-26 19:05:43 +03:00
main_env . Append ( CPPPATH = [
cwd + ' /include/test ' ,
2011-01-28 01:12:48 +03:00
' /usr/include/cppunit/ ' #not provided by cppunit-config command
2011-01-26 19:05:43 +03:00
] )
main_env . Append ( LIBPATH = [
cwd + ' /src/test ' ,
] )
main_env . Append ( LIBS = [
' nebula_test_common ' ,
] )
build_scripts . extend ( [
' src/authm/test/SConstruct ' ,
' src/common/test/SConstruct ' ,
' src/host/test/SConstruct ' ,
2012-02-24 18:53:53 +04:00
' src/cluster/test/SConstruct ' ,
2012-02-09 20:56:47 +04:00
' src/datastore/test/SConstruct ' ,
2011-05-10 20:45:15 +04:00
' src/group/test/SConstruct ' ,
2011-01-26 19:05:43 +03:00
' src/image/test/SConstruct ' ,
' src/lcm/test/SConstruct ' ,
' src/pool/test/SConstruct ' ,
' src/template/test/SConstruct ' ,
' src/test/SConstruct ' ,
' src/um/test/SConstruct ' ,
' src/vm/test/SConstruct ' ,
' src/vnm/test/SConstruct ' ,
2011-02-23 13:17:45 +03:00
' src/xml/test/SConstruct ' ,
2011-04-07 14:32:35 +04:00
' src/vm_template/test/SConstruct ' ,
2011-01-26 19:05:43 +03:00
] )
2011-01-28 01:12:48 +03:00
else :
main_env . Append ( testing = ' no ' )
2011-01-26 19:05:43 +03:00
2008-06-17 20:27:32 +04:00
for script in build_scripts :
env = main_env . Clone ( )
SConscript ( script , exports = ' env ' )