2014-11-24 08:16:08 +00:00
|
|
|
{ stdenv, fetchurl, zlib, ncurses, p7zip, lib, makeWrapper
|
|
|
|
, coreutils, file, findutils, gawk, gnugrep, gnused, jdk, which
|
2018-05-15 16:45:48 +01:00
|
|
|
, platformTools, python3, version, sha256
|
2014-04-20 10:29:10 +01:00
|
|
|
}:
|
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
2018-05-15 16:45:48 +01:00
|
|
|
name = "android-ndk-r${version}";
|
2018-05-17 16:22:27 +01:00
|
|
|
inherit version;
|
2014-04-20 10:29:10 +01:00
|
|
|
|
2018-05-15 15:58:37 +01:00
|
|
|
src = if stdenv.system == "x86_64-linux" then fetchurl {
|
2018-05-15 16:45:48 +01:00
|
|
|
url = "https://dl.google.com/android/repository/${name}-linux-x86_64.zip";
|
|
|
|
inherit sha256;
|
2018-05-15 15:58:37 +01:00
|
|
|
} else throw "platform ${stdenv.system} not supported!";
|
2014-04-20 10:29:10 +01:00
|
|
|
|
2014-11-24 08:16:08 +00:00
|
|
|
phases = "buildPhase";
|
2014-04-20 10:29:10 +01:00
|
|
|
|
2018-02-20 23:31:16 +00:00
|
|
|
nativeBuildInputs = [ p7zip makeWrapper ];
|
2014-11-10 22:54:44 +00:00
|
|
|
|
2014-11-24 08:16:08 +00:00
|
|
|
buildCommand = let
|
|
|
|
bin_path = "$out/bin";
|
|
|
|
pkg_path = "$out/libexec/${name}";
|
|
|
|
sed_script_1 =
|
|
|
|
"'s|^PROGDIR=`dirname $0`" +
|
|
|
|
"|PROGDIR=`dirname $(readlink -f $(which $0))`|'";
|
|
|
|
sed_script_2 =
|
|
|
|
"'s|^MYNDKDIR=`dirname $0`" +
|
|
|
|
"|MYNDKDIR=`dirname $(readlink -f $(which $0))`|'";
|
2016-04-13 13:53:51 +01:00
|
|
|
runtime_paths = (lib.makeBinPath [
|
2014-11-24 08:16:08 +00:00
|
|
|
coreutils file findutils
|
|
|
|
gawk gnugrep gnused
|
2018-05-15 16:45:48 +01:00
|
|
|
jdk python3 which
|
2014-11-24 08:16:08 +00:00
|
|
|
]) + ":${platformTools}/platform-tools";
|
|
|
|
in ''
|
2014-04-20 10:29:10 +01:00
|
|
|
set -x
|
2014-11-24 08:16:08 +00:00
|
|
|
mkdir -pv $out/libexec
|
|
|
|
cd $out/libexec
|
2014-11-10 22:54:44 +00:00
|
|
|
7z x $src
|
2014-09-25 10:59:16 +01:00
|
|
|
|
|
|
|
# so that it doesn't fail because of read-only permissions set
|
2014-11-24 08:16:08 +00:00
|
|
|
cd -
|
2018-05-15 16:45:48 +01:00
|
|
|
${if (version == "10e") then
|
|
|
|
''
|
|
|
|
patch -p1 \
|
|
|
|
--no-backup-if-mismatch \
|
|
|
|
-d $out/libexec/${name} < ${ ./make-standalone-toolchain_r10e.patch }
|
|
|
|
''
|
|
|
|
else
|
|
|
|
''
|
|
|
|
patchShebangs ${pkg_path}/build/tools/make-standalone-toolchain.sh
|
|
|
|
|
|
|
|
patch -p1 \
|
|
|
|
--no-backup-if-mismatch \
|
|
|
|
-d $out/libexec/${name} < ${ ./. + builtins.toPath ("/make_standalone_toolchain.py_" + "${version}" + ".patch") }
|
|
|
|
wrapProgram ${pkg_path}/build/tools/make_standalone_toolchain.py --prefix PATH : "${runtime_paths}"
|
|
|
|
''
|
|
|
|
}
|
2014-11-24 08:16:08 +00:00
|
|
|
cd ${pkg_path}
|
2014-09-25 10:59:16 +01:00
|
|
|
|
2014-04-20 10:29:10 +01:00
|
|
|
find $out \( \
|
|
|
|
\( -type f -a -name "*.so*" \) -o \
|
2015-09-06 09:21:43 +01:00
|
|
|
\( -type f -a -perm -0100 \) \
|
2015-04-26 18:54:51 +01:00
|
|
|
\) -exec patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-*so.? \
|
2016-07-07 17:23:25 +01:00
|
|
|
--set-rpath ${stdenv.lib.makeLibraryPath [ zlib.out ncurses ]} {} \;
|
2014-11-24 08:16:08 +00:00
|
|
|
# fix ineffective PROGDIR / MYNDKDIR determination
|
2018-05-15 16:45:48 +01:00
|
|
|
for i in ndk-build ${lib.optionalString (version == "10e") "ndk-gdb ndk-gdb-py"}
|
2014-11-24 08:16:08 +00:00
|
|
|
do
|
|
|
|
sed -i -e ${sed_script_1} $i
|
|
|
|
done
|
2018-05-15 16:45:48 +01:00
|
|
|
${lib.optionalString (version == "10e") ''
|
|
|
|
sed -i -e ${sed_script_2} ndk-which
|
|
|
|
# a bash script
|
|
|
|
patchShebangs ndk-which
|
|
|
|
''}
|
2017-08-17 16:46:01 +01:00
|
|
|
# wrap
|
2018-05-15 16:45:48 +01:00
|
|
|
for i in ndk-build ${lib.optionalString (version == "10e") "ndk-gdb ndk-gdb-py ndk-which"}
|
2017-08-17 16:46:01 +01:00
|
|
|
do
|
|
|
|
wrapProgram "$(pwd)/$i" --prefix PATH : "${runtime_paths}"
|
|
|
|
done
|
2014-11-24 08:16:08 +00:00
|
|
|
# make some executables available in PATH
|
|
|
|
mkdir -pv ${bin_path}
|
|
|
|
for i in \
|
2018-05-15 16:45:48 +01:00
|
|
|
ndk-build ${lib.optionalString (version == "10e") "ndk-depends ndk-gdb ndk-gdb-py ndk-gdb.py ndk-stack ndk-which"}
|
2014-11-24 08:16:08 +00:00
|
|
|
do
|
|
|
|
ln -sf ${pkg_path}/$i ${bin_path}/$i
|
|
|
|
done
|
2014-04-20 10:29:10 +01:00
|
|
|
'';
|
2016-08-02 17:06:29 +01:00
|
|
|
|
2018-05-15 16:45:48 +01:00
|
|
|
meta = {
|
|
|
|
platforms = stdenv.lib.platforms.linux;
|
|
|
|
hydraPlatforms = [];
|
|
|
|
};
|
2014-04-20 10:29:10 +01:00
|
|
|
}
|