1 import os, string, sys, subprocess
5 boost_env = env.Clone()
7 modules = ['thread','program_options']
9 target_os = env.get('TARGET_OS')
10 target_arch = env.get('TARGET_ARCH')
12 boost_version = '1.57.0'
13 boost_base_name = 'boost_'+string.replace(boost_version,'.','_')
14 boost_arch_name = boost_base_name+'.zip'
15 boost_url = 'http://downloads.sourceforge.net/project/boost/boost/'+boost_version+'/'+boost_arch_name+'?r=&ts=1421801329&use_mirror=iweb'
17 host_os = sys.platform
19 if host_os == 'linux2' :
20 boost_bootstrap = boost_base_name+os.sep+'bootstrap.sh'
21 boost_b2_name = boost_base_name+os.sep+'b2'
23 msg="Host platform (%s) is currently not supported for boost builds" % host_os
24 raise SCons.Errors.EnvironmentError(msg)
26 # Download source code
27 boost_zip = boost_env.Download(boost_arch_name, boost_url)
30 if not os.path.exists(boost_bootstrap):
31 boost_env.UnpackAll(boost_bootstrap, boost_zip)
33 # Fix android x86_64 build error due to missing asm/page.h
34 if target_os == 'android':
35 file_object = open(boost_base_name + '/boost/thread/pthread/thread_data.hpp', 'r+')
37 content = file_object.read()
38 idx = content.find('#include <asm/page.h>')
40 if content[idx -1] != '/' :
41 content = content.replace('#include <asm/page.h>', '//#include <asm/page.h>')
43 file_object.write(content)
48 if not os.path.exists(boost_b2_name):
49 boost_env.Configure(boost_base_name, './bootstrap.sh')
54 if boost_env["PLATFORM"] in ["win32"] :
55 if boost_env.WhereIs("cmd") :
56 # TODO: Add Windows Support
59 # read the tools on *nix systems and sets the default parameters
60 elif boost_env["PLATFORM"] in ["darwin", "linux", "posix"] :
61 if boost_env.WhereIs("sh") :
65 raise SCons.Errors.StopError("Boost build system not supported on this platform [%s]" % (boost_env["PLATFORM"]))
67 # We need to be in the target's directory
70 # Gather all of the path, bin and flags
71 version = boost_env.get('VERSION','')
72 tool_path = os.path.dirname(boost_env['CXX'])
73 cxx_bin = os.path.basename(boost_env['CXX'])
74 ar_bin = os.path.basename(boost_env['AR'])
75 ranlib_bin = os.path.basename(boost_env['RANLIB'])
76 cflags = list(boost_env['CFLAGS'])
77 ccflags = list(boost_env['CCFLAGS'])
78 cxxflags = list(boost_env['CXXFLAGS'])
81 cxxflags.remove('-fno-rtti')
85 cxxflags.remove('-fno-exceptions')
89 # Write a user-config for this variant
90 user_config_name = os.path.join(cwd, 'tools', 'build', 'src', 'user-config.jam')
91 user_config_file = open(user_config_name, 'w')
92 user_config_file.write('import os ;\n')
93 user_config_file.write('using gcc :')
94 user_config_file.write(' '+version+' :')
95 #user_config_file.write(' :')
96 #user_config_file.write(' '+os.path.basename(toolchain['CXX']['BIN'])+' :\n')
97 user_config_file.write(' '+cxx_bin+' :\n')
98 user_config_file.write(' <archiver>'+ar_bin+'\n')
99 user_config_file.write(' <ranlib>'+ranlib_bin+'\n')
100 for value in boost_env['CPPDEFINES'] :
102 user_config_file.write(' <compileflags>-D'+value[0]+'='+value[1]+'\n')
104 user_config_file.write(' <compileflags>-D'+value[0]+'\n')
105 for value in boost_env['CPPPATH'] :
106 user_config_file.write(' <compileflags>-I'+value+'\n')
107 for flag in ccflags :
108 user_config_file.write(' <compileflags>'+flag+'\n')
110 user_config_file.write(' <cflags>'+flag+'\n')
111 for flag in cxxflags :
112 user_config_file.write(' <cxxflags>'+flag+'\n')
113 user_config_file.write(' ;\n')
114 user_config_file.close();
116 # Ensure that the toolchain is in the PATH
117 penv = os.environ.copy()
118 penv["PATH"] = tool_path + ":" + env['ENV'].get('PATH', '') + ':' + penv["PATH"]
120 build_path = os.path.join('build', target_os, target_arch)
123 cmd.append('target-os=linux')
124 cmd.append('link=static')
125 cmd.append('threading=multi')
126 cmd.append('--layout=system')
127 cmd.append('--build-type=minimal')
128 cmd.append('--prefix='+ build_path + os.sep + 'install_tmp')
129 cmd.append('--build-dir='+build_path)
130 for module in modules :
131 cmd.append('--with-'+module)
132 cmd.append('headers')
133 cmd.append('install')
135 # build it now (we need the shell, because some programs need it)
136 devnull = open(os.devnull, "wb")
137 print "Building boost [%s] on the source [%s]" % (cmd, boost_b2_name)
138 handle = subprocess.Popen(cmd, env=penv, cwd=cwd)#, stdout=devnull )
140 if handle.wait() <> 0 :
141 raise SCons.Errors.BuildError( "Building boost [%s] on the source [%s]" % (cmd, boost_b2_name) )
143 # Use Copy instead of InstallXXX to make sure boost is installed immediately
144 Execute(Copy(os.path.join(env.get('SRC_DIR'), 'deps', target_os, 'include'),
145 os.path.join(boost_base_name, build_path, 'install_tmp', 'include')))
147 Execute(Copy(os.path.join(env.get('SRC_DIR'), 'deps', target_os, 'lib', target_arch),
148 os.path.join(boost_base_name, build_path, 'install_tmp', 'lib')))