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.3.3"
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 "
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
+ }
17
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
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 "
65
78
66
79
# Regenerate bindings for x86_64-unknown-linux-gnu
67
80
cargo clean
68
81
cargo build --features generate-bindings
69
82
find ../target -name tss_esapi_bindings.rs -exec cp {} ./src/bindings/x86_64-unknown-linux-gnu.rs \;
70
83
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
75
86
76
87
# Regenerate bindings for aarch64-unknown-linux-gnu
77
88
cross-compile-openssl aarch64-linux-gnu linux-generic64
@@ -82,11 +93,14 @@ cargo clean
82
93
cargo build --features generate-bindings --target aarch64-unknown-linux-gnu
83
94
find ../target -name tss_esapi_bindings.rs -exec cp {} ./src/bindings/aarch64-unknown-linux-gnu.rs \;
84
95
96
+ # Clean and prepare SYSROOT
97
+ prepare_sysroot
98
+
85
99
# Regenerate bindings for armv7-unknown-linux-gnueabi
86
100
cross-compile-openssl arm-linux-gnueabi linux-generic32
87
101
cross-compile-tpm2-tss arm-linux-gnueabi
88
102
89
103
rustup target add armv7-unknown-linux-gnueabi
90
104
cargo clean
91
105
cargo 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