summaryrefslogtreecommitdiff
path: root/config/android.config
blob: da9cee72221d283edc5550fd073a90b9b398e46a (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# This file contains the default configuration to compile for Android
# platforms. It contains sensitive enviroment configuration that
# shouldn't be modified unless you know what you are doing.
# PLEASE, DO NOT EDIT THIS FILE

import os
from cerbero.enums import Architecture, DistroVersion, Platform
from cerbero.errors import FatalError
import cerbero.utils.messages as m

# So, paths:
#
# With NDK r16, 'Unified Headers' is the only way to build against the NDK and
# the API-level specific headers are not shipped anymore.  A migration guide is
# available from https://android.googlesource.com/platform/ndk/+/ndk-release-r16/docs/UnifiedHeaders.md
# and we follow that when setting up these paths.  One thing to note however
# is that the 'Unified Headers' ship headers that contain API-level guarded
# functions so we may need to replace or override headers.  One such example
# is iconv.h which at the time of writing, has a header in the NDK
# with no usable functions.  This simply means that we have to construct 
# cflags/cppflags/ldflags/etc to look in our directories before looking into
# the sysroot.
#
# toolchain_prefix: NDK location
# toolchain_path: location of the compiler binaries
# sysroot: location of the API-level libraries (no headers)
# isysroot: location of the headers

variants += ['nopython', 'notestspackage']

# We don't want anything from linux system to be used on android :)
allow_system_libs=False

if not toolchain_prefix:
    toolchain_prefix = os.path.join(home_dir, 'android-ndk-18')

toolchain_path = None
toolchain_version = None

v = DistroVersion.get_android_api_version(target_distro_version)

tools_prefix = None
tools_dir = None
host = None
llvm_triple = None
_arch = None
if target_arch == Architecture.ARMv7:
    tools_prefix = 'arm-linux-androideabi'
    tools_dir = tools_prefix
    arch_include = tools_prefix
    host = 'arm-linux-androideabi'
    llvm_triple = 'armv7-none-linux-androideabi' + str(v)
    _android_arch = 'arm'
    _cerbero_arch = 'armv7'
elif target_arch == Architecture.ARM64:
    tools_prefix = 'aarch64-linux-android'
    tools_dir = tools_prefix
    arch_include = tools_prefix
    host = 'aarch64-linux-android'
    llvm_triple = 'aarch64-none-linux-android'
    _android_arch = 'arm64'
    _cerbero_arch = 'arm64'
elif target_arch == Architecture.X86:
    tools_prefix = 'i686-linux-android'
    tools_dir = 'x86'
    arch_include = tools_prefix
    host = 'i686-linux-android'
    llvm_triple = "i686-none-linux-android"
    _android_arch = 'x86'
    _cerbero_arch = 'x86'
elif target_arch == Architecture.X86_64:
    tools_prefix = 'x86_64-linux-android'
    tools_dir = 'x86_64'
    host = 'x86_64-linux-android'
    llvm_triple = "x86_64-none-linux-android"
    _android_arch = 'x86_64'
    _cerbero_arch = 'x86_64'
elif target_arch == Architecture.UNIVERSAL:
    tools_prefix = ''
    host = ''
    llvm_triple = ''
    _android_arch = 'x86_64'
    _cerbero_arch = 'x86_64'
else:
  raise FatalError("Arch %s not supported" % target_arch)

if platform == Platform.DARWIN:
    tc_arch = 'darwin-x86_64'
elif platform == Platform.LINUX:
    tc_arch = 'linux-x86_64'
else:
    raise FatalError("Platform %s is not supported" % platform)
llvm_toolchain_path = '%s/toolchains/llvm/prebuilt/%s/bin' % (toolchain_prefix, tc_arch)
gcc_toolchain_root = '%s/toolchains/%s-4.9/prebuilt/%s' % (toolchain_prefix, tools_dir, tc_arch)
spirv_toolchain_path = '%s/shader-tools/%s' % (toolchain_prefix, tc_arch)

gcc_toolchain_path = os.path.join (gcc_toolchain_root, 'bin')

isysroot = "%s/sysroot" % (toolchain_prefix)
sysroot = "%s/platforms/android-%d/arch-%s" % (toolchain_prefix, v, _android_arch)

# Default compiler flags
env['CFLAGS'] = '-Wall -g -Os '
env['CXXFLAGS'] = '-Wall -g -Os '
env['OBJCFLAGS'] = '-Wall -g -Os '

# Android NDK path
env['ANDROID_NDK'] = toolchain_prefix

# 'universal' is set by cerbero itself when building under a universal regime
# so that we can construct different paths to include/lib directories to where
# they actually are.  Without this we don't know where the headers/libs will
# actually end up
if 'universal' in variants:
    incl_dir = os.path.join(prefix, _cerbero_arch, 'include')
    lib_dir = os.path.join(prefix, _cerbero_arch, 'lib')
else:
    incl_dir = os.path.join(prefix, 'include')
    lib_dir = os.path.join(prefix, 'lib')
if target_arch != Architecture.UNIVERSAL and not os.path.exists(incl_dir):
    os.makedirs(incl_dir)
if target_arch != Architecture.UNIVERSAL and not os.path.exists(lib_dir):
    os.makedirs(lib_dir)

# Most of the compiler/linker specific flags are taken from
# from android-ndk-r16/build/core/toolchains/$NAME-$VERSION/setup.mk
ccache = use_ccache and 'ccache ' or ''
defines = '-DANDROID -DPIC -D__ANDROID_API__=%s ' % (v)
# -fno-integrated-as cause some libraries (e.g. pixman) fail to build with
# clang's assembler
# -target is being duplicated here and in CC variable to workaround cmake
# ignoring arguments in CC while other build systems may ignore CFLAGS for
# certain checks.
cflags = '-target %s --sysroot %s -gcc-toolchain %s -isysroot %s -isystem %s -isystem %s/usr/include -isystem %s/usr/include/%s -fno-integrated-as -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fPIC -Wno-invalid-command-line-argument -Wno-unused-command-line-argument ' % (llvm_triple, sysroot, gcc_toolchain_root, isysroot, incl_dir, isysroot, isysroot, tools_prefix)

# http://b.android.com/220159 http://b.android.com/222239
if target_arch == Architecture.X86:
    if v < 24:
        cflags += ' -mstackrealign'

ldflags = '-gcc-toolchain %s -fPIC -no-canonical-prefixes -Wl,-no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--gc-sections -Wl,-dynamic-linker,/system/bin/linker -Wl,--warn-shared-textrel -Wl,--exclude-libs,libatomic.a -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libunwind.a' % (gcc_toolchain_root)

if target_arch == Architecture.ARMv7:
    defines += ' -D__ARM_ARCH_7A__ '
    cflags += ' -mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16'
    ldflags += ' -Wl,--fix-cortex-a8 '
elif target_arch == Architecture.X86:
    cflags += ' -march=i686 '

ldflags += ' -L%s' % (lib_dir,)
if not target_arch in [Architecture.ARM64, Architecture.X86_64]:
   # nocopyreloc causes broken linking on arm64
   ldflags += ' -Wl,-z,nocopyreloc '
if target_arch in [Architecture.X86_64]:
   ldflags += ' -L%s/usr/lib64 ' % sysroot
else:
   ldflags += ' -L%s/usr/lib ' % sysroot

ldvariant = 'gold'
ldflags += ' -fuse-ld=%s ' % ldvariant

# Toolchain environment
env['CPPFLAGS'] = '-isysroot %s -isystem %s -isystem %s/usr/include -isystem %s/usr/include/%s %s' % (isysroot, incl_dir, isysroot, isysroot, tools_prefix, defines)
env['CFLAGS'] += "%s %s -Wa,--noexecstack" % (cflags, defines)
env['CXXFLAGS'] = env['CFLAGS'] + ' -fno-rtti -fno-exceptions'
env['LDFLAGS'] = '%s' % (ldflags,)

def cmd(command):
    return '%s-%s' % (tools_prefix, command)

# clang requires the full path otherwise it does stupid things and can't
# find it's own binary
env['CC']= ccache + os.path.join(llvm_toolchain_path, 'clang') + ' -target %s' % (llvm_triple) + ' --sysroot %s' % (sysroot)
env['CXX']= ccache + os.path.join(llvm_toolchain_path, 'clang++') + ' -target %s' % (llvm_triple) + ' --sysroot %s' % (sysroot)
env['LD']= cmd('ld.%s' % ldvariant)
env['CPP']= os.path.join(llvm_toolchain_path, 'clang') + ' -E'
env['RANLIB']= cmd('ranlib')
env['AR']= cmd('ar')
env['AS']= cmd('as')
env['NM']= cmd('nm')
env['STRIP']= cmd('strip')
env['OBJCOPY']= cmd('objcopy')

env['PATH'] = '%s:%s:%s:%s:%s' % (toolchain_prefix, llvm_toolchain_path, gcc_toolchain_path, spirv_toolchain_path, env['PATH'])
# For the libc.so dependency in i686-linux-android-as
if target_arch == Architecture.X86:
    extra_lib_path = '%s/usr/lib' % (sysroot)
elif target_arch == Architecture.X86_64:
    extra_lib_path = '%s/usr/lib64' % (sysroot)

# For GLib
env['glib_cv_stack_grows'] = 'yes'
env['glib_cv_uscore'] = 'no'
env['ac_cv_func_posix_getpwuid_r'] = 'no'
env['ac_cv_func_nonposix_getpwuid_r'] = 'no'
env['ac_cv_func_posix_getgrgid_r'] = 'no'
env['ac_cv_func_nonposix_getgrgid_r'] = 'no'

# For cairo
# FIXME : IF WE ADD BIG-ENDIAN PLATFORMS, FIX THIS !
env['ax_cv_c_float_words_bigendian'] = 'no'

#No, really, it doesn't have uselocale
env['ac_cv_func_uselocale'] = 'no'

# fixup meson detecting wrong functions as __builtin's
# https://github.com/mesonbuild/meson/issues/3672
if v < 18:
    meson_cross_properties['has_function_log2'] = 'false'
if v < 21:
    meson_cross_properties['has_function_stpcpy'] = 'false'
if v < 24:
    meson_cross_properties['has_function_fseeko'] = 'false'
    meson_cross_properties['has_function_ftello'] = 'false'
    meson_cross_properties['has_function_fsetpos'] = 'false'
    meson_cross_properties['has_function_fgetpos'] = 'false'
    meson_cross_properties['has_function_fseeko64'] = 'false'
    meson_cross_properties['has_function_ftello64'] = 'false'
    meson_cross_properties['has_function_fsetpos64'] = 'false'
    meson_cross_properties['has_function_fgetpos64'] = 'false'