diff --git a/toolchains/android-common/packages/openssl/build.sh b/toolchains/android-common/packages/openssl/build.sh index fb05eb2..dce4463 100755 --- a/toolchains/android-common/packages/openssl/build.sh +++ b/toolchains/android-common/packages/openssl/build.sh @@ -26,11 +26,10 @@ export RANLIB=ranlib if [ "$API" = "." ]; then # Standalone toolchain (even if merged) and_api= - export ANDROID_NDK_HOME=$TOOLCHAIN + export ANDROID_NDK_ROOT=$TOOLCHAIN else # Android fully unified toolchain and_api=-D__ANDROID_API__=$API - export ANDROID_NDK_HOME=${ANDROID_NDK_ROOT} fi ./Configure $ssl_target no-shared no-threads -fno-integrated-as $and_api --prefix=${PREFIX} --libdir=${PREFIX}/lib/${TARGET}/${API} diff --git a/toolchains/android-common/packages/openssl/patches/00_modernize_build_system.patch b/toolchains/android-common/packages/openssl/patches/00_modernize_build_system.patch new file mode 100644 index 0000000..a785551 --- /dev/null +++ b/toolchains/android-common/packages/openssl/patches/00_modernize_build_system.patch @@ -0,0 +1,286 @@ +From 79fd045374b72faccc75b046e069adde7d5feccf Mon Sep 17 00:00:00 2001 +From: Richard Levitte +Date: Sat, 29 Feb 2020 06:43:26 +0100 +Subject: [PATCH 1/3] Andoid cross compile: change ANDROID_NDK_HOME to + ANDROID_NDK_ROOT + +According to forum discussions with NDK developers, ANDROID_NDK_HOME +is used for something else. + +Fixes #11205 + +Reviewed-by: Matt Caswell +(Merged from https://github.com/openssl/openssl/pull/11206) +--- + Configurations/15-android.conf | 6 +++--- + NOTES.ANDROID | 12 ++++++------ + 2 files changed, 9 insertions(+), 9 deletions(-) + +diff --git a/Configurations/15-android.conf b/Configurations/15-android.conf +index 7b496a4529..d5021f68d0 100644 +--- a/Configurations/15-android.conf ++++ b/Configurations/15-android.conf +@@ -24,17 +24,17 @@ + + my $ndk_var; + my $ndk; +- foreach (qw(ANDROID_NDK_HOME ANDROID_NDK)) { ++ foreach (qw(ANDROID_NDK_ROOT ANDROID_NDK)) { + $ndk_var = $_; + $ndk = $ENV{$ndk_var}; + last if defined $ndk; + } +- die "\$ANDROID_NDK_HOME is not defined" if (!$ndk); ++ die "\$ANDROID_NDK_ROOT is not defined" if (!$ndk); + if (!-d "$ndk/platforms" && !-f "$ndk/AndroidVersion.txt") { + # $ndk/platforms is traditional "all-inclusive" NDK, while + # $ndk/AndroidVersion.txt is so-called standalone toolchain + # tailored for specific target down to API level. +- die "\$ANDROID_NDK_HOME=$ndk is invalid"; ++ die "\$ANDROID_NDK_ROOT=$ndk is invalid"; + } + $ndk = canonpath($ndk); + +diff --git a/NOTES.ANDROID b/NOTES.ANDROID +index 86459778fa..b057ff2757 100644 +--- a/NOTES.ANDROID ++++ b/NOTES.ANDROID +@@ -23,7 +23,7 @@ + platform. Though you still need to know the prefix to extend your PATH, + in order to invoke $(CROSS_COMPILE)gcc and company. (Configure will fail + and give you a hint if you get it wrong.) Apart from PATH adjustment +- you need to set ANDROID_NDK_HOME environment to point at NDK directory ++ you need to set ANDROID_NDK_ROOT environment to point at NDK directory + as /some/where/android-ndk-. Both variables are significant at both + configuration and compilation times. NDK customarily supports multiple + Android API levels, e.g. android-14, android-21, etc. By default latest +@@ -32,13 +32,13 @@ + target platform version. For example, to compile for ICS on ARM with + NDK 10d: + +- export ANDROID_NDK_HOME=/some/where/android-ndk-10d +- PATH=$ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin:$PATH ++ export ANDROID_NDK_ROOT=/some/where/android-ndk-10d ++ PATH=$ANDROID_NDK_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin:$PATH + ./Configure android-arm -D__ANDROID_API__=14 + make + + Caveat lector! Earlier OpenSSL versions relied on additional CROSS_SYSROOT +- variable set to $ANDROID_NDK_HOME/platforms/android-/arch- to ++ variable set to $ANDROID_NDK_ROOT/platforms/android-/arch- to + appoint headers-n-libraries' location. It's still recognized in order + to facilitate migration from older projects. However, since API level + appears in CROSS_SYSROOT value, passing -D__ANDROID_API__=N can be in +@@ -53,9 +53,9 @@ + + Another option is to create so called "standalone toolchain" tailored + for single specific platform including Android API level, and assign its +- location to ANDROID_NDK_HOME. In such case you have to pass matching ++ location to ANDROID_NDK_ROOT. In such case you have to pass matching + target name to Configure and shouldn't use -D__ANDROID_API__=N. PATH +- adjustment becomes simpler, $ANDROID_NDK_HOME/bin:$PATH suffices. ++ adjustment becomes simpler, $ANDROID_NDK_ROOT/bin:$PATH suffices. + + Running tests (on Linux) + ------------------------ +-- +2.29.2 + + +From 5420db1ac909a57c1bf451c27336abcb144d1ac5 Mon Sep 17 00:00:00 2001 +From: Richard Levitte +Date: Tue, 3 Mar 2020 22:55:09 +0100 +Subject: [PATCH 2/3] Configurations: Fix "android" configuration target + +This target gave '-pie' as a C flag when it should be a linker flag. +Additionally, we add '-fPIE' as C flag for binaries. + +Fixes #11237 + +Reviewed-by: Matt Caswell +(Merged from https://github.com/openssl/openssl/pull/11238) +--- + Configurations/15-android.conf | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/Configurations/15-android.conf b/Configurations/15-android.conf +index d5021f68d0..ea7785c663 100644 +--- a/Configurations/15-android.conf ++++ b/Configurations/15-android.conf +@@ -168,7 +168,8 @@ my %targets = ( + cppflags => add(sub { android_ndk()->{cppflags} }), + cxxflags => add(sub { android_ndk()->{cflags} }), + bn_ops => sub { android_ndk()->{bn_ops} }, +- bin_cflags => "-pie", ++ bin_cflags => "-fPIE", ++ bin_lflags => "-pie", + enable => [ ], + }, + "android-arm" => { +-- +2.29.2 + + +From c5051d5e0aa6019fb682fef8e3d237b20a2d562d Mon Sep 17 00:00:00 2001 +From: Fred Hornsey +Date: Tue, 17 Nov 2020 22:20:43 -0600 +Subject: [PATCH 3/3] Support for Android NDK r22-beta1 + +I think builds using standalone toolchain are fine so I left them alone, +but `Configure` will fail if using the NDK directly because the +`platforms` and `sysroot` directories were removed. + +If `sysroot` is missing, omit the `--sysroot` and `-gcc-toolchain` +arguments and use the triplet form clang command. + +Also since `platforms` was being used for the default API level, use +`meta/platforms.json` instead if needed. + +Reviewed-by: Matt Caswell +Reviewed-by: Paul Dale +Reviewed-by: Richard Levitte +(Merged from https://github.com/openssl/openssl/pull/13434) +--- + Configurations/15-android.conf | 82 +++++++++++++++++++++------------- + 1 file changed, 51 insertions(+), 31 deletions(-) + +diff --git a/Configurations/15-android.conf b/Configurations/15-android.conf +index ea7785c663..d96050a67e 100644 +--- a/Configurations/15-android.conf ++++ b/Configurations/15-android.conf +@@ -30,17 +30,17 @@ + last if defined $ndk; + } + die "\$ANDROID_NDK_ROOT is not defined" if (!$ndk); +- if (!-d "$ndk/platforms" && !-f "$ndk/AndroidVersion.txt") { +- # $ndk/platforms is traditional "all-inclusive" NDK, while +- # $ndk/AndroidVersion.txt is so-called standalone toolchain +- # tailored for specific target down to API level. ++ my $is_standalone_toolchain = -f "$ndk/AndroidVersion.txt"; ++ my $ndk_src_props = "$ndk/source.properties"; ++ my $is_ndk = -f $ndk_src_props; ++ if ($is_ndk == $is_standalone_toolchain) { + die "\$ANDROID_NDK_ROOT=$ndk is invalid"; + } + $ndk = canonpath($ndk); + + my $ndkver = undef; + +- if (open my $fh, "<$ndk/source.properties") { ++ if (open my $fh, "<$ndk_src_props") { + local $_; + while(<$fh>) { + if (m|Pkg\.Revision\s*=\s*([0-9]+)|) { +@@ -59,7 +59,7 @@ + if ($sysroot = $ENV{CROSS_SYSROOT}) { + $sysroot =~ m|/android-([0-9]+)/arch-(\w+)/?$|; + ($api, $arch) = ($1, $2); +- } elsif (-f "$ndk/AndroidVersion.txt") { ++ } elsif ($is_standalone_toolchain) { + $sysroot = "$ndk/sysroot"; + } else { + $api = "*"; +@@ -72,17 +72,31 @@ + } + } + +- # list available platforms (numerically) +- my @platforms = sort { $a =~ m/-([0-9]+)$/; my $aa = $1; +- $b =~ m/-([0-9]+)$/; $aa <=> $1; +- } glob("$ndk/platforms/android-$api"); +- die "no $ndk/platforms/android-$api" if ($#platforms < 0); ++ if (-d "$ndk/platforms") { ++ # list available platforms (numerically) ++ my @platforms = sort { $a =~ m/-([0-9]+)$/; my $aa = $1; ++ $b =~ m/-([0-9]+)$/; $aa <=> $1; ++ } glob("$ndk/platforms/android-$api"); ++ die "no $ndk/platforms/android-$api" if ($#platforms < 0); + +- $sysroot = "@platforms[$#platforms]/arch-$arch"; +- $sysroot =~ m|/android-([0-9]+)/arch-$arch|; +- $api = $1; ++ $sysroot = "@platforms[$#platforms]/arch-$arch"; ++ $sysroot =~ m|/android-([0-9]+)/arch-$arch|; ++ $api = $1; ++ } elsif ($api eq "*") { ++ # r22 Removed platforms dir, use this JSON file ++ my $path = "$ndk/meta/platforms.json"; ++ open my $fh, $path or die "Could not open '$path' $!"; ++ while (<$fh>) { ++ if (/"max": (\d+),/) { ++ $api = $1; ++ last; ++ } ++ } ++ close $fh; ++ } ++ die "Could not get default API Level" if ($api eq "*"); + } +- die "no sysroot=$sysroot" if (!-d $sysroot); ++ die "no sysroot=$sysroot" if (length $sysroot && !-d $sysroot); + + my $triarch = $triplet{$arch}; + my $cflags; +@@ -95,17 +109,21 @@ + my $arm = $ndkver > 16 ? "armv7a" : "armv5te"; + (my $tridefault = $triarch) =~ s/^arm-/$arm-/; + (my $tritools = $triarch) =~ s/(?:x|i6)86(_64)?-.*/x86$1/; +- $cflags .= " -target $tridefault " +- . "-gcc-toolchain \$($ndk_var)/toolchains" +- . "/$tritools-4.9/prebuilt/$host"; +- $user{CC} = "clang" if ($user{CC} !~ m|clang|); ++ if (length $sysroot) { ++ $cflags .= " -target $tridefault " ++ . "-gcc-toolchain \$($ndk_var)/toolchains" ++ . "/$tritools-4.9/prebuilt/$host"; ++ $user{CC} = "clang" if ($user{CC} !~ m|clang|); ++ } else { ++ $user{CC} = "$tridefault$api-clang"; ++ } + $user{CROSS_COMPILE} = undef; + if (which("llvm-ar") =~ m|^$ndk/.*/prebuilt/([^/]+)/|) { + $user{AR} = "llvm-ar"; + $user{ARFLAGS} = [ "rs" ]; + $user{RANLIB} = ":"; + } +- } elsif (-f "$ndk/AndroidVersion.txt") { #"standalone toolchain" ++ } elsif ($is_standalone_toolchain) { + my $cc = $user{CC} // "clang"; + # One can probably argue that both clang and gcc should be + # probed, but support for "standalone toolchain" was added +@@ -127,19 +145,21 @@ + $user{CROSS_COMPILE} = "$triarch-"; + } + +- if (!-d "$sysroot/usr/include") { +- my $incroot = "$ndk/sysroot/usr/include"; +- die "no $incroot" if (!-d $incroot); +- die "no $incroot/$triarch" if (!-d "$incroot/$triarch"); +- $incroot =~ s|^$ndk/||; +- $cppflags = "-D__ANDROID_API__=$api"; +- $cppflags .= " -isystem \$($ndk_var)/$incroot/$triarch"; +- $cppflags .= " -isystem \$($ndk_var)/$incroot"; ++ if (length $sysroot) { ++ if (!-d "$sysroot/usr/include") { ++ my $incroot = "$ndk/sysroot/usr/include"; ++ die "no $incroot" if (!-d $incroot); ++ die "no $incroot/$triarch" if (!-d "$incroot/$triarch"); ++ $incroot =~ s|^$ndk/||; ++ $cppflags = "-D__ANDROID_API__=$api"; ++ $cppflags .= " -isystem \$($ndk_var)/$incroot/$triarch"; ++ $cppflags .= " -isystem \$($ndk_var)/$incroot"; ++ } ++ $sysroot =~ s|^$ndk/||; ++ $sysroot = " --sysroot=\$($ndk_var)/$sysroot"; + } +- +- $sysroot =~ s|^$ndk/||; + $android_ndk = { +- cflags => "$cflags --sysroot=\$($ndk_var)/$sysroot", ++ cflags => $cflags . $sysroot, + cppflags => $cppflags, + bn_ops => $arch =~ m/64$/ ? "SIXTY_FOUR_BIT_LONG" + : "BN_LLONG", +-- +2.29.2 + diff --git a/toolchains/android/packages/ndk/build.sh b/toolchains/android/packages/ndk/build.sh index e20f090..2d814d4 100755 --- a/toolchains/android/packages/ndk/build.sh +++ b/toolchains/android/packages/ndk/build.sh @@ -17,15 +17,14 @@ do_sdk_install "ndk;${ANDROID_NDK_VERSION}" cd "ndk/${ANDROID_NDK_VERSION}" -# Don't cleanup as OpenSSL still need them # Cleanup unused parts of the NDK (which will get removed in future versions) -#rm -rf platforms sources/cxx-stl sysroot -#for d in toolchains/*; do -# if [ "$d" = "toolchains/llvm" ]; then -# continue -# fi -# rm -rf "$d" -#done +rm -rf platforms sources/cxx-stl sysroot +for d in toolchains/*; do + if [ "$d" = "toolchains/llvm" ]; then + continue + fi + rm -rf "$d" +done mkdir -p "${ANDROID_NDK_ROOT}/" # mv is faster than cp