-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·104 lines (86 loc) · 2.66 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/sh
set -e
HERE="$(dirname "$(readlink -f "$0")")"
cd "$HERE"
WITH_UPX=1
VENDOR_UPX=1
platform="$(uname -s)"
platform_arch="$(uname -m)"
export MAKEFLAGS="-j$(nproc)"
if [ "$platform" == "Linux" ]
then
export CFLAGS="-static"
export LDFLAGS='--static'
else
echo "= WARNING: your platform does not support static binaries."
echo "= (This is mainly due to non-static libc availability.)"
exit 1
fi
if [ -x "$(which apk 2>/dev/null)" ]
then
apk add git gcc musl-dev upx cmake make patch
fi
if [ "$WITH_UPX" == 1 ]
then
if [[ "$VENDOR_UPX" == 1 || ! -x "$(which upx 2>/dev/null)" ]]
then
upx_ver=4.2.4
case "$platform_arch" in
x86_64) upx_arch=amd64 ;;
aarch64) upx_arch=arm64 ;;
esac
wget https://github.com/upx/upx/releases/download/v${upx_ver}/upx-${upx_ver}-${upx_arch}_linux.tar.xz
tar xvf upx-${upx_ver}-${upx_arch}_linux.tar.xz
mv upx-${upx_ver}-${upx_arch}_linux/upx /usr/bin/
rm -rf upx-${upx_ver}-${upx_arch}_linux*
fi
fi
if [ -d build ]
then
echo "= removing previous build directory"
rm -rf build
fi
# if [ -d release ]
# then
# echo "= removing previous release directory"
# rm -rf release
# fi
echo "= create build and release directory"
mkdir -p build
mkdir -p release
(cd build
export CFLAGS="$CFLAGS -Os -g0 -ffunction-sections -fdata-sections -fvisibility=hidden -fmerge-all-constants"
export LDFLAGS="$LDFLAGS -Wl,--gc-sections -Wl,--strip-all"
echo "= download tini"
git clone https://github.com/krallin/tini.git
tini_version="$(cd tini && git describe --long --tags|sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g')"
tini_dir="${HERE}/build/tini-${tini_version}"
mv "tini" "tini-${tini_version}"
echo "= tini v${tini_version}"
echo "= build tini"
(cd "${tini_dir}"
export CC=gcc
patch -p1<"$HERE"/tini.patch
mkdir build && cd build
cmake .. && make)
echo "= extracting tini binaries and libraries"
mv -fv "${tini_dir}"/build/tini "$HERE"/release/tini-${platform_arch}
)
echo "= build super-strip"
(cd build && git clone https://github.com/aunali1/super-strip.git && cd super-strip
make
mv -fv sstrip /usr/bin/)
echo "= super-strip release binaries"
sstrip release/*-"${platform_arch}"
if [[ "$WITH_UPX" == 1 && -x "$(which upx 2>/dev/null)" ]]
then
echo "= upx compressing"
find release -name "*-${platform_arch}"|\
xargs -I {} upx --force-overwrite -9 --best {} -o {}-upx
fi
if [ "$NO_CLEANUP" != 1 ]
then
echo "= cleanup"
rm -rfv build
fi
echo "= tini done"