-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.sh
executable file
·77 lines (59 loc) · 1.97 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
#!/bin/bash
#
# build static coreutils because we need exercises in minimalism
# MIT licensed: google it or see robxu9.mit-license.org.
#
# For Linux, also builds musl for truly static linking.
coreutils_version="8.28"
musl_version="1.1.15"
platform=$(uname -s)
if [ -d build ]; then
echo "= removing previous build directory"
rm -rf build
fi
mkdir build # make build directory
pushd build
# download tarballs
echo "= downloading coreutils"
curl -LO http://ftp.gnu.org/gnu/coreutils/coreutils-${coreutils_version}.tar.xz
echo "= extracting coreutils"
tar xJf coreutils-${coreutils_version}.tar.xz
if [ "$platform" = "Linux" ]; then
echo "= downloading musl"
curl -LO http://www.musl-libc.org/releases/musl-${musl_version}.tar.gz
echo "= extracting musl"
tar -xf musl-${musl_version}.tar.gz
echo "= building musl"
working_dir=$(pwd)
install_dir=${working_dir}/musl-install
pushd musl-${musl_version}
env CFLAGS="$CFLAGS -Os -ffunction-sections -fdata-sections" LDFLAGS='-Wl,--gc-sections' ./configure --prefix=${install_dir}
make install
popd # musl-${musl-version}
echo "= setting CC to musl-gcc"
export CC=${working_dir}/musl-install/bin/musl-gcc
export CFLAGS="-static"
else
echo "= WARNING: your platform does not support static binaries."
echo "= (This is mainly due to non-static libc availability.)"
fi
echo "= building coreutils"
pushd coreutils-${coreutils_version}
env FORCE_UNSAFE_CONFIGURE=1 CFLAGS="$CFLAGS -Os -ffunction-sections -fdata-sections" LDFLAGS='-Wl,--gc-sections' ./configure
make
popd # coreutils-${coreutils_version}
popd # build
if [ ! -d releases ]; then
mkdir releases
fi
echo "= striptease"
strip -s -R .comment -R .gnu.version --strip-unneeded build/coreutils-${coreutils_version}/coreutils
echo "= compressing"
shopt -s extglob
for file in build/coreutils-${coreutils_version}/src/!(*.*)
do
upx --ultra-brute $file
done
echo "= extracting coreutils binary"
cp build/coreutils-${coreutils_version}/src/!(*.*) releases
echo "= done"