diff options
author | Matthew Waters <matthew@centricular.com> | 2018-03-07 18:42:45 +1100 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2018-11-12 04:13:14 +0000 |
commit | c12581f6b12acfd2c1e95a6ec36414f8e8f38413 (patch) | |
tree | 2bb6533a72dd742c4e8925d625e35aeb06e3a9ad /config | |
parent | 65b3ac9e89a8db33e6111d9e84ed2b210ad1401e (diff) |
android: Update compiler to clang and NDKr18
Update all the locations/flags/etc for the new clang paradigm.
-gcc-toolchain points to the gnu binutils ar, as, etc that clang will
use.
NDK r18 removed the armv5 target and only has android platforms that
target at least armv7 so the armv5 target is not useful anymore.
https://gitlab.freedesktop.org/gstreamer/cerbero/issues/26
Diffstat (limited to 'config')
-rw-r--r-- | config/android.config | 166 | ||||
-rw-r--r-- | config/cross-android-armv7.cbc | 2 | ||||
-rw-r--r-- | config/cross-android-universal.cbc | 3 | ||||
-rw-r--r-- | config/cross-android-x86.cbc | 2 | ||||
-rw-r--r-- | config/cross-android.cbc | 10 |
5 files changed, 93 insertions, 90 deletions
diff --git a/config/android.config b/config/android.config index 6b05878d..bb0ea7df 100644 --- a/config/android.config +++ b/config/android.config @@ -32,79 +32,75 @@ variants += ['nopython', 'notestspackage'] allow_system_libs=False if not toolchain_prefix: - toolchain_prefix = os.path.join(home_dir, 'android-ndk-16') + toolchain_prefix = os.path.join(home_dir, 'android-ndk-18') toolchain_path = None toolchain_version = None -if target_arch == Architecture.ARM or target_arch == Architecture.ARMv7: +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' - host = "arm-linux-androideabi" - _arch = 'arm' - - for tc_version in ['4.9', '4.8', '4.7', '4.6']: - for tc_arch in ['darwin-x86', 'darwin-x86_64', 'linux-x86', 'linux-x86_64']: - tmp = '%s/toolchains/arm-linux-androideabi-%s/prebuilt/%s/bin' % (toolchain_prefix, tc_version, tc_arch) - if os.path.exists(tmp): - toolchain_path = tmp - toolchain_version = tc_version - break - if toolchain_path: - break + 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' - host = "aarch64-linux-android" - _arch = 'arm64' - - for tc_version in ['4.9', '4.8', '4.7', '4.6']: - for tc_arch in ['darwin-x86', 'darwin-x86_64', 'linux-x86', 'linux-x86_64']: - tmp = '%s/toolchains/aarch64-linux-android-%s/prebuilt/%s/bin' % (toolchain_prefix, tc_version, tc_arch) - if os.path.exists(tmp): - toolchain_path = tmp - toolchain_version = tc_version - break - if toolchain_path: - break + 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' - host = "i686-linux-android" - _arch = 'x86' - for tc_version in ['4.9', '4.8', '4.7', '4.6']: - for tc_arch in ['darwin-x86', 'darwin-x86_64', 'linux-x86', 'linux-x86_64']: - tmp = '%s/toolchains/x86-%s/prebuilt/%s/bin' % (toolchain_prefix, tc_version, tc_arch) - if os.path.exists(tmp): - toolchain_path = tmp - toolchain_version = tc_version - break - if toolchain_path: - break + 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' - host = "x86_64-linux-android" - _arch = 'x86_64' - for tc_version in ['4.9', '4.8', '4.7', '4.6']: - for tc_arch in ['darwin-x86', 'darwin-x86_64', 'linux-x86', 'linux-x86_64']: - tmp = '%s/toolchains/x86_64-%s/prebuilt/%s/bin' % (toolchain_prefix, tc_version, tc_arch) - if os.path.exists(tmp): - toolchain_path = tmp - toolchain_version = tc_version - break - if toolchain_path: - break + 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: - _arch = '' tools_prefix = '' - toolchain_path = '.' + host = '' + llvm_triple = '' + _android_arch = 'x86_64' + _cerbero_arch = 'x86_64' else: raise FatalError("Arch %s not supported" % target_arch) -if not toolchain_path: +llvm_toolchain_path = '.' +gcc_toolchain_root = '.' +for tc_arch in ['darwin-x86_64', 'linux-x86_64']: + llvm_tmp = '%s/toolchains/llvm/prebuilt/%s/bin' % (toolchain_prefix, tc_arch) + gcc_tmp = '%s/toolchains/%s-4.9/prebuilt/%s' % (toolchain_prefix, tools_dir, tc_arch) + if os.path.exists(llvm_tmp) and os.path.exists(gcc_tmp): + llvm_toolchain_path = llvm_tmp + gcc_toolchain_root = gcc_tmp + break + +if target_arch != Architecture.UNIVERSAL and llvm_toolchain_path == '.': m.warning ("Android NDK not found") -v = DistroVersion.get_android_api_version(target_distro_version) +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, _arch) +sysroot = "%s/platforms/android-%d/arch-%s" % (toolchain_prefix, v, _android_arch) # Default compiler flags os.environ['CFLAGS'] = '-Wall -g -Os ' @@ -119,8 +115,8 @@ os.environ['ANDROID_NDK'] = toolchain_prefix # 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, _arch, 'include') - lib_dir = os.path.join(prefix, _arch, 'lib') + 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') @@ -129,15 +125,20 @@ if target_arch != Architecture.UNIVERSAL and not os.path.exists(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) -# Android API older than 21 does not work well with -D_FILE_OFFSET_BITS=64, -# which is set by default in Meson. We must remove this when we move to -# building with Clang. -if v < 21: - defines += '-U_FILE_OFFSET_BITS ' -cflags = '-isysroot %s -isystem %s -isystem %s/usr/include -isystem %s/usr/include/%s -ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes -fPIC' % (isysroot, incl_dir, isysroot, isysroot, tools_prefix) -ldflags = '--sysroot %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 ' % (sysroot) +# -fno-integrated-as cause some libraries (e.g. pixman) fail to build with +# clang's assembler +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 not target_arch in [Architecture.ARM64, Architecture.X86_64]: # nocopyreloc causes broken linking on arm64 ldflags += ' -Wl,-z,nocopyreloc ' @@ -150,15 +151,10 @@ ldvariant = 'gold' ldflags += ' -fuse-ld=%s ' % ldvariant ldflags += ' -L%s' % (lib_dir,) -# from android-ndk-r8b/toolchains/$NAME-$VERSION/setup.mk -if target_arch in [Architecture.ARM, Architecture.ARMv7, Architecture.ARM64]: - if target_arch == Architecture.ARM: - defines += ' -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ ' - cflags += ' -mthumb -march=armv5te -mtune=xscale -msoft-float' - elif target_arch == Architecture.ARMv7: - defines += ' -D__ARM_ARCH_7A__ ' - cflags += ' -mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16' - ldflags += "-march=armv7-a -Wl,--fix-cortex-a8 " +if target_arch == Architecture.ARMv7: + defines += ' -D__ARM_ARCH_7A__ ' + cflags += ' -mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16' + ldflags += "-march=armv7-a -Wl,--fix-cortex-a8 " elif target_arch == Architecture.X86: cflags += ' -march=i686 ' @@ -171,10 +167,12 @@ os.environ['LDFLAGS'] = '%s' % (ldflags,) def cmd(command): return '%s-%s' % (tools_prefix, command) -os.environ['CC']= '%s%s' % (ccache, cmd('gcc')) -os.environ['CXX']= '%s%s' % (ccache, cmd('g++')) +# clang requires the full path otherwise it does stupid things and can't +# find it's own binary +os.environ['CC']= ccache + os.path.join(llvm_toolchain_path, 'clang') + ' -target %s' % (llvm_triple) + ' --sysroot %s' % (sysroot) +os.environ['CXX']= ccache + os.path.join(llvm_toolchain_path, 'clang++') + ' -target %s' % (llvm_triple) + ' --sysroot %s' % (sysroot) os.environ['LD']= cmd('ld.%s' % ldvariant) -os.environ['CPP']= cmd('cpp') +os.environ['CPP']= os.path.join(llvm_toolchain_path, 'clang') + ' -E' os.environ['RANLIB']= cmd('ranlib') os.environ['AR']= cmd('ar') os.environ['AS']= cmd('as') @@ -182,14 +180,13 @@ os.environ['NM']= cmd('nm') os.environ['STRIP']= cmd('strip') os.environ['OBJCOPY']= cmd('objcopy') -os.environ['PATH'] = '%s:%s:%s' % (toolchain_prefix, toolchain_path, os.environ['PATH']) +os.environ['PATH'] = '%s:%s:%s:%s' % (toolchain_prefix, llvm_toolchain_path, gcc_toolchain_path, os.environ['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 os.environ['glib_cv_stack_grows'] = 'yes' os.environ['glib_cv_uscore'] = 'no' @@ -204,3 +201,20 @@ os.environ['ax_cv_c_float_words_bigendian'] = 'no' #No, really, it doesn't have uselocale os.environ['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' + diff --git a/config/cross-android-armv7.cbc b/config/cross-android-armv7.cbc index 0188a963..9f0eb2f2 100644 --- a/config/cross-android-armv7.cbc +++ b/config/cross-android-armv7.cbc @@ -3,7 +3,7 @@ from cerbero.config import Platform, Architecture, Distro, DistroVersion target_platform = Platform.ANDROID target_distro = Distro.ANDROID -target_distro_version = DistroVersion.ANDROID_ICE_CREAM_SANDWICH +target_distro_version = DistroVersion.ANDROID_JELLY_BEAN target_arch = Architecture.ARMv7 #variants = ['nodebug'] diff --git a/config/cross-android-universal.cbc b/config/cross-android-universal.cbc index 2f50ba4c..b31ee158 100644 --- a/config/cross-android-universal.cbc +++ b/config/cross-android-universal.cbc @@ -3,12 +3,11 @@ from cerbero.config import Platform, Architecture, Distro, DistroVersion target_platform = Platform.ANDROID target_distro = Distro.ANDROID -target_distro_version = DistroVersion.ANDROID_ICE_CREAM_SANDWICH +target_distro_version = DistroVersion.ANDROID_JELLY_BEAN target_arch = Architecture.UNIVERSAL universal_archs = { # Path is relative to this file - Architecture.ARM: "cross-android.cbc", Architecture.ARMv7: "cross-android-armv7.cbc", Architecture.ARM64: "cross-android-arm64.cbc", Architecture.X86: "cross-android-x86.cbc", diff --git a/config/cross-android-x86.cbc b/config/cross-android-x86.cbc index 95ede106..1ed47611 100644 --- a/config/cross-android-x86.cbc +++ b/config/cross-android-x86.cbc @@ -3,7 +3,7 @@ from cerbero.config import Platform, Architecture, Distro, DistroVersion target_platform = Platform.ANDROID target_distro = Distro.ANDROID -target_distro_version = DistroVersion.ANDROID_ICE_CREAM_SANDWICH +target_distro_version = DistroVersion.ANDROID_JELLY_BEAN target_arch = Architecture.X86 #variants = ['nodebug'] diff --git a/config/cross-android.cbc b/config/cross-android.cbc deleted file mode 100644 index a7dba104..00000000 --- a/config/cross-android.cbc +++ /dev/null @@ -1,10 +0,0 @@ -import os -from cerbero.config import Platform, Architecture, Distro, DistroVersion - -target_platform = Platform.ANDROID -target_distro = Distro.ANDROID -target_distro_version = DistroVersion.ANDROID_ICE_CREAM_SANDWICH -target_arch = Architecture.ARM - -#variants = ['nodebug'] -allow_parallel_build = True |