2019-03-12 22:04:12 +03:00
# -*- coding: utf-8 -*-
2009-01-19 21:05:46 +03:00
# -------------------------------------------------------------------------- #
2023-01-09 14:23:19 +03:00
# Copyright 2002-2023, OpenNebula Project, OpenNebula Systems #
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. #
2019-09-06 14:30:23 +03:00
# -------------------------------------------------------------------------- #
2008-06-17 20:27:32 +04:00
import os
import sys
2009-04-23 21:01:52 +04:00
import shutil
2019-09-06 14:30:23 +03:00
from subprocess import Popen , PIPE
import SCons
from SCons . Environment import Environment
from SCons . Script import ARGUMENTS , SConscript
2008-06-17 20:27:32 +04:00
sys . path . append ( " ./share/scons " )
from lex_bison import *
2019-03-12 22:04:12 +03:00
2019-09-06 14:30:23 +03:00
# Get git version
2019-03-12 22:04:12 +03:00
try :
2019-09-06 14:30:23 +03:00
out = Popen ( [ " git " , " describe " , " --dirty " , " --always " , " --abbrev=8 " ] ,
stdout = PIPE )
git_version = out . communicate ( ) [ 0 ] . rstrip ( ) . decode ( ' utf-8 ' )
2019-03-12 22:04:12 +03:00
except OSError :
2019-09-19 11:32:12 +03:00
git_version = ARGUMENTS . get ( ' gitversion ' , ' not known ' )
2008-06-17 20:27:32 +04:00
# This is the absolute path where the project is located
2018-11-28 14:26:59 +03:00
cwd = os . getcwd ( )
2008-06-17 20:27:32 +04:00
# Environment that will be applied to each scons child
2018-11-28 14:26:59 +03:00
main_env = Environment ( )
main_env [ ' ENV ' ] [ ' PATH ' ] = os . environ [ ' PATH ' ]
2008-06-17 20:27:32 +04:00
2019-03-12 22:04:12 +03:00
main_env [ ' CXXFLAGS ' ] = " -DGITVERSION= \' \" " + git_version + " \" \' "
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
2019-09-06 14:30:23 +03:00
if ' CC ' in os . environ :
2010-08-19 14:32:50 +04:00
main_env [ ' CC ' ] = os . environ [ ' CC ' ]
2019-09-06 14:30:23 +03:00
if ' CFLAGS ' in os . environ :
2010-08-19 14:32:50 +04:00
main_env [ ' CCFLAGS ' ] + = SCons . Util . CLVar ( os . environ [ ' CFLAGS ' ] )
2019-09-06 14:30:23 +03:00
if ' CXX ' in os . environ :
2010-08-19 14:32:50 +04:00
main_env [ ' CXX ' ] = os . environ [ ' CXX ' ]
2019-09-06 14:30:23 +03:00
if ' CXXFLAGS ' in os . environ :
2010-08-19 14:32:50 +04:00
main_env [ ' CXXFLAGS ' ] + = SCons . Util . CLVar ( os . environ [ ' CXXFLAGS ' ] )
2019-09-06 14:30:23 +03:00
if ' LDFLAGS ' in os . environ :
2010-08-19 14:32:50 +04:00
main_env [ ' LINKFLAGS ' ] + = SCons . Util . CLVar ( os . environ [ ' LDFLAGS ' ] )
2011-01-13 13:50:38 +03:00
else :
2018-11-28 14:26:59 +03:00
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 ' ,
2020-03-04 18:05:57 +03:00
cwd + ' /src/monitor/include ' ,
2018-03-18 01:31:52 +03:00
cwd + ' /src/parsers '
2008-06-17 20:27:32 +04:00
] )
# Library dirs
main_env . Append ( LIBPATH = [
2018-03-18 01:31:52 +03:00
cwd + ' /src/parsers ' ,
2008-07-10 15:24:48 +04:00
cwd + ' /src/common ' ,
2010-05-14 17:30:28 +04:00
cwd + ' /src/log ' ,
2017-04-25 18:15:31 +03:00
cwd + ' /src/raft ' ,
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/nebula ' ,
cwd + ' /src/pool ' ,
cwd + ' /src/template ' ,
cwd + ' /src/vm ' ,
2017-01-02 18:43:44 +03:00
cwd + ' /src/vm_group ' ,
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 ' ,
2018-11-20 19:24:59 +03:00
cwd + ' /src/vn_template ' ,
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 ' ,
2013-12-12 22:08:59 +04:00
cwd + ' /src/zone ' ,
2014-01-23 20:07:52 +04:00
cwd + ' /src/client ' ,
2014-09-08 13:50:25 +04:00
cwd + ' /src/secgroup ' ,
2014-12-19 19:30:00 +03:00
cwd + ' /src/vdc ' ,
2015-11-30 18:50:23 +03:00
cwd + ' /src/vrouter ' ,
2016-08-18 14:30:31 +03:00
cwd + ' /src/market ' ,
2020-03-04 18:05:57 +03:00
cwd + ' /src/ipamm ' ,
cwd + ' /src/data_model ' ,
2020-06-29 16:14:04 +03:00
cwd + ' /src/protocol '
2008-06-17 20:27:32 +04:00
] )
# Compile flags
main_env . Append ( CPPFLAGS = [
2008-07-10 15:24:48 +04:00
" -g " ,
2016-11-17 16:53:06 +03:00
" -Wall " ,
2023-03-08 17:52:20 +03:00
" -std=c++17 "
2008-06-17 20:27:32 +04:00
] )
2016-06-01 16:10:11 +03:00
# Linking flags & common libraries
2010-10-13 22:32:58 +04:00
main_env . Append ( LINKFLAGS = [ ' -g ' , ' -pthread ' ] )
2016-06-01 16:10:11 +03:00
main_env . Append ( LIBS = [ ' z ' ] )
2008-06-17 20:27:32 +04:00
#######################
# EXTRA CONFIGURATION #
#######################
2023-03-08 17:52:20 +03:00
# Generate help text
vars = Variables ( ' custom.py ' )
vars . Add ( ' sqlite_dir ' , ' Path to sqlite directory ' , ' ' )
vars . Add ( ' sqlite ' , ' Build with SQLite support ' , ' yes ' )
vars . Add ( ' mysql ' , ' Build with MySQL support ' , ' no ' )
vars . Add ( ' postgresql ' , ' Build with PostgreSQL support ' , ' no ' )
vars . Add ( ' parsers ' , ' Obsolete. Rebuild flex/bison files ' , ' no ' )
vars . Add ( ' xmlrpc ' , ' Path to xmlrpc directory ' , ' ' )
vars . Add ( ' new_xmlrpc ' , ' Use xmlrpc-c version >=1.31 ' , ' no ' )
vars . Add ( ' sunstone ' , ' Build Sunstone ' , ' no ' )
vars . Add ( ' fireedge ' , ' Build FireEdge ' , ' no ' )
vars . Add ( ' systemd ' , ' Build with systemd support ' , ' no ' )
vars . Add ( ' docker_machine ' , ' Build Docker machine driver ' , ' no ' )
vars . Add ( ' rubygems ' , ' Generate Ruby gems ' , ' no ' )
vars . Add ( ' svncterm ' , ' Build VNC support for LXD drivers ' , ' yes ' )
vars . Add ( ' context ' , ' Download guest contextualization packages ' , ' no ' )
vars . Add ( ' strict ' , ' Strict C++ compiler, more warnings, treat warnings as errors ' , ' no ' )
env = Environment ( variables = vars )
Help ( vars . GenerateHelpText ( env ) )
2008-06-17 20:27:32 +04:00
# SQLITE
2019-09-06 14:30:23 +03:00
sqlite_dir = ARGUMENTS . get ( ' sqlite_dir ' , " none " )
2018-11-28 14:26:59 +03: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
2018-11-28 14:26:59 +03:00
sqlite = ARGUMENTS . get ( ' sqlite ' , ' yes ' )
if sqlite == ' yes ' :
2010-05-07 16:45:27 +04:00
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
2018-11-28 14:26:59 +03:00
mysql = ARGUMENTS . get ( ' mysql ' , ' no ' )
if mysql == ' yes ' :
2010-05-05 21:26:35 +04:00
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
2020-04-13 18:32:21 +03:00
# PostgreSql
postgresql = ARGUMENTS . get ( ' postgresql ' , ' no ' )
if postgresql == ' yes ' :
main_env . Append ( postgresql = ' yes ' )
main_env . Append ( CPPPATH = [ ' /usr/include/postgresql ' ] )
main_env . Append ( CPPFLAGS = [ " -DPOSTGRESQL_DB " ] )
main_env . Append ( LIBS = [ ' libpq ' ] )
else :
main_env . Append ( postgresql = ' no ' )
2013-07-31 20:34:33 +04:00
# Flag to compile with xmlrpc-c versions prior to 1.31 (September 2012)
2018-11-28 14:26:59 +03:00
new_xmlrpc = ARGUMENTS . get ( ' new_xmlrpc ' , ' no ' )
if new_xmlrpc == ' yes ' :
2013-10-17 16:23:53 +04:00
main_env . Append ( new_xmlrpc = ' yes ' )
2013-07-31 20:34:33 +04:00
else :
2013-10-17 16:23:53 +04:00
main_env . Append ( new_xmlrpc = ' no ' )
main_env . Append ( CPPFLAGS = [ " -DOLD_XMLRPC " ] )
2013-07-31 20:34:33 +04:00
2008-06-17 20:27:32 +04:00
# xmlrpc
2018-11-28 14:26:59 +03:00
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 " ] )
2018-02-21 19:06:20 +03:00
# systemd
2018-11-28 14:26:59 +03:00
systemd = ARGUMENTS . get ( ' systemd ' , ' no ' )
if systemd == ' yes ' :
2018-02-21 19:06:20 +03:00
main_env . Append ( systemd = ' yes ' )
main_env . Append ( CPPFLAGS = [ " -DSYSTEMD " ] )
main_env . Append ( LIBS = [ ' systemd ' ] )
else :
main_env . Append ( systemd = ' no ' )
2008-06-17 20:27:32 +04:00
# build lex/bison
2018-11-28 14:26:59 +03:00
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 ' )
2023-03-08 17:52:20 +03:00
# strict: Add more warnings add treat warnings as errors
strict = ARGUMENTS . get ( ' strict ' , ' no ' )
if strict == ' yes ' :
main_env . Append ( CPPFLAGS = [
" -Wextra " ,
" -Werror " ,
" -Wno-error=deprecated-declarations " ,
" -Wno-unused-parameter " ,
" -Wno-unused-result "
] )
2012-10-24 21:18:48 +04:00
# Rubygem generation
main_env . Append ( rubygems = ARGUMENTS . get ( ' rubygems ' , ' no ' ) )
2020-06-01 20:21:13 +03:00
# Enterprise Edition
main_env . Append ( enterprise = ARGUMENTS . get ( ' enterprise ' , ' no ' ) )
2015-07-17 16:49:09 +03:00
# Sunstone minified files generation
main_env . Append ( sunstone = ARGUMENTS . get ( ' sunstone ' , ' no ' ) )
2020-07-02 17:12:39 +03:00
# FireEdge minified files generation
main_env . Append ( fireedge = ARGUMENTS . get ( ' fireedge ' , ' no ' ) )
2020-06-03 19:44:52 +03:00
# TODO this should be aligned with one-ee-tools workflows
# Onedb Marshal files generation
main_env . Append ( marshal = ARGUMENTS . get ( ' marshal ' , ' no ' ) )
2018-03-23 14:58:29 +03:00
# Docker-machine addon generation
main_env . Append ( docker_machine = ARGUMENTS . get ( ' docker_machine ' , ' no ' ) )
2020-06-25 12:24:51 +03:00
# Context packages download
main_env . Append ( context = ARGUMENTS . get ( ' context ' , ' no ' ) )
2009-04-23 20:30:59 +04:00
if not main_env . GetOption ( ' clean ' ) :
2011-04-13 17:24:45 +04:00
try :
2018-11-28 14:26:59 +03:00
if mysql == ' yes ' :
2011-04-13 17:24:45 +04:00
main_env . ParseConfig ( ' mysql_config --cflags --libs ' )
2019-09-06 14:30:23 +03:00
except Exception :
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 ( " " )
2011-04-13 17:24:45 +04:00
exit ( - 1 )
2009-04-23 20:30:59 +04:00
try :
2019-09-17 00:13:25 +03:00
env_xmlrpc_flags = " LDFLAGS= ' %s ' CXXFLAGS= ' %s ' CPPFLAGS= ' %s ' " % (
os . environ . get ( ' LDFLAGS ' , ' ' ) ,
os . environ . get ( ' CXXFLAGS ' , ' ' ) ,
os . environ . get ( ' CPPFLAGS ' , ' ' ) )
main_env . ParseConfig ( " %s share/scons/get_xmlrpc_config server " % (
env_xmlrpc_flags , ) )
main_env . ParseConfig ( " %s share/scons/get_xmlrpc_config client " % (
env_xmlrpc_flags , ) )
2010-05-07 16:45:27 +04:00
2019-09-06 14:30:23 +03:00
except Exception :
print ( " " )
print ( " Error searching for xmlrpc-c libraries. Please check this "
" things: " )
print ( " " )
print ( " * You have installed development libraries for xmlrpc-c. "
" One way to check " )
print ( " this is calling xmlrpc-c-config that is provided with the "
" development " )
print ( " package. " )
print ( " * Check that the version of xmlrpc-c is at least 1.06. You "
" can do this also " )
print ( " calling: " )
print ( " $ xmlrpc-c-config --version " )
print ( " * If all this requirements are already met please send log " ) + \
( " files located in " )
print ( " .xmlrpc_test to the mailing list. " )
print ( " " )
2009-04-23 20:30:59 +04:00
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 ' )
2020-05-04 14:21:51 +03:00
svncterm_path = ' src/svncterm_server/SConstruct '
2010-07-29 14:53:36 +04:00
2008-06-17 20:27:32 +04:00
# SCONS scripts to build
2019-09-06 14:30:23 +03:00
build_scripts = [
2018-03-18 01:31:52 +03:00
' src/parsers/SConstruct ' ,
2010-05-07 16:45:27 +04:00
' src/sql/SConstruct ' ,
2010-05-14 17:30:28 +04:00
' src/log/SConstruct ' ,
2017-04-25 18:15:31 +03:00
' src/raft/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/nebula/SConstruct ' ,
' src/pool/SConstruct ' ,
' src/vm/SConstruct ' ,
2017-01-02 18:43:44 +03:00
' src/vm_group/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 ' ,
2018-11-20 19:24:59 +03:00
' src/vn_template/SConstruct ' ,
2009-04-04 03:34:33 +04:00
' 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 ' ,
2013-12-12 22:08:59 +04:00
' src/zone/SConstruct ' ,
2014-09-08 13:50:25 +04:00
' src/secgroup/SConstruct ' ,
2014-12-19 19:30:00 +03:00
' src/vdc/SConstruct ' ,
2015-11-30 18:50:23 +03:00
' src/vrouter/SConstruct ' ,
2015-12-01 18:09:31 +03:00
' src/market/SConstruct ' ,
2016-08-18 14:30:31 +03:00
' src/ipamm/SConstruct ' ,
2015-06-25 18:08:46 +03:00
' src/sunstone/public/locale/languages/SConstruct ' ,
2015-07-17 16:49:09 +03:00
' src/sunstone/public/SConstruct ' ,
2020-07-02 17:12:39 +03:00
' src/fireedge/SConstruct ' ,
2013-09-30 01:08:08 +04:00
' share/rubygems/SConstruct ' ,
2018-03-23 14:58:29 +03:00
' src/client/SConstruct ' ,
2018-11-28 14:26:59 +03:00
' src/docker_machine/SConstruct ' ,
2020-03-04 18:05:57 +03:00
' src/monitor/SConstruct ' ,
2020-06-03 19:44:52 +03:00
' src/onedb/SConstruct ' ,
2020-06-29 16:14:04 +03:00
' src/protocol/SConstruct ' ,
2020-06-25 12:24:51 +03:00
svncterm_path ,
' share/context/SConstruct '
2008-06-17 20:27:32 +04:00
]
2018-12-05 19:42:51 +03:00
# disable svncterm
svncterm = ARGUMENTS . get ( ' svncterm ' , ' yes ' )
if svncterm == ' no ' :
build_scripts . remove ( svncterm_path )
else :
pass
2008-06-17 20:27:32 +04:00
for script in build_scripts :
2018-11-28 14:26:59 +03:00
env = main_env . Clone ( )
2008-06-17 20:27:32 +04:00
SConscript ( script , exports = ' env ' )