@@ -1,4 +1,6 @@
1−{ stdenv, fetchurl, zlib, ncurses, p7zip
1+{ stdenv, fetchurl, zlib, ncurses, p7zip, lib, makeWrapper
2+, coreutils, file, findutils, gawk, gnugrep, gnused, jdk, which
3+, platformTools
24}:
35
46assert stdenv.isLinux;
@@ -17,23 +19,62 @@ stdenv.mkDerivation rec {
1719 }
1820 else throw "platform ${stdenv.system} not supported!";
1921
20− phases = "installPhase";
22+ phases = "buildPhase";
2123
22− buildInputs = [ p7zip ];
24+ buildInputs = [ p7zip makeWrapper ];
2325
24− installPhase = ''
26+ buildCommand = let
27+ bin_path = "$out/bin";
28+ pkg_path = "$out/libexec/${name}";
29+ sed_script_1 =
30+ "'s|^PROGDIR=`dirname $0`" +
31+ "|PROGDIR=`dirname $(readlink -f $(which $0))`|'";
32+ sed_script_2 =
33+ "'s|^MYNDKDIR=`dirname $0`" +
34+ "|MYNDKDIR=`dirname $(readlink -f $(which $0))`|'";
35+ runtime_paths = (lib.makeSearchPath "bin" [
36+ coreutils file findutils
37+ gawk gnugrep gnused
38+ jdk
39+ which
40+ ]) + ":${platformTools}/platform-tools";
41+ in ''
2542 set -x
26− mkdir -pv $out
43+ mkdir -pv $out/libexec
44+ cd $out/libexec
2745 7z x $src
28− mv */* $out
2946
3047 # so that it doesn't fail because of read-only permissions set
31− patch -p1 -d $out < ${ ./make-standalone-toolchain.patch }
48+ cd -
49+ patch -p1 \
50+ --no-backup-if-mismatch \
51+ -d $out/libexec/${name} < ${ ./make-standalone-toolchain.patch }
52+ cd ${pkg_path}
3253
3354 find $out \( \
3455 \( -type f -a -name "*.so*" \) -o \
35− \( -type f -a -perm +0100 \) \
56+ \( -type f -a -perm /0100 \) \
3657 \) -exec patchelf --set-interpreter ${stdenv.gcc.libc}/lib/ld-*so.? \
37− --set-rpath ${zlib}/lib:${ncurses}/lib {} \;
58+ --set-rpath ${zlib}/lib:${ncurses}/lib {} \;
59+ # fix ineffective PROGDIR / MYNDKDIR determination
60+ for i in ndk-build ndk-gdb ndk-gdb-py
61+ do
62+ sed -i -e ${sed_script_1} $i
63+ done
64+ sed -i -e ${sed_script_2} ndk-which
65+ # a bash script
66+ patchShebangs ndk-which
67+ # make some executables available in PATH
68+ mkdir -pv ${bin_path}
69+ for i in \
70+ ndk-build ndk-depends ndk-gdb ndk-gdb-py ndk-gdb.py ndk-stack ndk-which
71+ do
72+ ln -sf ${pkg_path}/$i ${bin_path}/$i
73+ done
74+ # wrap
75+ for i in ndk-build ndk-gdb ndk-gdb-py ndk-which
76+ do
77+ wrapProgram "${bin_path}/$i" --prefix PATH : "${runtime_paths}"
78+ done
3879 '';
3980}