|
29 | 29 | $ndk = $ENV{$ndk_var};
|
30 | 30 | last if defined $ndk;
|
31 | 31 | }
|
32 |
| - die "\$ANDROID_NDK_HOME is not defined" if (!$ndk); |
33 |
| - if (!-d "$ndk/platforms" && !-f "$ndk/AndroidVersion.txt") { |
34 |
| - # $ndk/platforms is traditional "all-inclusive" NDK, while |
35 |
| - # $ndk/AndroidVersion.txt is so-called standalone toolchain |
36 |
| - # tailored for specific target down to API level. |
| 32 | + die "\$ANDROID_NDK_HOME is not defined" if (!$ndk); |
| 33 | + my $is_standalone_toolchain = -f "$ndk/AndroidVersion.txt"; |
| 34 | + my $ndk_src_props = "$ndk/source.properties"; |
| 35 | + my $is_ndk = -f $ndk_src_props; |
| 36 | + if ($is_ndk == $is_standalone_toolchain) { |
37 | 37 | die "\$ANDROID_NDK_HOME=$ndk is invalid";
|
38 | 38 | }
|
39 | 39 | $ndk = canonpath($ndk);
|
40 | 40 |
|
41 | 41 | my $ndkver = undef;
|
42 | 42 |
|
43 |
| - if (open my $fh, "<$ndk/source.properties") { |
| 43 | + if (open my $fh, "<$ndk_src_props") { |
44 | 44 | local $_;
|
45 | 45 | while(<$fh>) {
|
46 | 46 | if (m|Pkg\.Revision\s*=\s*([0-9]+)|) {
|
|
59 | 59 | if ($sysroot = $ENV{CROSS_SYSROOT}) {
|
60 | 60 | $sysroot =~ m|/android-([0-9]+)/arch-(\w+)/?$|;
|
61 | 61 | ($api, $arch) = ($1, $2);
|
62 |
| - } elsif (-f "$ndk/AndroidVersion.txt") { |
| 62 | + } elsif ($is_standalone_toolchain) { |
63 | 63 | $sysroot = "$ndk/sysroot";
|
64 | 64 | } else {
|
65 | 65 | $api = "*";
|
|
72 | 72 | }
|
73 | 73 | }
|
74 | 74 |
|
75 |
| - # list available platforms (numerically) |
76 |
| - my @platforms = sort { $a =~ m/-([0-9]+)$/; my $aa = $1; |
77 |
| - $b =~ m/-([0-9]+)$/; $aa <=> $1; |
78 |
| - } glob("$ndk/platforms/android-$api"); |
79 |
| - die "no $ndk/platforms/android-$api" if ($#platforms < 0); |
| 75 | + if (-d "$ndk/platforms") { |
| 76 | + # list available platforms (numerically) |
| 77 | + my @platforms = sort { $a =~ m/-([0-9]+)$/; my $aa = $1; |
| 78 | + $b =~ m/-([0-9]+)$/; $aa <=> $1; |
| 79 | + } glob("$ndk/platforms/android-$api"); |
| 80 | + die "no $ndk/platforms/android-$api" if ($#platforms < 0); |
80 | 81 |
|
81 |
| - $sysroot = "@platforms[$#platforms]/arch-$arch"; |
82 |
| - $sysroot =~ m|/android-([0-9]+)/arch-$arch|; |
83 |
| - $api = $1; |
| 82 | + $sysroot = "@platforms[$#platforms]/arch-$arch"; |
| 83 | + $sysroot =~ m|/android-([0-9]+)/arch-$arch|; |
| 84 | + $api = $1; |
| 85 | + } elsif ($api eq "*") { |
| 86 | + # r22 Removed platforms dir, use this JSON file |
| 87 | + my $path = "$ndk/meta/platforms.json"; |
| 88 | + open my $fh, $path or die "Could not open '$path' $!"; |
| 89 | + while (<$fh>) { |
| 90 | + if (/"max": (\d+),/) { |
| 91 | + $api = $1; |
| 92 | + last; |
| 93 | + } |
| 94 | + } |
| 95 | + close $fh; |
| 96 | + } |
| 97 | + die "Could not get default API Level" if ($api eq "*"); |
84 | 98 | }
|
85 |
| - die "no sysroot=$sysroot" if (!-d $sysroot); |
| 99 | + die "no sysroot=$sysroot" if (length $sysroot && !-d $sysroot); |
86 | 100 |
|
87 | 101 | my $triarch = $triplet{$arch};
|
88 | 102 | my $cflags;
|
|
95 | 109 | my $arm = $ndkver > 16 ? "armv7a" : "armv5te";
|
96 | 110 | (my $tridefault = $triarch) =~ s/^arm-/$arm-/;
|
97 | 111 | (my $tritools = $triarch) =~ s/(?:x|i6)86(_64)?-.*/x86$1/;
|
98 |
| - $cflags .= " -target $tridefault " |
99 |
| - . "-gcc-toolchain \$($ndk_var)/toolchains" |
100 |
| - . "/$tritools-4.9/prebuilt/$host"; |
101 |
| - $user{CC} = "clang" if ($user{CC} !~ m|clang|); |
| 112 | + if (length $sysroot) { |
| 113 | + $cflags .= " -target $tridefault " |
| 114 | + . "-gcc-toolchain \$($ndk_var)/toolchains" |
| 115 | + . "/$tritools-4.9/prebuilt/$host"; |
| 116 | + $user{CC} = "clang" if ($user{CC} !~ m|clang|); |
| 117 | + } else { |
| 118 | + $user{CC} = "$tridefault$api-clang"; |
| 119 | + } |
102 | 120 | $user{CROSS_COMPILE} = undef;
|
103 | 121 | if (which("llvm-ar") =~ m|^$ndk/.*/prebuilt/([^/]+)/|) {
|
104 | 122 | $user{AR} = "llvm-ar";
|
105 | 123 | $user{ARFLAGS} = [ "rs" ];
|
106 | 124 | $user{RANLIB} = ":";
|
107 | 125 | }
|
108 |
| - } elsif (-f "$ndk/AndroidVersion.txt") { #"standalone toolchain" |
| 126 | + } elsif ($is_standalone_toolchain) { |
109 | 127 | my $cc = $user{CC} // "clang";
|
110 | 128 | # One can probably argue that both clang and gcc should be
|
111 | 129 | # probed, but support for "standalone toolchain" was added
|
|
127 | 145 | $user{CROSS_COMPILE} = "$triarch-";
|
128 | 146 | }
|
129 | 147 |
|
130 |
| - if (!-d "$sysroot/usr/include") { |
131 |
| - my $incroot = "$ndk/sysroot/usr/include"; |
132 |
| - die "no $incroot" if (!-d $incroot); |
133 |
| - die "no $incroot/$triarch" if (!-d "$incroot/$triarch"); |
134 |
| - $incroot =~ s|^$ndk/||; |
135 |
| - $cppflags = "-D__ANDROID_API__=$api"; |
136 |
| - $cppflags .= " -isystem \$($ndk_var)/$incroot/$triarch"; |
137 |
| - $cppflags .= " -isystem \$($ndk_var)/$incroot"; |
| 148 | + if (length $sysroot) { |
| 149 | + if (!-d "$sysroot/usr/include") { |
| 150 | + my $incroot = "$ndk/sysroot/usr/include"; |
| 151 | + die "no $incroot" if (!-d $incroot); |
| 152 | + die "no $incroot/$triarch" if (!-d "$incroot/$triarch"); |
| 153 | + $incroot =~ s|^$ndk/||; |
| 154 | + $cppflags = "-D__ANDROID_API__=$api"; |
| 155 | + $cppflags .= " -isystem \$($ndk_var)/$incroot/$triarch"; |
| 156 | + $cppflags .= " -isystem \$($ndk_var)/$incroot"; |
| 157 | + } |
| 158 | + $sysroot =~ s|^$ndk/||; |
| 159 | + $sysroot = " --sysroot=\$($ndk_var)/$sysroot"; |
138 | 160 | }
|
139 |
| - |
140 |
| - $sysroot =~ s|^$ndk/||; |
141 | 161 | $android_ndk = {
|
142 |
| - cflags => "$cflags --sysroot=\$($ndk_var)/$sysroot", |
| 162 | + cflags => $cflags . $sysroot, |
143 | 163 | cppflags => $cppflags,
|
144 | 164 | bn_ops => $arch =~ m/64$/ ? "SIXTY_FOUR_BIT_LONG"
|
145 | 165 | : "BN_LLONG",
|
|
0 commit comments