8
8
9
9
set -euf -o pipefail
10
10
11
+ OPENSSL_GIT=" https://github.com/openssl/openssl.git"
11
12
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"
12
15
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 "
17
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
+ }
36
+
37
+ cross-compile-openssl () {
18
38
pushd /tmp/openssl
19
39
# 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 -
21
41
make clean
22
42
make depend
23
43
make -j$( nproc)
24
- make install
44
+ make install_sw
25
45
popd
26
-
27
- export INSTALL_DIR=
28
46
}
29
47
30
48
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
45
52
make clean
46
53
make -j$( nproc)
47
- make install
54
+ make DESTDIR= " $SYSROOT " install
48
55
popd
49
-
50
- export DESTDIR=
51
56
}
52
57
53
58
# Download cross-compilers
@@ -56,17 +61,27 @@ apt install -y gcc-multilib
56
61
apt install -y gcc-arm-linux-gnueabi
57
62
apt install -y gcc-aarch64-linux-gnu
58
63
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
+
59
76
# Download OpenSSL source code
60
77
if [ ! -d " /tmp/openssl" ]; then
61
78
pushd /tmp
62
79
git clone https://github.com/openssl/openssl.git --branch $OPENSSL_VERSION
63
80
popd
64
81
fi
65
82
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
70
85
71
86
# Compile OpenSSL and TSS stack for aarch64-unknown-linux-gnu
72
87
cross-compile-openssl aarch64-linux-gnu linux-generic64
@@ -76,6 +91,9 @@ rustup target add aarch64-unknown-linux-gnu
76
91
cargo build --features generate-bindings --target aarch64-unknown-linux-gnu
77
92
cargo build --target aarch64-unknown-linux-gnu
78
93
94
+ # Clean and prepare SYSROOT
95
+ prepare_sysroot
96
+
79
97
# Compile OpenSSL and TSS stack for armv7-unknown-linux-gnueabi
80
98
cross-compile-openssl arm-linux-gnueabi linux-generic32
81
99
cross-compile-tpm2-tss arm-linux-gnueabi
0 commit comments