Skip to content

Commit ee00ccc

Browse files
committed
Align cross-compile.sh with regenerate-bindings script
Signed-off-by: Gowtham Suresh Kumar <[email protected]>
1 parent 263a31d commit ee00ccc

File tree

1 file changed

+47
-29
lines changed

1 file changed

+47
-29
lines changed

tss-esapi/tests/cross-compile.sh

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,51 @@
88

99
set -euf -o pipefail
1010

11+
OPENSSL_GIT="https://github.com/openssl/openssl.git"
1112
OPENSSL_VERSION="OpenSSL_1_1_1j"
13+
TPM2_TSS_GIT="https://github.com/tpm2-software/tpm2-tss.git"
14+
TPM2_TSS_VERSION="2.4.6"
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"
1730

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+
}
36+
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

3048
cross-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
@@ -56,17 +61,27 @@ apt install -y gcc-multilib
5661
apt install -y gcc-arm-linux-gnueabi
5762
apt install -y gcc-aarch64-linux-gnu
5863

64+
# Download other dependencies
65+
apt install -y autoconf
66+
apt install -y autoconf-archive
67+
apt install -y cmake
68+
apt install -y libclang-dev
69+
apt install -y libtool
70+
apt install -y pkgconf
71+
72+
# Download OpenSSL, tpm2-tss and dependencies source code
73+
git_checkout "$OPENSSL_GIT" "$OPENSSL_VERSION"
74+
git_checkout "$TPM2_TSS_GIT" "$TPM2_TSS_VERSION"
75+
5976
# Download OpenSSL source code
6077
if [ ! -d "/tmp/openssl" ]; then
6178
pushd /tmp
6279
git clone https://github.com/openssl/openssl.git --branch $OPENSSL_VERSION
6380
popd
6481
fi
6582

66-
# Allow the `pkg-config` crate to cross-compile
67-
export PKG_CONFIG_ALLOW_CROSS=1
68-
# Make the `pkg-config` crate use our wrapper
69-
export PKG_CONFIG=$(pwd)/tests/pkg-config
83+
# Clean and prepare SYSROOT
84+
prepare_sysroot
7085

7186
# Compile OpenSSL and TSS stack for aarch64-unknown-linux-gnu
7287
cross-compile-openssl aarch64-linux-gnu linux-generic64
@@ -76,6 +91,9 @@ rustup target add aarch64-unknown-linux-gnu
7691
cargo build --features generate-bindings --target aarch64-unknown-linux-gnu
7792
cargo build --target aarch64-unknown-linux-gnu
7893

94+
# Clean and prepare SYSROOT
95+
prepare_sysroot
96+
7997
# Compile OpenSSL and TSS stack for armv7-unknown-linux-gnueabi
8098
cross-compile-openssl arm-linux-gnueabi linux-generic32
8199
cross-compile-tpm2-tss arm-linux-gnueabi

0 commit comments

Comments
 (0)