]> git.ipfire.org Git - thirdparty/openssl.git/blob - Configurations/15-android.conf
Style: ssl.h
[thirdparty/openssl.git] / Configurations / 15-android.conf
1 #### Android...
2 #
3 # See NOTES.ANDROID for details, and don't miss platform-specific
4 # comments below...
5
6 {
7 my $android_ndk = {};
8 my %triplet = (
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",
15 );
16
17 sub android_ndk {
18 unless (%$android_ndk) {
19 if ($now_printing =~ m|^android|) {
20 return $android_ndk = { bn_ops => "BN_AUTO" };
21 }
22
23 my $ndk = $ENV{ANDROID_NDK};
24 die "\$ANDROID_NDK is not defined" if (!$ndk);
25 die "\$ANDROID_NDK=$ndk is invalid" if (!-d "$ndk/platforms");
26
27 my $ndkver = undef;
28
29 if (open my $fh, "<$ndk/source.properties") {
30 local $_;
31 while(<$fh>) {
32 if (m|Pkg\.Revision\s*=\s*([0-9]+)|) {
33 $ndkver = $1;
34 last;
35 }
36 }
37 close $fh;
38 }
39
40 my $sysroot;
41
42 if (!($sysroot = $ENV{CROSS_SYSROOT})) {
43 my $api = "*";
44
45 # see if user passed -D__ANDROID_API__=N
46 foreach (@{$useradd{CPPDEFINES}}, @{$user{CPPFLAGS}}) {
47 if (m|__ANDROID_API__=([0-9]+)|) {
48 $api = $1;
49 last;
50 }
51 }
52
53 # list available platforms (numerically)
54 my @platforms = sort { $a =~ m/-([0-9]+)$/; my $aa = $1;
55 $b =~ m/-([0-9]+)$/; $aa <=> $1;
56 } glob("$ndk/platforms/android-$api");
57 die "no $ndk/platforms/android-$api" if ($#platforms < 0);
58
59 $config{target} =~ m|[^-]+-([^-]+)$|; # split on dash
60 $sysroot = "@platforms[$#platforms]/arch-$1";
61 }
62 die "no sysroot=$sysroot" if (!-d $sysroot);
63
64 $sysroot =~ m|/android-([0-9]+)/arch-(\w+)/?$|;
65 my ($api, $arch) = ($1, $2);
66
67 my $triarch = $triplet{$arch};
68 my $cflags = "-Wa,--noexecstack";
69 my $cppflags;
70
71 # see if there is NDK clang on $PATH
72 if (which("clang") =~ m|^$ndk/.*/prebuilt/([^/]+)/|) {
73 my $host=$1;
74 # harmonize with gcc default
75 my $arm = $ndkver > 16 ? "armv7a" : "armv5te";
76 (my $tridefault = $triarch) =~ s/^arm-/$arm-/;
77 (my $tritools = $triarch) =~ s/(?:x|i6)86(_64)?-.*/x86$1/;
78 $cflags .= " -target $tridefault "
79 . "-gcc-toolchain \$(ANDROID_NDK)/toolchains"
80 . "/$tritools-4.9/prebuilt/$host";
81 $user{CC} = "clang" if ($user{CC} !~ m|clang|);
82 $user{CROSS_COMPILE} = undef;
83 } elsif ($user{CC} eq "clang") {
84 die "no NDK clang on \$PATH";
85 } else {
86 if (which("$triarch-gcc") !~ m|^$ndk/.*/prebuilt/([^/]+)/|) {
87 die "no NDK $triarch-gcc on \$PATH";
88 }
89 $cflags .= " -mandroid";
90 $user{CROSS_COMPILE} = "$triarch-";
91 }
92
93 if (!-d "$sysroot/usr/include") {
94 my $incroot = "$ndk/sysroot/usr/include";
95 die "no $incroot" if (!-d $incroot);
96 die "no $incroot/$triarch" if (!-d "$incroot/$triarch");
97 $incroot =~ s|^$ndk/||;
98 $cppflags = "-D__ANDROID_API__=$api";
99 $cppflags .= " -isystem \$(ANDROID_NDK)/$incroot/$triarch";
100 $cppflags .= " -isystem \$(ANDROID_NDK)/$incroot";
101 }
102
103 $sysroot =~ s|^$ndk/||;
104 $android_ndk = {
105 cflags => "$cflags --sysroot=\$(ANDROID_NDK)/$sysroot",
106 cppflags => $cppflags,
107 bn_ops => $arch =~ m/64$/ ? "SIXTY_FOUR_BIT_LONG"
108 : "BN_LLONG",
109 };
110 }
111
112 return $android_ndk;
113 }
114 }
115
116 my %targets = (
117 "android" => {
118 inherit_from => [ "linux-generic32" ],
119 template => 1,
120 ################################################################
121 # Special note about -pie. The underlying reason is that
122 # Lollipop refuses to run non-PIE. But what about older systems
123 # and NDKs? -fPIC was never problem, so the only concern is -pie.
124 # Older toolchains, e.g. r4, appear to handle it and binaries
125 # turn out mostly functional. "Mostly" means that oldest
126 # Androids, such as Froyo, fail to handle executable, but newer
127 # systems are perfectly capable of executing binaries targeting
128 # Froyo. Keep in mind that in the nutshell Android builds are
129 # about JNI, i.e. shared libraries, not applications.
130 cflags => add(sub { android_ndk()->{cflags} }),
131 cppflags => add(sub { android_ndk()->{cppflags} }),
132 cxxflags => add(sub { android_ndk()->{cflags} }),
133 bn_ops => sub { android_ndk()->{bn_ops} },
134 bin_cflags => "-pie",
135 },
136 "android-arm" => {
137 ################################################################
138 # Contemporary Android applications can provide multiple JNI
139 # providers in .apk, targeting multiple architectures. Among
140 # them there is "place" for two ARM flavours: generic eabi and
141 # armv7-a/hard-float. However, it should be noted that OpenSSL's
142 # ability to engage NEON is not constrained by ABI choice, nor
143 # is your ability to call OpenSSL from your application code
144 # compiled with floating-point ABI other than default 'soft'.
145 # (Latter thanks to __attribute__((pcs("aapcs"))) declaration.)
146 # This means that choice of ARM libraries you provide in .apk
147 # is driven by application needs. For example if application
148 # itself benefits from NEON or is floating-point intensive, then
149 # it might be appropriate to provide both libraries. Otherwise
150 # just generic eabi would do. But in latter case it would be
151 # appropriate to
152 #
153 # ./Configure android-arm -D__ARM_MAX_ARCH__=8
154 #
155 # in order to build "universal" binary and allow OpenSSL take
156 # advantage of NEON when it's available.
157 #
158 # Keep in mind that (just like with linux-armv4) we rely on
159 # compiler defaults, which is not necessarily what you had
160 # in mind, in which case you would have to pass additional
161 # -march and/or -mfloat-abi flags. NDK defaults to armv5te.
162 # Newer NDK versions reportedly require additional -latomic.
163 #
164 inherit_from => [ "android", asm("armv4_asm") ],
165 bn_ops => add("RC4_CHAR"),
166 },
167 "android-arm64" => {
168 inherit_from => [ "android", asm("aarch64_asm") ],
169 bn_ops => add("RC4_CHAR"),
170 perlasm_scheme => "linux64",
171 },
172
173 "android-mips" => {
174 inherit_from => [ "android", asm("mips32_asm") ],
175 bn_ops => add("RC4_CHAR"),
176 perlasm_scheme => "o32",
177 },
178 "android-mips64" => {
179 ################################################################
180 # You are more than likely have to specify target processor
181 # on ./Configure command line. Trouble is that toolchain's
182 # default is MIPS64r6 (at least in r10d), but there are no
183 # such processors around (or they are too rare to spot one).
184 # Actual problem is that MIPS64r6 is binary incompatible
185 # with previous MIPS ISA versions, in sense that unlike
186 # prior versions original MIPS binary code will fail.
187 #
188 inherit_from => [ "android", asm("mips64_asm") ],
189 bn_ops => add("RC4_CHAR"),
190 perlasm_scheme => "64",
191 },
192
193 "android-x86" => {
194 inherit_from => [ "android", asm("x86_asm") ],
195 CFLAGS => add(picker(release => "-fomit-frame-pointer")),
196 bn_ops => add("RC4_INT"),
197 perlasm_scheme => "android",
198 },
199 "android-x86_64" => {
200 inherit_from => [ "android", asm("x86_64_asm") ],
201 bn_ops => add("RC4_INT"),
202 perlasm_scheme => "elf",
203 },
204
205 ####################################################################
206 # Backward compatible targets, (might) requre $CROSS_SYSROOT
207 #
208 "android-armeabi" => {
209 inherit_from => [ "android-arm" ],
210 },
211 "android64" => {
212 inherit_from => [ "android" ],
213 },
214 "android64-aarch64" => {
215 inherit_from => [ "android-arm64" ],
216 },
217 "android64-x86_64" => {
218 inherit_from => [ "android-x86_64" ],
219 },
220 "android64-mips64" => {
221 inherit_from => [ "android-mips64" ],
222 },
223 );