2cefa8bc60cbd20f311ca76538abe9f20cfd48c1
[platform/upstream/iotivity.git] / extlibs / boost / SConscript
1 import os, string, sys, subprocess
2
3 Import('env')
4
5 boost_env = env.Clone()
6
7 modules = ['thread','program_options']
8
9 target_os = env.get('TARGET_OS')
10 target_arch = env.get('TARGET_ARCH')
11
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'
16
17 host_os = sys.platform
18
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'
22 else :
23     msg="Host platform (%s) is currently not supported for boost builds" % host_os
24     raise SCons.Errors.EnvironmentError(msg)
25
26 # Download source code
27 boost_zip = boost_env.Download(boost_arch_name, boost_url)
28
29 # Unpack source code
30 if not os.path.exists(boost_bootstrap):
31     boost_env.UnpackAll(boost_bootstrap, boost_zip)
32
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+')
36     try:
37         content = file_object.read()
38         idx = content.find('#include <asm/page.h>')
39         if idx > 0 :
40             if content[idx -1] != '/' :
41                 content = content.replace('#include <asm/page.h>', '//#include <asm/page.h>')
42                 file_object.seek(0)
43                 file_object.write(content)
44     finally:
45         file_object.close( )
46
47 # Run bootstrap.sh
48 if not os.path.exists(boost_b2_name):
49     boost_env.Configure(boost_base_name, './bootstrap.sh')
50
51 cmd = None
52
53 # Windows...
54 if boost_env["PLATFORM"] in ["win32"] :
55     if boost_env.WhereIs("cmd") :
56         # TODO: Add Windows Support
57         cmd = None
58
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") :
62         cmd = ['./b2']
63
64 if not cmd :
65     raise SCons.Errors.StopError("Boost build system not supported on this platform [%s]" % (boost_env["PLATFORM"]))
66
67 # We need to be in the target's directory
68 cwd = boost_base_name
69
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'])
79
80 try:
81     cxxflags.remove('-fno-rtti')
82 except ValueError:
83     pass
84 try:
85     cxxflags.remove('-fno-exceptions')
86 except ValueError:
87     pass
88
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'] :
101     if len(value) > 1 :
102         user_config_file.write('    <compileflags>-D'+value[0]+'='+value[1]+'\n')
103     else :
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')
109 for flag in cflags :
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();
115
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"]
119
120 build_path = os.path.join('build', target_os, target_arch)
121
122 cmd.append('-q')
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')
134
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 )
139
140 if handle.wait() <> 0 :
141     raise SCons.Errors.BuildError( "Building boost [%s] on the source [%s]" % (cmd, boost_b2_name) )
142
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')))
146
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')))
149