2
0

15-android.conf 8.9 KB

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