1 # -*- coding: utf-8 -*-
3 # *********************************************************************
5 # Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
7 # *********************************************************************
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http:#www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
21 # *********************************************************************
23 # This builder executes the boost builder ('b2') for the toolchain
24 # defined currently in the SCONS environment. This builder was created
25 # to create cross-compiled version of boost. In particular, it has
26 # created to create boost binaries for Android's various architectures.
29 import SCons.Builder, SCons.Node, SCons.Errors
31 # Creates the building message
33 # @param s original message
34 # @param target target name
35 # @param source source name
36 # @param env environment object
37 def __message( s, target, source, env ) :
38 print "building boost from [%s] for ..." % (source[0])
41 # Create the builder action which constructs a user-config.jam based
42 # on the current toolchain and executes the boost build system ('b2')
44 # @param target target file on the local drive
45 # @param source URL for download
46 # @@param env environment object
47 def __action( target, source, env ) :
51 if env["PLATFORM"] in ["win32"] :
52 if env.WhereIs("cmd") :
53 # TODO: Add Windows Support
56 # read the tools on *nix systems and sets the default parameters
57 elif env["PLATFORM"] in ["darwin", "linux", "posix"] :
58 if env.WhereIs("sh") :
62 raise SCons.Errors.StopError("Boost build system not supported on this platform [%s]" % (env["PLATFORM"]))
64 # We need to be in the target's directory
65 cwd = os.path.dirname(os.path.realpath(source[0].path))
67 # Gather all of the path, bin and flags
68 version = env.get('VERSION','')
69 target_os = env['TARGET_OS']
70 target_arch = env['TARGET_ARCH']
71 tool_path = os.path.dirname(env['CXX'])
72 cxx_bin = os.path.basename(env['CXX'])
73 ar_bin = os.path.basename(env['AR'])
74 ranlib_bin = os.path.basename(env['RANLIB'])
75 ccflags = list(env['CFLAGS'])
76 cxxflags = list(env['CXXFLAGS'])
79 cxxflags.remove('-fno-rtti')
83 cxxflags.remove('-fno-exceptions')
87 # Write a user-config for this variant
88 user_config_name = cwd+os.sep+'tools'+os.sep+'build'+os.sep+'src'+os.sep+'user-config.jam'
89 user_config_file = open(user_config_name, 'w')
90 user_config_file.write('import os ;\n')
91 user_config_file.write('using gcc :')
92 user_config_file.write(' '+version+' :')
93 #user_config_file.write(' :')
94 #user_config_file.write(' '+os.path.basename(toolchain['CXX']['BIN'])+' :\n')
95 user_config_file.write(' '+cxx_bin+' :\n')
96 user_config_file.write(' <archiver>'+ar_bin+'\n')
97 user_config_file.write(' <ranlib>'+ranlib_bin+'\n')
98 for value in env['CPPDEFINES'] :
100 user_config_file.write(' <compileflags>-D'+value[0]+'='+value[1]+'\n')
102 user_config_file.write(' <compileflags>-D'+value[0]+'\n')
103 for value in env['CPPPATH'] :
104 user_config_file.write(' <compileflags>-I'+value+'\n')
105 for flag in ccflags :
106 user_config_file.write(' <compileflags>'+flag+'\n')
107 for flag in cxxflags :
108 user_config_file.write(' <cxxflags>'+flag+'\n')
109 user_config_file.write(' ;\n')
110 user_config_file.close();
112 # Ensure that the toolchain is in the PATH
113 penv = os.environ.copy()
114 penv["PATH"] = tool_path+":" + penv["PATH"]
116 build_path = 'build' + os.sep + target_os + os.sep + target_arch
119 cmd.append('target-os=linux')
120 cmd.append('link=static')
121 cmd.append('threading=multi')
122 cmd.append('--layout=system')
123 cmd.append('--build-type=minimal')
124 cmd.append('--prefix='+env['PREFIX'])
125 cmd.append('--build-dir='+build_path)
126 for module in env.get('MODULES',[]) :
127 cmd.append('--with-'+module)
128 cmd.append('headers')
129 cmd.append('install')
131 # build it now (we need the shell, because some programs need it)
132 devnull = open(os.devnull, "wb")
133 handle = subprocess.Popen( cmd, env=penv, cwd=cwd ) #, stdout=devnull )
135 if handle.wait() <> 0 :
136 raise SCons.Errors.BuildError( "Building boost [%s] on the source [%s]" % (cmd, source[0]) )
138 # Define the emitter of the builder
140 # @param target target file on the local drive
142 # @param env environment object
143 def __emitter( target, source, env ) :
144 return target, source
146 # Generate function which adds the builder to the environment
148 # @param env environment object
149 def generate( env ) :
150 env["BUILDERS"]["BoostBuild"] = SCons.Builder.Builder( action = __action, emitter = __emitter, target_factory = SCons.Node.FS.Entry, source_factory = SCons.Node.FS.File, single_source = True, PRINT_CMD_LINE_FUNC = __message )
152 # Exist function of the builder
153 # @param env environment object