build 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #!/bin/bash
  2. [% c("var/set_default_env") -%]
  3. [% IF ! c("var/nss-linux-x86_64") -%]
  4. [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
  5. [% END -%]
  6. distdir=/var/tmp/dist/nss
  7. builddir=/var/tmp/build/[% project %]
  8. mkdir -p /var/tmp/build /var/tmp/dist
  9. tar -C /var/tmp/dist -xf [% c('input_files_by_name/ninja') %]
  10. export PATH=/var/tmp/dist/ninja:$PATH
  11. [% IF ! c("var/nss-linux-x86_64") -%]
  12. nspr_64=""
  13. [% IF c("var/cross_prefix") == "armv7a-linux-androideabi" -%]
  14. gyp_arch="arm"
  15. [% ELSIF c("var/cross_prefix") == "i686-linux-android" -%]
  16. gyp_arch="ia32"
  17. [% ELSIF c("var/cross_prefix") == "x86_64-linux-android" -%]
  18. gyp_arch="x64"
  19. nspr_64="--enable-64bit"
  20. [% ELSIF c("var/cross_prefix") == "aarch64-linux-android" -%]
  21. gyp_arch="arm64"
  22. nspr_64="--enable-64bit"
  23. [% END -%]
  24. export AR="[% c('var/cross_prefix') %]-ar"
  25. # XXX: Mozilla really uses the NDK_API_VERSION here, which is weird.
  26. export CC="[% c('var/cross_prefix') %][% pc('android-toolchain', 'var/android_ndk_version') %]-clang"
  27. export CXX="[% c('var/cross_prefix') %][% pc('android-toolchain', 'var/android_ndk_version') %]-clang++"
  28. export LD="[% c('var/cross_prefix') %]-ld"
  29. export NM="[% c('var/cross_prefix') %]-nm"
  30. export RANLIB="[% c('var/cross_prefix') %]-ranlib"
  31. export READELF="[% c('var/cross_prefix') %]-readelf"
  32. [% END -%]
  33. tar -C /var/tmp/build -xf [% c('input_files_by_name/nss') %]
  34. mv /var/tmp/build/[% project %]-[% c('version') %] $builddir
  35. cd $builddir
  36. # Early return hack to prevent NSPR Android setup
  37. # which does not work with ndk unified headers and clang. See:
  38. # application-services/libs/build-all.sh
  39. cat $rootdir/configure.patch | patch nspr/configure
  40. # Some NSS symbols clash with OpenSSL symbols, rename them using
  41. # C preprocessor define macros. See:
  42. # application-services/libs/build-all.sh
  43. patch -p2 < $rootdir/config.patch
  44. # Let's apply our proxy bypass defense-in-depth here as well to be on the safe
  45. # side.
  46. patch -p2 < $rootdir/bug_13028.patch
  47. patch -p1 < $rootdir/use-python3.patch
  48. [% IF c("var/nss-linux-x86_64") -%]
  49. patch -p1 < $rootdir/use-python3-build-sh.patch
  50. $builddir/nss/build.sh \
  51. -v \
  52. --opt \
  53. --static \
  54. --disable-tests \
  55. -Ddisable_dbm=1 \
  56. -Dsign_libs=0 \
  57. -Ddisable_libpkix=1 \
  58. -Dpython=python3
  59. mv $builddir/dist/Release "$builddir/nss_build"
  60. [% ELSE -%]
  61. # Building NSPR
  62. mkdir $builddir/nspr_build
  63. cd $builddir/nspr_build
  64. ../nspr/configure \
  65. $nspr_64 \
  66. --target=[% IF c("arch") == "armv7" %]arm-linux-androideabi[% ELSE %][% c("var/cross_prefix") %][% END %] \
  67. --disable-debug \
  68. --enable-optimize
  69. make
  70. cd ..
  71. # Building NSS
  72. mkdir $builddir/nss_build
  73. gyp -f ninja-android "$builddir/nss/nss.gyp" \
  74. --depth "$builddir/nss/" \
  75. --generator-output=. \
  76. -DOS=android \
  77. -Dnspr_lib_dir="$builddir/nspr_build/dist/lib" \
  78. -Dnspr_include_dir="$builddir/nspr_build/dist/include/nspr" \
  79. -Dnss_dist_dir="$builddir/nss_build" \
  80. -Dnss_dist_obj_dir="$builddir/nss_build" \
  81. -Dhost_arch="$gyp_arch" \
  82. -Dtarget_arch="$gyp_arch" \
  83. -Dstatic_libs=1 \
  84. -Ddisable_dbm=1 \
  85. -Dsign_libs=0 \
  86. -Denable_sslkeylogfile=0 \
  87. -Ddisable_tests=1 \
  88. -Ddisable_libpkix=1 \
  89. -Dpython=python3
  90. gendir="$builddir/nss/out/Release"
  91. ninja -C "$gendir"
  92. [% END -%]
  93. mkdir -p $distdir/include/nss
  94. mkdir -p $distdir/lib
  95. cp -p -L "$builddir/nss_build/lib/libcertdb.a" "$distdir/lib"
  96. cp -p -L "$builddir/nss_build/lib/libcerthi.a" "$distdir/lib"
  97. cp -p -L "$builddir/nss_build/lib/libcryptohi.a" "$distdir/lib"
  98. cp -p -L "$builddir/nss_build/lib/libfreebl_static.a" "$distdir/lib"
  99. cp -p -L "$builddir/nss_build/lib/libnss_static.a" "$distdir/lib"
  100. cp -p -L "$builddir/nss_build/lib/libmozpkix.a" "$distdir/lib"
  101. cp -p -L "$builddir/nss_build/lib/libnssb.a" "$distdir/lib"
  102. cp -p -L "$builddir/nss_build/lib/libnssdev.a" "$distdir/lib"
  103. cp -p -L "$builddir/nss_build/lib/libnsspki.a" "$distdir/lib"
  104. cp -p -L "$builddir/nss_build/lib/libnssutil.a" "$distdir/lib"
  105. cp -p -L "$builddir/nss_build/lib/libpk11wrap_static.a" "$distdir/lib"
  106. cp -p -L "$builddir/nss_build/lib/libpkcs12.a" "$distdir/lib"
  107. cp -p -L "$builddir/nss_build/lib/libpkcs7.a" "$distdir/lib"
  108. cp -p -L "$builddir/nss_build/lib/libsmime.a" "$distdir/lib"
  109. cp -p -L "$builddir/nss_build/lib/libsoftokn_static.a" "$distdir/lib"
  110. cp -p -L "$builddir/nss_build/lib/libssl.a" "$distdir/lib"
  111. [% IF c("var/nss-linux-x86_64") -%]
  112. cp -p -L "$builddir/nss_build/lib/libintel-gcm-wrap_c_lib.a" "$distdir/lib"
  113. cp -p -L "$builddir/nss_build/lib/libintel-gcm-s_lib.a" "$distdir/lib"
  114. cp -p -L "$builddir/nss_build/lib/libhw-acc-crypto-avx.a" "$distdir/lib"
  115. cp -p -L "$builddir/nss_build/lib/libhw-acc-crypto-avx2.a" "$distdir/lib"
  116. cp -p -L "$builddir/nss_build/lib/libgcm-aes-x86_c_lib.a" "$distdir/lib"
  117. [% ELSE -%]
  118. # HW specific.
  119. # https://searchfox.org/nss/rev/08c4d05078d00089f8d7540651b0717a9d66f87e/lib/freebl/freebl.gyp#278-296
  120. [% IF c("var/cross_prefix") == "i686-linux-android" || c("var/cross_prefix") == "x86_64-linux-android"-%]
  121. cp -p -L "$builddir/nss_build/lib/libgcm-aes-x86_c_lib.a" "$distdir/lib"
  122. [% END %]
  123. [% IF c("var/cross_prefix") == "armv7a-linux-androideabi" || c("var/cross_prefix") == "aarch64-linux-android"-%]
  124. cp -p -L "$builddir/nss_build/lib/libarmv8_c_lib.a" "$distdir/lib"
  125. [% END %]
  126. [% IF c("var/cross_prefix") == "aarch64-linux-android" -%]
  127. cp -p -L "$builddir/nss_build/lib/libgcm-aes-aarch64_c_lib.a" "$distdir/lib"
  128. [% END %]
  129. [% IF c("var/cross_prefix") == "armv7a-linux-androideabi" -%]
  130. cp -p -L "$builddir/nss_build/lib/libgcm-aes-arm32-neon_c_lib.a" "$distdir/lib"
  131. [% END %]
  132. # https://searchfox.org/nss/rev/08c4d05078d00089f8d7540651b0717a9d66f87e/lib/freebl/freebl.gyp#315-324
  133. # https://searchfox.org/nss/rev/08c4d05078d00089f8d7540651b0717a9d66f87e/lib/freebl/freebl.gyp#43-47
  134. [% IF c("var/cross_prefix") == "x86_64-linux-android"-%]
  135. cp -p -L "$builddir/nss_build/lib/libintel-gcm-wrap_c_lib.a" "$distdir/lib"
  136. cp -p -L "$builddir/nss_build/lib/libintel-gcm-s_lib.a" "$distdir/lib"
  137. cp -p -L "$builddir/nss_build/lib/libhw-acc-crypto-avx.a" "$distdir/lib"
  138. cp -p -L "$builddir/nss_build/lib/libhw-acc-crypto-avx2.a" "$distdir/lib"
  139. [% END %]
  140. [% END -%]
  141. [% IF c("var/nss-linux-x86_64") -%]
  142. nspr_libdir="$builddir/nss_build/lib"
  143. nss_include_dir="$builddir/dist/public/nss/"
  144. nspr_include_dir="$builddir/nss_build/include/nspr/"
  145. [% ELSE -%]
  146. nspr_libdir="$builddir/nspr_build/dist/lib"
  147. nss_include_dir="$builddir/nss_build/public/nss/"
  148. nspr_include_dir="$builddir/nspr_build/dist/include/nspr/"
  149. [% END -%]
  150. cp -p -L "$nspr_libdir/libplc4.a" "$distdir/lib"
  151. cp -p -L "$nspr_libdir/libplds4.a" "$distdir/lib"
  152. cp -p -L "$nspr_libdir/libnspr4.a" "$distdir/lib"
  153. cp -p -L -R "$nss_include_dir/"* "$distdir/include/nss"
  154. cp -p -L -R "$nspr_include_dir/"* "$distdir/include/nss"
  155. cd /var/tmp/dist
  156. [% c('tar', {
  157. tar_src => [ project ],
  158. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
  159. }) %]