@@ -5,13 +5,21 @@ apt-get update && apt-get install -y build-essential wget cmake gcc-aarch64-linu
5
5
6
6
ARCHITECTURES=(" x86_64" " aarch64" )
7
7
COMPILERS=(" gcc" " aarch64-linux-gnu-gcc" )
8
- OUTPUT_FILES=(" ${BUILD_DIR} /zstd-linux-x86_64" " ${BUILD_DIR} /zstd-linux-aarch64" )
8
+ OUTPUT_FILES=(" zstd-linux-x86_64" " zstd-linux-aarch64" )
9
+ VERIFY=(" x86-64" " ARM aarch64" )
10
+ STRIP=(" strip" " aarch64-linux-gnu-strip" )
11
+ CURR_DIR=$( pwd)
9
12
10
13
# Function to check if binary is static and has correct architecture
11
14
check_binary () {
12
15
local binary=" $1 "
13
16
local arch=" $2 "
14
17
18
+ # Verify the binary
19
+ echo " Verifying $binary ..."
20
+ ldd $binary
21
+ file $binary
22
+
15
23
# Check if binary is statically linked
16
24
if ldd " $binary " 2>&1 | grep -q " not a dynamic executable" ; then
17
25
echo " The binary $binary is statically linked."
@@ -21,42 +29,87 @@ check_binary() {
21
29
fi
22
30
23
31
# Check architecture
24
- if file " $binary " | grep -q " $arch " ; then
32
+ if file " $binary " | grep -q " $arch , version 1 (GNU/Linux), statically linked " ; then
25
33
echo " The binary $binary is for the correct architecture $arch ."
26
34
else
27
35
echo " Error: The binary $binary is not for the correct architecture (expected $arch )."
28
36
exit 1
29
37
fi
30
38
}
31
39
40
+ # build zlib for aarch64
41
+ build_zlib () {
42
+ wget https://zlib.net/zlib-1.3.1.tar.gz
43
+ tar -xzf zlib-1.3.1.tar.gz
44
+ cd zlib-1.3.1
45
+ CC=aarch64-linux-gnu-gcc ./configure --prefix=/tmp/zlib-aarch64 --static
46
+ make
47
+ make install
48
+ file /tmp/zlib-aarch64/lib/libz.a
49
+ aarch64-linux-gnu-objdump -f /tmp/zlib-aarch64/lib/libz.a | grep architecture
50
+ cd ..
51
+ }
52
+
53
+ build_liblzma () {
54
+ wget https://tukaani.org/xz/xz-5.4.4.tar.gz
55
+ tar -xzf xz-5.4.4.tar.gz
56
+ cd xz-5.4.4
57
+ CC=aarch64-linux-gnu-gcc ./configure --prefix=/tmp/liblzma-aarch64 --host=aarch64-linux-gnu --enable-static --disable-shared
58
+ make
59
+ make install
60
+ file /tmp/liblzma-aarch64/lib/liblzma.a
61
+ aarch64-linux-gnu-objdump -f /tmp/liblzma-aarch64/lib/liblzma.a | grep architecture
62
+ cd ..
63
+ }
64
+
65
+
32
66
# Ensure BUILD_DIR and ZSTD_VERSION are set
33
67
if [ -z " $BUILD_DIR " ] || [ -z " $ZSTD_VERSION " ]; then
34
68
echo " BUILD_DIR and ZSTD_VERSION must be set."
35
69
exit 1
36
70
fi
37
71
38
- mkdir -p " $BUILD_DIR "
39
- cd " $BUILD_DIR "
40
-
41
72
if [ ! -d " zstd-${ZSTD_VERSION} " ]; then
42
73
echo " Downloading zstd version ${ZSTD_VERSION} ..."
43
74
wget https://github.com/facebook/zstd/releases/download/v${ZSTD_VERSION} /zstd-${ZSTD_VERSION} .tar.gz
44
75
tar -xzf zstd-${ZSTD_VERSION} .tar.gz
45
76
fi
46
- cd " zstd-${ZSTD_VERSION} "
77
+
78
+ mkdir -p " $BUILD_DIR "
47
79
48
80
# Build and verify binaries for each architecture
49
81
for i in " ${! ARCHITECTURES[@]} " ; do
50
82
arch=" ${ARCHITECTURES[$i]} "
83
+ verify=" ${VERIFY[$i]} "
51
84
compiler=" ${COMPILERS[$i]} "
52
85
output_file=" ${OUTPUT_FILES[$i]} "
86
+ strip_cmd=" ${STRIP[$i]} "
87
+
88
+ cf_flags=" -static -O2 -pthread"
89
+ ld_flags=" -static"
90
+
91
+ if [ " $arch " == " aarch64" ]; then
92
+ build_zlib
93
+ build_liblzma
94
+ cf_flags=" -static -O2 -pthread -I/tmp/zlib-aarch64/include -I/tmp/liblzma-aarch64/include"
95
+ ld_flags=" -static -L/tmp/zlib-aarch64/lib -lz -L/tmp/liblzma-aarch64/lib -llzma"
96
+ cd $CURR_DIR
97
+ fi
98
+
99
+ cp -r " zstd-${ZSTD_VERSION} " " $BUILD_DIR "
100
+ cd " $BUILD_DIR "
101
+ ls -lrt
53
102
54
103
echo " Building zstd statically for $arch ..."
55
- make clean
56
- CC=" $compiler " CFLAGS=" -static -O2 -pthread" LDFLAGS=" -static" make -j4 zstd
57
- cp zstd " $output_file "
104
+ make clean -C " zstd-${ZSTD_VERSION} "
105
+ CC=" $compiler " CFLAGS=" ${cf_flags} " LDFLAGS=" ${ld_flags} " make -j4 -C " zstd-${ZSTD_VERSION} " zstd
106
+ " $strip_cmd " -s " zstd-${ZSTD_VERSION} /programs/zstd"
107
+ mv " zstd-${ZSTD_VERSION} /programs/zstd" " $CURR_DIR /$output_file "
58
108
109
+ chmod +x $CURR_DIR /$output_file
110
+ rm -rf *
111
+ cd " $CURR_DIR "
59
112
echo " Verifying $output_file ..."
60
- check_binary " $output_file " " $arch "
113
+ check_binary " $output_file " " $verify "
61
114
done
62
- echo " Binaries are located at ${OUTPUT_FILES[*]} ."
115
+ echo " Binaries are located at ${OUTPUT_FILES[*]} ."
0 commit comments