1 import os, string, sys, subprocess
5 boost_env = env.Clone()
7 modules = ['thread','program_options']
9 target_os = env.get('TARGET_OS')
11 boost_version = '1.57.0'
12 boost_base_name = 'boost_'+string.replace(boost_version,'.','_')
13 boost_arch_name = boost_base_name+'.zip'
14 boost_url = 'http://downloads.sourceforge.net/project/boost/boost/'+boost_version+'/'+boost_arch_name+'?r=&ts=1421801329&use_mirror=iweb'
16 host_os = sys.platform
18 if host_os == 'linux2' :
19 boost_bootstrap = boost_base_name+os.sep+'bootstrap.sh'
20 boost_b2_name = boost_base_name+os.sep+'b2'
22 msg="Host platform (%s) is currently not supported for boost builds" % host_os
23 raise SCons.Errors.EnvironmentError(msg)
25 # Download source code
26 boost_zip = boost_env.Download(boost_arch_name, boost_url)
29 if not os.path.exists(boost_bootstrap):
30 boost_env.UnpackAll(boost_bootstrap, boost_zip)
33 if not os.path.exists(boost_b2_name):
34 boost_env.Configure(boost_base_name, './bootstrap.sh')
39 if boost_env["PLATFORM"] in ["win32"] :
40 if boost_env.WhereIs("cmd") :
41 # TODO: Add Windows Support
44 # read the tools on *nix systems and sets the default parameters
45 elif boost_env["PLATFORM"] in ["darwin", "linux", "posix"] :
46 if boost_env.WhereIs("sh") :
50 raise SCons.Errors.StopError("Boost build system not supported on this platform [%s]" % (boost_env["PLATFORM"]))
52 # We need to be in the target's directory
55 # Gather all of the path, bin and flags
56 version = boost_env.get('VERSION','')
57 target_os = boost_env['TARGET_OS']
58 target_arch = boost_env['TARGET_ARCH']
59 tool_path = os.path.dirname(boost_env['CXX'])
60 cxx_bin = os.path.basename(boost_env['CXX'])
61 ar_bin = os.path.basename(boost_env['AR'])
62 ranlib_bin = os.path.basename(boost_env['RANLIB'])
63 ccflags = list(boost_env['CFLAGS'])
64 cxxflags = list(boost_env['CXXFLAGS'])
67 cxxflags.remove('-fno-rtti')
71 cxxflags.remove('-fno-exceptions')
75 # Write a user-config for this variant
76 user_config_name = os.path.join(cwd, 'tools', 'build', 'src', 'user-config.jam')
77 user_config_file = open(user_config_name, 'w')
78 user_config_file.write('import os ;\n')
79 user_config_file.write('using gcc :')
80 user_config_file.write(' '+version+' :')
81 #user_config_file.write(' :')
82 #user_config_file.write(' '+os.path.basename(toolchain['CXX']['BIN'])+' :\n')
83 user_config_file.write(' '+cxx_bin+' :\n')
84 user_config_file.write(' <archiver>'+ar_bin+'\n')
85 user_config_file.write(' <ranlib>'+ranlib_bin+'\n')
86 for value in boost_env['CPPDEFINES'] :
88 user_config_file.write(' <compileflags>-D'+value[0]+'='+value[1]+'\n')
90 user_config_file.write(' <compileflags>-D'+value[0]+'\n')
91 for value in boost_env['CPPPATH'] :
92 user_config_file.write(' <compileflags>-I'+value+'\n')
94 user_config_file.write(' <compileflags>'+flag+'\n')
95 for flag in cxxflags :
96 user_config_file.write(' <cxxflags>'+flag+'\n')
97 user_config_file.write(' ;\n')
98 user_config_file.close();
100 # Ensure that the toolchain is in the PATH
101 penv = os.environ.copy()
102 penv["PATH"] = tool_path + ":" + env['ENV'].get('PATH', '') + ':' + penv["PATH"]
104 build_path = os.path.join('build', target_os, target_arch)
107 cmd.append('target-os=linux')
108 cmd.append('link=static')
109 cmd.append('threading=multi')
110 cmd.append('--layout=system')
111 cmd.append('--build-type=minimal')
112 cmd.append('--prefix='+ build_path + os.sep + 'install_tmp')
113 cmd.append('--build-dir='+build_path)
114 for module in modules :
115 cmd.append('--with-'+module)
116 cmd.append('headers')
117 cmd.append('install')
119 # build it now (we need the shell, because some programs need it)
120 devnull = open(os.devnull, "wb")
121 print "Building boost [%s] on the source [%s]" % (cmd, boost_b2_name)
122 handle = subprocess.Popen(cmd, env=penv, cwd=cwd)#, stdout=devnull )
124 if handle.wait() <> 0 :
125 raise SCons.Errors.BuildError( "Building boost [%s] on the source [%s]" % (cmd, boost_b2_name) )
127 # Use Copy instead of InstallXXX to make sure boost is installed immediately
128 Execute(Copy(os.path.join(env.get('SRC_DIR'), 'deps', target_os, 'include'),
129 os.path.join(boost_base_name, build_path, 'install_tmp', 'include')))
131 Execute(Copy(os.path.join(env.get('SRC_DIR'), 'deps', target_os, 'lib', target_arch),
132 os.path.join(boost_base_name, build_path, 'install_tmp', 'lib')))