3 # See NOTES.ANDROID for details. But don't miss platform-specific
9 arm => "arm-linux-androideabi",
10 arm64 => "aarch64-linux-android",
11 mips => "mipsel-linux-android",
12 mips64 => "mips64el-linux-android",
13 x86 => "i686-linux-android",
14 x86_64 => "x86_64-linux-android",
18 unless (%$android_ndk) {
19 my $ndk = $ENV{ANDROID_NDK};
20 die "\$ANDROID_NDK is not defined" if (!$ndk);
21 die "\$ANDROID_NDK=$ndk is invalid" if (!-d "$ndk/platforms");
25 if (!($sysroot = $ENV{CROSS_SYSROOT})) {
28 # see if user passed -D__ANDROID_API__=N
29 foreach (@{$useradd{CPPDEFINES}}) {
30 if (m|__ANDROID_API__=([0-9]+)|) {
36 # list available platforms (numerically)
37 my @platforms = sort { $a =~ m/-([0-9]+)$/; my $aa = $1;
38 $b =~ m/-([0-9]+)$/; $aa <=> $1;
39 } glob("$ndk/platforms/android-$api");
40 die "no $ndk/platforms/android-$api" if ($#platforms < 0);
42 $config{target} =~ m|[^-]+-([^-]+)$|; # split on dash
43 $sysroot = "@platforms[$#platforms]/arch-$1";
45 die "no sysroot=$sysroot" if (!-d $sysroot);
47 $sysroot =~ m|/android-([0-9]+)/arch-(\w+)/?$|;
48 my ($api, $arch) = ($1, $2);
50 my $triarch = $triplet{$arch};
51 my $cflags = "-Wa,--noexecstack";
54 # see if user passed CC=clang
55 if ($user{CC} eq "clang") {
56 if (which("clang") !~ m|^$ndk/.*/prebuilt/([^/]+)/|) {
57 die "no NDK clang on \$PATH";
60 # harmonize with gcc default
61 (my $tridefault = $triarch) =~ s/^arm-/armv5te-/;
62 (my $tritools = $triarch) =~ s/(?:x|i6)86(_64)?-.*/x86$1/;
63 $cflags .= " -target $tridefault "
64 . "-gcc-toolchain \$(ANDROID_NDK)/toolchains"
65 . "/$tritools-4.9/prebuilt/$host";
66 $user{CROSS_COMPILE} = undef;
68 $cflags .= " -mandroid";
69 $user{CROSS_COMPILE} = "$triarch-";
72 if (!-d "$sysroot/usr/include") {
73 my $incroot = "$ndk/sysroot/usr/include";
74 die "no $incroot" if (!-d $incroot);
75 die "no $incroot/$triarch" if (!-d "$incroot/$triarch");
76 $incroot =~ s|^$ndk/||;
77 $cppflags = "-D__ANDROID_API__=$api";
78 $cppflags .= " -isystem \$(ANDROID_NDK)/$incroot/$triarch";
79 $cppflags .= " -isystem \$(ANDROID_NDK)/$incroot";
82 $sysroot =~ s|^$ndk/||;
84 cflags => "$cflags --sysroot=\$(ANDROID_NDK)/$sysroot",
85 cppflags => $cppflags,
86 bn_ops => $arch =~ m/64$/ ? "SIXTY_FOUR_BIT_LONG"
97 inherit_from => [ "linux-generic32" ],
99 ################################################################
100 # Special note about -pie. The underlying reason is that
101 # Lollipop refuses to run non-PIE. But what about older systems
102 # and NDKs? -fPIC was never problem, so the only concern is -pie.
103 # Older toolchains, e.g. r4, appear to handle it and binaries
104 # turn out mostly functional. "Mostly" means that oldest
105 # Androids, such as Froyo, fail to handle executable, but newer
106 # systems are perfectly capable of executing binaries targeting
107 # Froyo. Keep in mind that in the nutshell Android builds are
108 # about JNI, i.e. shared libraries, not applications.
109 cflags => add(sub { android_ndk()->{cflags} }),
110 cppflags => add(sub { android_ndk()->{cppflags} }),
111 cxxflags => add(sub { android_ndk()->{cflags} }),
112 bn_ops => sub { android_ndk()->{bn_ops} },
113 bin_cflags => "-pie",
116 ################################################################
117 # Contemporary Android applications can provide multiple JNI
118 # providers in .apk, targeting multiple architectures. Among
119 # them there is "place" for two ARM flavours: generic eabi and
120 # armv7-a/hard-float. However, it should be noted that OpenSSL's
121 # ability to engage NEON is not constrained by ABI choice, nor
122 # is your ability to call OpenSSL from your application code
123 # compiled with floating-point ABI other than default 'soft'.
124 # (Latter thanks to __attribute__((pcs("aapcs"))) declaration.)
125 # This means that choice of ARM libraries you provide in .apk
126 # is driven by application needs. For example if application
127 # itself benefits from NEON or is floating-point intensive, then
128 # it might be appropriate to provide both libraries. Otherwise
129 # just generic eabi would do. But in latter case it would be
132 # ./Configure android-arm -D__ARM_MAX_ARCH__=8
134 # in order to build "universal" binary and allow OpenSSL take
135 # advantage of NEON when it's available.
137 # Keep in mind that (just like with linux-armv4) we rely on
138 # compiler defaults, which is not necessarily what you had
139 # in mind, in which case you would have to pass additional
140 # -march and/or -mfloat-abi flags. NDK defaults to armv5te.
141 # Some NDK versions reportedly require additional -latomic.
143 inherit_from => [ "android", asm("armv4_asm") ],
144 bn_ops => add("RC4_CHAR"),
147 inherit_from => [ "android", asm("aarch64_asm") ],
148 bn_ops => add("RC4_CHAR"),
149 perlasm_scheme => "linux64",
153 inherit_from => [ "android", asm("mips32_asm") ],
154 bn_ops => add("RC4_CHAR"),
155 perlasm_scheme => "o32",
157 "android-mips64" => {
158 ################################################################
159 # You are more than likely have to specify target processor
160 # on ./Configure command line. Trouble is that toolchain's
161 # default is MIPS64r6 (at least in r10d), but there are no
162 # such processors around (or they are too rare to spot one).
163 # Actual problem is that MIPS64r6 is binary incompatible
164 # with previous MIPS ISA versions, in sense that unlike
165 # prior versions original MIPS binary code will fail.
167 inherit_from => [ "android", asm("mips64_asm") ],
168 bn_ops => add("RC4_CHAR"),
169 perlasm_scheme => "64",
173 inherit_from => [ "android", asm("x86_asm") ],
174 CFLAGS => add(picker(release => "-fomit-frame-pointer")),
175 bn_ops => add("RC4_INT"),
176 perlasm_scheme => "android",
178 "android-x86_64" => {
179 inherit_from => [ "android", asm("x86_64_asm") ],
180 bn_ops => add("RC4_INT"),
181 perlasm_scheme => "elf",
184 ####################################################################
185 # Backward compatible targets, (might) requre $CROSS_SYSROOT
187 "android-armeabi" => {
188 inherit_from => [ "android-arm" ],
191 inherit_from => [ "android" ],
193 "android64-aarch64" => {
194 inherit_from => [ "android-arm64" ],
196 "android64-x86_64" => {
197 inherit_from => [ "android-x86_64" ],
199 "android64-mips64" => {
200 inherit_from => [ "android-mips64" ],