15-android.conf 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 = "-Wa,--noexecstack";
  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. },
  119. "android-arm" => {
  120. ################################################################
  121. # Contemporary Android applications can provide multiple JNI
  122. # providers in .apk, targeting multiple architectures. Among
  123. # them there is "place" for two ARM flavours: generic eabi and
  124. # armv7-a/hard-float. However, it should be noted that OpenSSL's
  125. # ability to engage NEON is not constrained by ABI choice, nor
  126. # is your ability to call OpenSSL from your application code
  127. # compiled with floating-point ABI other than default 'soft'.
  128. # (Latter thanks to __attribute__((pcs("aapcs"))) declaration.)
  129. # This means that choice of ARM libraries you provide in .apk
  130. # is driven by application needs. For example if application
  131. # itself benefits from NEON or is floating-point intensive, then
  132. # it might be appropriate to provide both libraries. Otherwise
  133. # just generic eabi would do. But in latter case it would be
  134. # appropriate to
  135. #
  136. # ./Configure android-arm -D__ARM_MAX_ARCH__=8
  137. #
  138. # in order to build "universal" binary and allow OpenSSL take
  139. # advantage of NEON when it's available.
  140. #
  141. # Keep in mind that (just like with linux-armv4) we rely on
  142. # compiler defaults, which is not necessarily what you had
  143. # in mind, in which case you would have to pass additional
  144. # -march and/or -mfloat-abi flags. NDK defaults to armv5te.
  145. # Newer NDK versions reportedly require additional -latomic.
  146. #
  147. inherit_from => [ "android", asm("armv4_asm") ],
  148. bn_ops => add("RC4_CHAR"),
  149. },
  150. "android-arm64" => {
  151. inherit_from => [ "android", asm("aarch64_asm") ],
  152. bn_ops => add("RC4_CHAR"),
  153. perlasm_scheme => "linux64",
  154. },
  155. "android-mips" => {
  156. inherit_from => [ "android", asm("mips32_asm") ],
  157. bn_ops => add("RC4_CHAR"),
  158. perlasm_scheme => "o32",
  159. },
  160. "android-mips64" => {
  161. ################################################################
  162. # You are more than likely have to specify target processor
  163. # on ./Configure command line. Trouble is that toolchain's
  164. # default is MIPS64r6 (at least in r10d), but there are no
  165. # such processors around (or they are too rare to spot one).
  166. # Actual problem is that MIPS64r6 is binary incompatible
  167. # with previous MIPS ISA versions, in sense that unlike
  168. # prior versions original MIPS binary code will fail.
  169. #
  170. inherit_from => [ "android", asm("mips64_asm") ],
  171. bn_ops => add("RC4_CHAR"),
  172. perlasm_scheme => "64",
  173. },
  174. "android-x86" => {
  175. inherit_from => [ "android", asm("x86_asm") ],
  176. CFLAGS => add(picker(release => "-fomit-frame-pointer")),
  177. bn_ops => add("RC4_INT"),
  178. perlasm_scheme => "android",
  179. },
  180. "android-x86_64" => {
  181. inherit_from => [ "android", asm("x86_64_asm") ],
  182. bn_ops => add("RC4_INT"),
  183. perlasm_scheme => "elf",
  184. },
  185. ####################################################################
  186. # Backward compatible targets, (might) requre $CROSS_SYSROOT
  187. #
  188. "android-armeabi" => {
  189. inherit_from => [ "android-arm" ],
  190. },
  191. "android64" => {
  192. inherit_from => [ "android" ],
  193. },
  194. "android64-aarch64" => {
  195. inherit_from => [ "android-arm64" ],
  196. },
  197. "android64-x86_64" => {
  198. inherit_from => [ "android-x86_64" ],
  199. },
  200. "android64-mips64" => {
  201. inherit_from => [ "android-mips64" ],
  202. },
  203. );