88
99set -euf -o pipefail
1010
11+ OPENSSL_GIT=" https://github.com/openssl/openssl.git"
1112OPENSSL_VERSION=" OpenSSL_1_1_1j"
13+ TPM2_TSS_GIT=" https://github.com/tpm2-software/tpm2-tss.git"
14+ TPM2_TSS_VERSION=" 2.3.3"
1215
13- cross-compile-openssl () {
14- # Prepare directory for cross-compiled OpenSSL files
15- mkdir -p /tmp/openssl-$1
16- export INSTALL_DIR=/tmp/openssl-$1
16+ export SYSROOT=" /tmp/sysroot"
17+
18+ git_checkout () {
19+ if [ ! -d " /tmp/$( basename " $1 " " .git" ) " ]; then
20+ pushd /tmp
21+ git clone " $1 " --branch " $2 "
22+ popd
23+ fi
24+ }
25+
26+ prepare_sysroot () {
27+ # Prepare the SYSROOT
28+ [ -d " $SYSROOT " ] && rm -fr " $SYSROOT "
29+ mkdir -p " $SYSROOT "
30+
31+ # Allow the `pkg-config` crate to cross-compile
32+ export PKG_CONFIG_ALLOW_CROSS=1
33+ export PKG_CONFIG_PATH=" $SYSROOT " /lib/pkgconfig:" $SYSROOT " /share/pkgconfig
34+ export PKG_CONFIG_SYSROOT_DIR=" $SYSROOT "
35+ }
1736
37+ cross-compile-openssl () {
1838 pushd /tmp/openssl
1939 # Compile and copy files over
20- ./Configure $2 shared --prefix=$INSTALL_DIR --openssldir=$INSTALL_DIR /openssl --cross-compile-prefix=$1 -
40+ ./Configure $2 shared --prefix=" $SYSROOT " --openssldir=" $SYSROOT " /openssl --cross-compile-prefix=$1 -
2141 make clean
2242 make depend
2343 make -j$( nproc)
24- make install
44+ make install_sw
2545 popd
26-
27- export INSTALL_DIR=
2846}
2947
3048cross-compile-tpm2-tss () {
31- # Prepare directory for cross-compiled TSS lib
32- # `DESTDIR` is used in `make install` below to set the root of the installation paths.
33- # The `./configure` script accepts a `--prefix` input variable which sets the same root,
34- # but also adds it to the paths in `.pc` files used by `pkg-config`. This prevents the
35- # use of `PKG_CONFIG_SYSROOT_DIR`.
36- mkdir -p /tmp/tpm2-tss-$1
37- export DESTDIR=/tmp/tpm2-tss-$1
38- # Set sysroot to be used by the `pkg-config` wrapper
39- export SYSROOT=/tmp/tpm2-tss-$1
40-
41- pushd /tpm2-tss
42- # Compile and copy files over
43- ./configure --build=x86_64-pc-linux-gnu --host=$1 --target=$1 CC=$1 -gcc \
44- LIBCRYPTO_CFLAGS=" -I/tmp/openssl-$1 /include" LIBCRYPTO_LIBS=" -L/tmp/openssl-$1 /lib -lcrypto"
49+ pushd /tmp/tpm2-tss
50+ [ ! -f configure ] && ./bootstrap
51+ ./configure --enable-fapi=no --prefix=/ --build=x86_64-pc-linux-gnu --host=$1 --target=$1 CC=$1 -gcc
4552 make clean
4653 make -j$( nproc)
47- make install
54+ make DESTDIR= " $SYSROOT " install
4855 popd
49-
50- export DESTDIR=
5156}
5257
5358# Download cross-compilers
54- apt update
55- apt install -y gcc-multilib
56- apt install -y gcc-arm-linux-gnueabi
57- apt install -y gcc-aarch64-linux-gnu
58-
59- # Download OpenSSL source code
60- if [ ! -d " /tmp/openssl" ]; then
61- pushd /tmp
62- git clone https://github.com/openssl/openssl.git --branch $OPENSSL_VERSION
63- popd
64- fi
59+ sudo apt update
60+ sudo apt install -y gcc-multilib
61+ sudo apt install -y gcc-arm-linux-gnueabi
62+ sudo apt install -y gcc-aarch64-linux-gnu
63+
64+ # Download development version for tpm2-tss
65+ sudo apt install -y libtss2-dev
66+
67+ # Download other dependencies
68+ sudo apt install -y autoconf
69+ sudo apt install -y autoconf-archive
70+ sudo apt install -y cmake
71+ sudo apt install -y libclang-dev
72+ sudo apt install -y libtool
73+ sudo apt install -y pkgconf
74+
75+ # Download OpenSSL, tpm2-tss and dependencies source code
76+ git_checkout " $OPENSSL_GIT " " $OPENSSL_VERSION "
77+ git_checkout " $TPM2_TSS_GIT " " $TPM2_TSS_VERSION "
6578
6679# Regenerate bindings for x86_64-unknown-linux-gnu
6780cargo clean
6881cargo build --features generate-bindings
6982find ../target -name tss_esapi_bindings.rs -exec cp {} ./src/bindings/x86_64-unknown-linux-gnu.rs \;
7083
71- # Allow the `pkg-config` crate to cross-compile
72- export PKG_CONFIG_ALLOW_CROSS=1
73- # Make the `pkg-config` crate use our wrapper
74- export PKG_CONFIG=$( pwd) /../tss-esapi/tests/pkg-config
84+ # Clean and prepare SYSROOT
85+ prepare_sysroot
7586
7687# Regenerate bindings for aarch64-unknown-linux-gnu
7788cross-compile-openssl aarch64-linux-gnu linux-generic64
@@ -82,11 +93,14 @@ cargo clean
8293cargo build --features generate-bindings --target aarch64-unknown-linux-gnu
8394find ../target -name tss_esapi_bindings.rs -exec cp {} ./src/bindings/aarch64-unknown-linux-gnu.rs \;
8495
96+ # Clean and prepare SYSROOT
97+ prepare_sysroot
98+
8599# Regenerate bindings for armv7-unknown-linux-gnueabi
86100cross-compile-openssl arm-linux-gnueabi linux-generic32
87101cross-compile-tpm2-tss arm-linux-gnueabi
88102
89103rustup target add armv7-unknown-linux-gnueabi
90104cargo clean
91105cargo build --features generate-bindings --target armv7-unknown-linux-gnueabi
92- find ../target -name tss_esapi_bindings.rs -exec cp {} ./src/bindings/arm-unknown-linux-gnueabi.rs \;
106+ find ../target -name tss_esapi_bindings.rs -exec cp {} ./src/bindings/arm-unknown-linux-gnueabi.rs \;
0 commit comments