1 #################################################################
2 # Important: this build file has been tested with Android NDK r6, r7 and r8
3 # It may or may not work with other releases of the NDK. Please notify
4 # us if you find a newer NDK for which this does not work.
5 #################################################################
12 # we need to know when the NDK is
13 ANDROID_NDK_ROOT=os.getenv('ANDROID_NDK_ROOT')
14 if not ANDROID_NDK_ROOT:
15 raise Exception('ANDROID_NDK_ROOT environment variable not set')
17 # detect the host system on which we're running
18 if env.has_key('android_host_system') and env['android_host_system']:
19 ANDROID_HOST_SYSTEM = env['android_host_system']
21 PLATFORM_TO_TARGET_MAP = {
22 'linux-i386' : 'linux-x86',
23 'linux2' : 'linux-x86',
26 'darwin' : 'darwin-x86'
28 if sys.platform in PLATFORM_TO_TARGET_MAP:
29 ANDROID_HOST_SYSTEM = PLATFORM_TO_TARGET_MAP[sys.platform]
31 raise Exception('Android Host Platform cannot be determined')
35 ANDROID_PLATFORM = 'android-9'
36 ANDROID_TOOLCHAIN = 'arm-linux-androideabi-4.4.3'
37 ANDROID_CROSS_PREFIX = 'arm-linux-androideabi'
39 if not os.path.exists(os.path.join(ANDROID_NDK_ROOT, 'toolchains', ANDROID_TOOLCHAIN)):
40 toolchain_dirs = os.listdir(ANDROID_NDK_ROOT+'/toolchains')
41 for toolchain_dir in toolchain_dirs:
42 if os.path.exists(os.path.join(ANDROID_NDK_ROOT, 'toolchains', toolchain_dir, 'prebuilt', ANDROID_HOST_SYSTEM)):
43 ANDROID_TOOLCHAIN=toolchain_dir
44 suffix_pos = toolchain_dir.rfind('-')
46 ANDROID_CROSS_PREFIX = ANDROID_TOOLCHAIN[:suffix_pos]
47 print "Auto-selecting toolchain:", ANDROID_TOOLCHAIN
50 # override defaults from command line args
51 if ARGUMENTS.get('android_toolchain'):
52 ANDROID_TOOLCHAIN=ARGUMENTS.get('android_toolchain')
54 if ARGUMENTS.get('android_cross_prefix'):
55 ANDROID_CROSS_PREFIX=ARGUMENTS.get('android_cross_prefix')
57 if ARGUMENTS.get('android_platform'):
58 ANDROID_PLATFORM=ARGUMENTS.get('android_platform')
60 if ARGUMENTS.get('android_arch'):
61 ANDROID_ARCH=ARGUMENTS.get('android_arch')
63 print 'Building for Android: '
64 print 'ANDROID_HOST_SYSTEM =', ANDROID_HOST_SYSTEM
65 print 'ANDROID_TOOLCHAIN =', ANDROID_TOOLCHAIN
66 print 'ANDROID_PLATFORM =', ANDROID_PLATFORM
67 print 'ANDROID_ARCH =', ANDROID_ARCH
69 ANDROID_TOOLCHAIN_BIN = ANDROID_NDK_ROOT+'/toolchains/'+ANDROID_TOOLCHAIN+'/prebuilt/'+ANDROID_HOST_SYSTEM+'/bin'
70 ANDROID_SYSROOT = ANDROID_NDK_ROOT+'/platforms/'+ANDROID_PLATFORM+'/arch-'+ANDROID_ARCH
72 ### add the tools to the path
73 env.PrependENVPath('PATH', ANDROID_TOOLCHAIN_BIN)
75 ### special C Runtime startup for executables
76 env['NPT_EXTRA_EXECUTABLE_OBJECTS'] = []
77 env['NPT_EXTRA_LIBS'] = ['gcc']
80 LoadTool('gcc-generic', env, gcc_cross_prefix=ANDROID_CROSS_PREFIX, gcc_strict=False)
81 env.AppendUnique(CCFLAGS = ['-I'+ANDROID_NDK_ROOT+'/sources/cxx-stl/system/include' ,
82 '--sysroot', ANDROID_SYSROOT,
86 '-ffunction-sections',
90 env.AppendUnique(CXXFLAGS = ['-fno-exceptions', '-fno-rtti'])
91 env.AppendUnique(CPPDEFINES = ['ANDROID', 'NPT_CONFIG_HAVE_SYSTEM_LOG_CONFIG'])
92 env.AppendUnique(LINKFLAGS = ['--sysroot', ANDROID_SYSROOT,
95 '-L'+ANDROID_SYSROOT+'/usr/lib',
102 ### Specific System choices
103 env['NPT_SYSTEM_SOURCES']={'System/StdC':'NptStdc[!D]*.cpp',
104 'System/Bsd':'*.cpp',
105 'System/Posix':'*.cpp',
106 'System/Null':['NptNullSerialPort.cpp', 'NptNullAutoreleasePool.cpp'],
107 'System/Android':'*.cpp'}