summaryrefslogtreecommitdiffstats
path: root/lib/libUPnP/Platinum/Build/Targets/arm-android-linux/Config.scons
blob: bdbf08d3e65c407f2a71929baa09bb9e932499f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#################################################################
# Important: this build file has been tested with Android NDK r6, r7 and r8
# It may or may not work with other releases of the NDK. Please notify
# us if you find a newer NDK for which this does not work.
#################################################################

import os
import re
import sys
import platform

# we need to know when the NDK is
ANDROID_NDK_ROOT=os.getenv('ANDROID_NDK_ROOT')
if not ANDROID_NDK_ROOT:
    raise Exception('ANDROID_NDK_ROOT environment variable not set')

# detect the host system on which we're running
if env.has_key('android_host_system') and env['android_host_system']:
	ANDROID_HOST_SYSTEM = env['android_host_system']
else:
	PLATFORM_TO_TARGET_MAP = {
    	'linux-i386' : 'linux-x86',
    	'linux2'     : 'linux-x86',
    	'win32'      : 'windows',
    	'cygwin'     : 'windows',
    	'darwin'     : 'darwin-x86'
	}
	if sys.platform in PLATFORM_TO_TARGET_MAP:
		ANDROID_HOST_SYSTEM = PLATFORM_TO_TARGET_MAP[sys.platform]
	else:
		raise Exception('Android Host Platform cannot be determined')

# set defaults
ANDROID_ARCH         = 'arm'
ANDROID_PLATFORM     = 'android-9'
ANDROID_TOOLCHAIN    = 'arm-linux-androideabi-4.4.3'
ANDROID_CROSS_PREFIX = 'arm-linux-androideabi'

if not os.path.exists(os.path.join(ANDROID_NDK_ROOT, 'toolchains', ANDROID_TOOLCHAIN)):
    toolchain_dirs = os.listdir(ANDROID_NDK_ROOT+'/toolchains')
    for toolchain_dir in toolchain_dirs:
        if os.path.exists(os.path.join(ANDROID_NDK_ROOT, 'toolchains', toolchain_dir, 'prebuilt', ANDROID_HOST_SYSTEM)):
            ANDROID_TOOLCHAIN=toolchain_dir
            suffix_pos = toolchain_dir.rfind('-')
            if (suffix_pos >= 0):
                ANDROID_CROSS_PREFIX = ANDROID_TOOLCHAIN[:suffix_pos]
            print "Auto-selecting toolchain:", ANDROID_TOOLCHAIN
            break

# override defaults from command line args
if ARGUMENTS.get('android_toolchain'):
    ANDROID_TOOLCHAIN=ARGUMENTS.get('android_toolchain')

if ARGUMENTS.get('android_cross_prefix'):
    ANDROID_CROSS_PREFIX=ARGUMENTS.get('android_cross_prefix')

if ARGUMENTS.get('android_platform'):
    ANDROID_PLATFORM=ARGUMENTS.get('android_platform')

if ARGUMENTS.get('android_arch'):
    ANDROID_ARCH=ARGUMENTS.get('android_arch')

print 'Building for Android: '
print 'ANDROID_HOST_SYSTEM =', ANDROID_HOST_SYSTEM
print 'ANDROID_TOOLCHAIN   =', ANDROID_TOOLCHAIN
print 'ANDROID_PLATFORM    =', ANDROID_PLATFORM
print 'ANDROID_ARCH        =', ANDROID_ARCH

ANDROID_TOOLCHAIN_BIN = ANDROID_NDK_ROOT+'/toolchains/'+ANDROID_TOOLCHAIN+'/prebuilt/'+ANDROID_HOST_SYSTEM+'/bin'
ANDROID_SYSROOT = ANDROID_NDK_ROOT+'/platforms/'+ANDROID_PLATFORM+'/arch-'+ANDROID_ARCH

### add the tools to the path
env.PrependENVPath('PATH', ANDROID_TOOLCHAIN_BIN)

### special C Runtime startup for executables
env['NPT_EXTRA_EXECUTABLE_OBJECTS'] = []
env['NPT_EXTRA_LIBS'] = ['gcc']

### Load the tools
LoadTool('gcc-generic', env, gcc_cross_prefix=ANDROID_CROSS_PREFIX, gcc_strict=False)
env.AppendUnique(CCFLAGS = ['-I'+ANDROID_NDK_ROOT+'/sources/cxx-stl/system/include' ,
                            '--sysroot', ANDROID_SYSROOT,
                            '-msoft-float',
                            '-fpic',
                            '-mthumb-interwork',
                            '-ffunction-sections',
                            '-funwind-tables',
                            '-fstack-protector',
                            '-fno-short-enums'])
env.AppendUnique(CXXFLAGS = ['-fno-exceptions', '-fno-rtti'])
env.AppendUnique(CPPDEFINES = ['ANDROID', 'NPT_CONFIG_HAVE_SYSTEM_LOG_CONFIG'])
env.AppendUnique(LINKFLAGS = ['--sysroot', ANDROID_SYSROOT,
                			  '-Wl,--no-undefined',
                              '-Wl,-z,noexecstack',
                			  '-L'+ANDROID_SYSROOT+'/usr/lib',
                			  '-lc',
                			  '-lstdc++',
                			  '-lm',
                			  '-llog',
                			  '-ldl'])

### Specific System choices
env['NPT_SYSTEM_SOURCES']={'System/StdC':'NptStdc[!D]*.cpp',
                           'System/Bsd':'*.cpp',
                           'System/Posix':'*.cpp',
                           'System/Null':['NptNullSerialPort.cpp', 'NptNullAutoreleasePool.cpp'],
                           'System/Android':'*.cpp'}