@ -18,19 +18,28 @@ let
" x 8 6 _ 6 4 - u n k n o w n - l i n u x - g n u " = {
double = " l i n u x - x 8 6 _ 6 4 " ;
} ;
" a r m v 5 t e l - u n k n o w n - l i n u x - a n d r o i d e a b i " = {
arch = " a r m " ;
triple = " a r m - l i n u x - a n d r o i d e a b i " ;
gccVer = " 4 . 8 " ;
" i 6 8 6 - u n k n o w n - l i n u x - a n d r o i d " = {
triple = " i 6 8 6 - l i n u x - a n d r o i d " ;
arch = " x 8 6 " ;
toolchain = " x 8 6 " ;
gccVer = " 4 . 9 " ;
} ;
" x 8 6 _ 6 4 - u n k n o w n - l i n u x - a n d r o i d " = {
triple = " x 8 6 _ 6 4 - l i n u x - a n d r o i d " ;
arch = " x 8 6 _ 6 4 " ;
toolchain = " x 8 6 " ;
gccVer = " 4 . 9 " ;
} ;
" a r m v 7 a - u n k n o w n - l i n u x - a n d r o i d e a b i " = {
arch = " a r m " ;
triple = " a r m - l i n u x - a n d r o i d e a b i " ;
toolchain = " a r m - l i n u x - a n d r o i d e a b i " ;
gccVer = " 4 . 9 " ;
} ;
" a a r c h 6 4 - u n k n o w n - l i n u x - a n d r o i d " = {
arch = " a r m 6 4 " ;
triple = " a a r c h 6 4 - l i n u x - a n d r o i d " ;
toolchain = " a a r c h 6 4 - l i n u x - a n d r o i d " ;
gccVer = " 4 . 9 " ;
} ;
} . ${ config } or
@ -38,49 +47,49 @@ let
hostInfo = ndkInfoFun stdenv . hostPlatform ;
targetInfo = ndkInfoFun stdenv . targetPlatform ;
prefix = stdenv . lib . optionalString ( stdenv . targetPlatform != stdenv . hostPlatform ) ( stdenv . targetPlatform . config + " - " ) ;
in
rec {
# Misc tools
binaries = let
ndkBinDir =
" ${ androidndk } / l i b e x e c / a n d r o i d - s d k / n d k - b u n d l e / t o o l c h a i n s / ${ targetInfo . triple } - ${ targetInfo . gccVer } / p r e b u i l t / ${ hostInfo . double } / b i n " ;
ndkGCCLibDir =
" ${ androidndk } / l i b e x e c / a n d r o i d - s d k / n d k - b u n d l e / t o o l c h a i n s / ${ targetInfo . triple } - ${ targetInfo . gccVer } / p r e b u i l t / ${ hostInfo . double } / l i b / g c c / ${ targetInfo . triple } / 4 . 9 . x " ;
binaries = runCommand " n d k - g c c - b i n u t i l s " {
isClang = true ; # clang based cc, but bintools ld
nativeBuildInputs = [ makeWrapper ] ;
propgatedBuildInputs = [ androidndk ] ;
} ''
mkdir - p $ out/bin
in runCommand " n d k - g c c - b i n u t i l s " {
isGNU = true ; # for cc-wrapper
nativeBuildInputs = [ makeWrapper ] ;
propgatedBuildInputs = [ androidndk ] ;
} ''
mkdir - p $ out/bin
for prog in $ { ndkBinDir } / $ { targetInfo . triple } - * ; do
prog_suffix = $ ( basename $ prog | sed ' s / $ { targetInfo . triple } - // ' )
cat > $ out/bin / $ { stdenv . targetPlatform . config } - $ prog_suffix < < EOF
#! ${stdenv.shell} -e
$ prog " \$ @ "
EOF
chmod + x $ out/bin / $ { stdenv . targetPlatform . config } - $ prog_suffix
done
# llvm toolchain
for prog in $ { androidndk } /libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt / $ { hostInfo . double } /bin /* ; d o
ln - s $ prog $ out/bin / $ ( basename $ prog )
ln - s $ prog $ out/bin / $ { prefix } $ ( basename $ prog )
done
ln - s $ out/bin / $ { stdenv . targetPlatform . config } - ld $ out/bin/ld
ln - s $ { ndkGCCLibDir } $ out/lib
'' ;
# bintools toolchain
for prog in $ { androidndk } /libexec/android-sdk/ndk-bundle/toolchains / $ { targetInfo . toolchain } - $ { targetInfo . gccVer } /prebuilt / $ { hostInfo . double } /bin /* ; d o
prog_suffix = $ ( basename $ prog | sed ' s / $ { targetInfo . triple } - // ' )
ln - s $ prog $ out/bin / $ { stdenv . targetPlatform . config } - $ prog_suffix
done
# shitty googly wrappers
rm - f $ out/bin / $ { stdenv . targetPlatform . config } - gcc $ out/bin / $ { stdenv . targetPlatform . config } - g ++
'' ;
binutils = wrapBintoolsWith {
bintools = binaries ;
libc = targetAndroidndkPkgs . libraries ;
extraBuildCommands = ''
echo " - - b u i l d - i d " > > $ out/nix-support/libc-ldflags
'' ;
} ;
gcc = wrapCCWith {
clang = wrapCCWith {
cc = binaries ;
bintools = binutils ;
libc = targetAndroidndkPkgs . libraries ;
extraBuildCommands = ''
echo " - D _ _ A N D R O I D _ A P I _ _ = ${ stdenv . targetPlatform . sdkVer } " > > $ out/nix-support/cc-cflags
echo " - t a r g e t ${ stdenv . targetPlatform . config } " > > $ out/nix-support/cc-cflags
echo " - r e s o u r c e - d i r = $ ( e c h o ${ androidndk } / l i b e x e c / a n d r o i d - s d k / n d k - b u n d l e / t o o l c h a i n s / l l v m / p r e b u i l t / ${ hostInfo . double } / l i b * / c l a n g / * ) " > > $ out/nix-support/cc-cflags
echo " - - g c c - t o o l c h a i n = ${ androidndk } / l i b e x e c / a n d r o i d - s d k / n d k - b u n d l e / t o o l c h a i n s / ${ targetInfo . toolchain } - ${ targetInfo . gccVer } / p r e b u i l t / ${ hostInfo . double } " > > $ out/nix-support/cc-cflags
''
+ lib . optionalString stdenv . targetPlatform . isAarch32 ( let
p = stdenv . targetPlatform . platform . gcc or { }
@ -98,16 +107,10 @@ rec {
sed - E - i \
$ out/bin / $ { stdenv . targetPlatform . config } - cc \
$ out/bin / $ { stdenv . targetPlatform . config } - c ++ \
$ out/bin / $ { stdenv . targetPlatform . config } - gcc \
$ out/bin / $ { stdenv . targetPlatform . config } - g ++ \
$ out/bin / $ { stdenv . targetPlatform . config } - clang \
$ out/bin / $ { stdenv . targetPlatform . config } - clan g++ \
- e ' s | ^ ( extraBefore = ) \ ( ( . * ) \ ) $ | \ 1 ( \ 2 - Wl , - - fix-cortex-a8 $ { builtins . toString flags } ) | '
'' )
# GCC 4.9 is the first relase with "-fstack-protector"
+ lib . optionalString ( lib . versionOlder targetInfo . gccVer " 4 . 9 " ) ''
sed - E \
- i $ out/nix-support/add-hardening.sh \
- e ' s | ( - fstack-protector ) - strong | \ 1 | g'
'' ;
'' ) ;
} ;
# Bionic lib C and other libraries.
@ -115,17 +118,11 @@ rec {
# We use androidndk from the previous stage, else we waste time or get cycles
# cross-compiling packages to wrap incorrectly wrap binaries we don't include
# anyways.
libraries =
let
includePath = " ${ buildAndroidndk } / l i b e x e c / a n d r o i d - s d k / n d k - b u n d l e / s y s r o o t / u s r / i n c l u d e " ;
asmIncludePath = " ${ buildAndroidndk } / l i b e x e c / a n d r o i d - s d k / n d k - b u n d l e / s y s r o o t / u s r / i n c l u d e / ${ targetInfo . triple } " ;
libPath = " ${ buildAndroidndk } / l i b e x e c / a n d r o i d - s d k / n d k - b u n d l e / p l a t f o r m s / a n d r o i d - ${ stdenv . hostPlatform . sdkVer } / a r c h - ${ hostInfo . arch } / u s r / l i b / " ;
in
runCommand " b i o n i c - p r e b u i l t " { } ''
mkdir - p $ out
cp - r $ { includePath } $ out/include
chmod + w $ out/include
cp - r $ { asmIncludePath } /* $ o u t / i n c l u d e
ln - s $ { libPath } $ out/lib
'' ;
libraries = runCommand " b i o n i c - p r e b u i l t " { } ''
mkdir - p $ out
cp - r $ { buildAndroidndk } /libexec/android-sdk/ndk-bundle/sysroot/usr/include $ out/include
chmod + w $ out/include
cp - r $ { buildAndroidndk } /libexec/android-sdk/ndk-bundle/sysroot/usr/include / $ { targetInfo . triple } /* $ o u t / i n c l u d e
ln - s $ { buildAndroidndk } /libexec/android-sdk/ndk-bundle/platforms/android- $ { stdenv . hostPlatform . sdkVer } /arch- $ { hostInfo . arch } /usr/lib $ out/lib
'' ;
}