From bf84e4871df42b186cb3a75756bdd48e7ddf4f71 Mon Sep 17 00:00:00 2001 From: Chen Jie Date: Wed, 3 Apr 2013 10:42:00 +0800 Subject: [PATCH 1/2] Android: add support for llvm toolchain --- cerbero/config.py | 2 +- config/android.config | 38 +++++++++++++++++++++++++++++--------- config/cross-android.cbc | 1 + 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/cerbero/config.py b/cerbero/config.py index 48be783..a8ab78d 100644 --- a/cerbero/config.py +++ b/cerbero/config.py @@ -81,7 +81,7 @@ class Config (object): 'universal_archs', 'osx_target_sdk_version', 'variants', 'build_tools_prefix', 'build_tools_sources', 'build_tools_cache', 'home_dir', 'recipes_commits', - 'ios_platform'] + 'ios_platform', 'use_llvm'] def __init__(self): self._check_uninstalled() diff --git a/config/android.config b/config/android.config index d1bb647..d480876 100644 --- a/config/android.config +++ b/config/android.config @@ -19,7 +19,10 @@ else: if not toolchain_prefix: toolchain_prefix = os.path.expanduser('~/cerbero/android-ndk-r8b') -toolchain_path = '%s/toolchains/%s/prebuilt/linux-x86/bin' % (toolchain_prefix, tc_path) +gcc_toolchain = '%s/toolchains/%s/prebuilt/linux-x86' % (toolchain_prefix, tc_path) +toolchain = gcc_toolchain +if use_llvm: + toolchain = '%s/toolchains/llvm-3.1/prebuilt/linux-x86' % toolchain_prefix if target_distro_version == DistroVersion.ANDROID_GINGERBREAD: v = '9' @@ -46,10 +49,19 @@ ldflags = '--sysroot=%s -fPIC -Wl,-no-undefined -Wl,-z,noexecstack -Wl,-z,relro # from android-ndk-r8b/toolchains/$NAME-$VERSION/setup.mk if target_arch in [Architecture.ARM, Architecture.ARMv7]: defines += ' -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ ' - cflags += ' -mthumb -fstack-protector -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 ' + cflags += ' -mthumb -fstack-protector -fomit-frame-pointer -fno-strict-aliasing ' + + if use_llvm: + cflags += ' -gcc-toolchain %s' % gcc_toolchain + else: + cflags += ' -finline-limit=64' if target_arch == Architecture.ARM: + cflags += use_llvm and ' -target armv5te-none-linux-androideabi' or '' + ldflags += use_llvm and ' -target armv5te-none-linux-androideabi' or '' cflags += ' -march=armv5te -mtune=xscale -msoft-float' elif target_arch == Architecture.ARMv7: + cflags += use_llvm and ' -target armv7-none-linux-androideabi' or '' + ldflags += use_llvm and ' -target armv5te-none-linux-androideabi' or '' cflags += ' -march=armv7-a -mfloat-abi=softfp -mfpu=vfp' ldflags += " -Wl,--fix-cortex-a8 " if target_arch == Architecture.X86: @@ -65,19 +77,27 @@ os.environ['LDFLAGS'] = '%s' % (ldflags,) def cmd(command): return '%s-%s' % (tools_prefix, command) -os.environ['CC']= '%s%s' % (ccache, cmd('gcc')) -os.environ['CC'] += ' -fuse-ld=gold' -os.environ['CXX']= '%s%s' % (ccache, cmd('g++')) -os.environ['CXX'] += ' -fuse-ld=gold' -os.environ['LD']= cmd('ld.gold') -os.environ['CPP']= cmd('cpp') +if use_llvm: + os.environ['CC']= '%s%s' % (ccache, 'clang') + os.environ['CXX']= '%s%s' % (ccache, 'clang++') + os.environ['LD']= 'llvm-link' + os.environ['CPP']= 'clang -E' +else: + os.environ['CC']= '%s%s' % (ccache, cmd('gcc')) + os.environ['CC'] += ' -fuse-ld=gold' + os.environ['CXX']= '%s%s' % (ccache, cmd('g++')) + os.environ['CXX'] += ' -fuse-ld=gold' + os.environ['LD']= cmd('ld.gold') + os.environ['CPP']= cmd('cpp') os.environ['RANLIB']= cmd('ranlib') os.environ['AR']= cmd('ar') os.environ['AS']= cmd('as') os.environ['NM']= cmd('nm') os.environ['STRIP']= cmd('strip') -os.environ['PATH'] = '%s:%s:%s' % (toolchain_prefix, toolchain_path, os.environ['PATH']) +os.environ['PATH'] = '%s:%s/bin:%s' % (toolchain_prefix, gcc_toolchain, os.environ['PATH']) +if use_llvm: + os.environ['PATH'] = '%s/bin:%s' % (toolchain, 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) diff --git a/config/cross-android.cbc b/config/cross-android.cbc index 4376af1..d4542df 100644 --- a/config/cross-android.cbc +++ b/config/cross-android.cbc @@ -7,4 +7,5 @@ target_distro_version = DistroVersion.ANDROID_GINGERBREAD target_arch = Architecture.ARM host = "arm-linux-androideabi" +use_llvm = False #variants = ['nodebug'] -- 1.8.1.4