GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

build 6.02 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
#!/bin/bash
[% c("var/set_default_env") -%]
[% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
distdir=/var/tmp/dist/nss
builddir=/var/tmp/build/[% project %]
mkdir /var/tmp/build
tar -C /var/tmp/dist -xf [% c('input_files_by_name/ninja') %]
export PATH=/var/tmp/dist/ninja:$PATH

# application-services uses a newer NDK, 21d, than all the other projects...
Georg Koppen's avatar
Georg Koppen committed
11
export ANDROID_NDK_API_VERSION=[% pc("android-toolchain", "var/android_ndk_version") %][% pc('android-toolchain', 'var/android_ndk_revision') %]
12 13 14 15 16 17 18
export ANDROID_NDK_HOME=/var/tmp/dist/[% c('var/compiler') %]/android-ndk/android-ndk-r$ANDROID_NDK_API_VERSION
# We need to add the new path to our build tools to PATH
export PATH=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH
export ANDROID_NDK_ROOT=$ANDROID_NDK_HOME
export NDK_HOST_TAG=linux-x86_64

nspr_64=""
Georg Koppen's avatar
Georg Koppen committed
19
[% IF c("var/cross_prefix") == "armv7a-linux-androideabi" -%]
20
  gyp_arch="arm"
Georg Koppen's avatar
Georg Koppen committed
21
[% ELSIF c("var/cross_prefix") == "i686-linux-android" -%]
22
  gyp_arch="ia32"
Georg Koppen's avatar
Georg Koppen committed
23
[% ELSIF c("var/cross_prefix") == "x86_64-linux-android" -%]
24 25
  gyp_arch="x64"
  nspr_64="--enable-64bit"
Georg Koppen's avatar
Georg Koppen committed
26
[% ELSIF c("var/cross_prefix") == "aarch64-linux-android" -%]
27 28 29 30 31 32
  gyp_arch="arm64"
  nspr_64="--enable-64bit"
[% END -%]

export AR="[% c('var/cross_prefix') %]-ar"
# XXX: Mozilla really uses the NDK_API_VERSION here, which is weird.
Georg Koppen's avatar
Georg Koppen committed
33 34
export CC="[% c('var/cross_prefix') %][% pc('android-toolchain', 'var/android_ndk_version') %]-clang"
export CXX="[% c('var/cross_prefix') %][% pc('android-toolchain', 'var/android_ndk_version') %]-clang++"
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
export LD="[% c('var/cross_prefix') %]-ld"
export NM="[% c('var/cross_prefix') %]-nm"
export RANLIB="[% c('var/cross_prefix') %]-ranlib"
export READELF="[% c('var/cross_prefix') %]-readelf"

tar -C /var/tmp/build -xf [% c('input_files_by_name/nss') %]
mv /var/tmp/build/[% project %]-[% c('version') %] $builddir
cd $builddir
# Early return hack to prevent NSPR Android setup
# which does not work with ndk unified headers and clang. See:
# application-services/libs/build-all.sh
cat $rootdir/configure.patch | patch nspr/configure
# Some NSS symbols clash with OpenSSL symbols, rename them using
# C preprocessor define macros. See:
# application-services/libs/build-all.sh
patch -p2 < $rootdir/config.patch
# Let's apply our proxy bypass defense-in-depth here as well to be on the safe
# side.
patch -p2 < $rootdir/bug_13028.patch

# Building NSPR
mkdir $builddir/nspr_build
cd $builddir/nspr_build
../nspr/configure \
  $nspr_64 \
Georg Koppen's avatar
Georg Koppen committed
60
  --target=[% IF c("arch") == "armv7" %]arm-linux-androideabi[% ELSE %][% c("var/cross_prefix") %][% END %] \
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
  --disable-debug \
  --enable-optimize
make
cd ..

# Building NSS
mkdir $builddir/nss_build
gyp -f ninja-android "$builddir/nss/nss.gyp" \
  --depth "$builddir/nss/" \
  --generator-output=. \
  -DOS=android \
  -Dnspr_lib_dir="$builddir/nspr_build/dist/lib" \
  -Dnspr_include_dir="$builddir/nspr_build/dist/include/nspr" \
  -Dnss_dist_dir="$builddir/nss_build" \
  -Dnss_dist_obj_dir="$builddir/nss_build" \
  -Dhost_arch="$gyp_arch" \
  -Dtarget_arch="$gyp_arch" \
  -Dstatic_libs=1 \
  -Ddisable_dbm=1 \
  -Dsign_libs=0 \
  -Denable_sslkeylogfile=0 \
  -Ddisable_tests=1 \
  -Ddisable_libpkix=1

gendir="$builddir/nss/out/Release"
ninja -C "$gendir"

mkdir -p $distdir/include/nss
mkdir -p $distdir/lib
cp -p -L "$builddir/nss_build/lib/libcertdb.a" "$distdir/lib"
cp -p -L "$builddir/nss_build/lib/libcerthi.a" "$distdir/lib"
cp -p -L "$builddir/nss_build/lib/libcryptohi.a" "$distdir/lib"
cp -p -L "$builddir/nss_build/lib/libfreebl_static.a" "$distdir/lib"
cp -p -L "$builddir/nss_build/lib/libnss_static.a" "$distdir/lib"
cp -p -L "$builddir/nss_build/lib/libnssb.a" "$distdir/lib"
cp -p -L "$builddir/nss_build/lib/libnssdev.a" "$distdir/lib"
cp -p -L "$builddir/nss_build/lib/libnsspki.a" "$distdir/lib"
cp -p -L "$builddir/nss_build/lib/libnssutil.a" "$distdir/lib"
cp -p -L "$builddir/nss_build/lib/libpk11wrap_static.a" "$distdir/lib"
cp -p -L "$builddir/nss_build/lib/libpkcs12.a" "$distdir/lib"
cp -p -L "$builddir/nss_build/lib/libpkcs7.a" "$distdir/lib"
cp -p -L "$builddir/nss_build/lib/libsmime.a" "$distdir/lib"
cp -p -L "$builddir/nss_build/lib/libsoftokn_static.a" "$distdir/lib"
cp -p -L "$builddir/nss_build/lib/libssl.a" "$distdir/lib"

# HW specific.
# https://searchfox.org/nss/rev/08c4d05078d00089f8d7540651b0717a9d66f87e/lib/freebl/freebl.gyp#278-296
Georg Koppen's avatar
Georg Koppen committed
108
[% IF c("var/cross_prefix") == "i686-linux-android" || c("var/cross_prefix") == "x86_64-linux-android"-%]
109 110
  cp -p -L "$builddir/nss_build/lib/libgcm-aes-x86_c_lib.a" "$distdir/lib"
[% END %]
Georg Koppen's avatar
Georg Koppen committed
111
[% IF c("var/cross_prefix") == "armv7a-linux-androideabi" || c("var/cross_prefix") == "aarch64-linux-android"-%]
112 113
  cp -p -L "$builddir/nss_build/lib/libarmv8_c_lib.a" "$distdir/lib"
[% END %]
Georg Koppen's avatar
Georg Koppen committed
114
[% IF c("var/cross_prefix") == "aarch64-linux-android" -%]
115 116
  cp -p -L "$builddir/nss_build/lib/libgcm-aes-aarch64_c_lib.a" "$distdir/lib"
[% END %]
Georg Koppen's avatar
Georg Koppen committed
117
[% IF c("var/cross_prefix") == "armv7a-linux-androideabi" -%]
118 119 120 121
  cp -p -L "$builddir/nss_build/lib/libgcm-aes-arm32-neon_c_lib.a" "$distdir/lib"
[% END %]
# https://searchfox.org/nss/rev/08c4d05078d00089f8d7540651b0717a9d66f87e/lib/freebl/freebl.gyp#315-324
# https://searchfox.org/nss/rev/08c4d05078d00089f8d7540651b0717a9d66f87e/lib/freebl/freebl.gyp#43-47
Georg Koppen's avatar
Georg Koppen committed
122
[% IF c("var/cross_prefix") == "x86_64-linux-android"-%]
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
  cp -p -L "$builddir/nss_build/lib/libintel-gcm-wrap_c_lib.a" "$distdir/lib"
  cp -p -L "$builddir/nss_build/lib/libintel-gcm-s_lib.a" "$distdir/lib"
  cp -p -L "$builddir/nss_build/lib/libhw-acc-crypto-avx.a" "$distdir/lib"
  cp -p -L "$builddir/nss_build/lib/libhw-acc-crypto-avx2.a" "$distdir/lib"
[% END %]
cp -p -L "$builddir/nspr_build/dist/lib/libplc4.a" "$distdir/lib"
cp -p -L "$builddir/nspr_build/dist/lib/libplds4.a" "$distdir/lib"
cp -p -L "$builddir/nspr_build/dist/lib/libnspr4.a" "$distdir/lib"

cp -p -L -R "$builddir/nss_build/public/nss/"* "$distdir/include/nss"
cp -p -L -R "$builddir/nspr_build/dist/include/nspr/"* "$distdir/include/nss"

cd /var/tmp/dist
[% c('tar', {
        tar_src => [ project ],
        tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
    }) %]