1、静态编译脚本
#!/bin/bash
#
# build static tar because we need exercises in minimalism
# MIT licentar: google it or see robxu9.mit-license.org.
#
# For Linux, also builds musl for truly static linking.tar_version="1.29"
musl_version="1.1.15"platform=$(uname -s)if [ -d build ]; thenecho "= removing previous build directory"rm -rf build
fimkdir build # make build directory
pushd build# download tarballs
echo "= downloading tar"
curl -LO http://ftp.gnu.org/gnu/tar/tar-${tar_version}.tar.xzecho "= extracting tar"
tar xJf tar-${tar_version}.tar.xzif [ "$platform" = "Linux" ]; thenecho "= downloading musl"curl -LO http://www.musl-libc.org/releases/musl-${musl_version}.tar.gzecho "= extracting musl"tar -xf musl-${musl_version}.tar.gzecho "= building musl"working_dir=$(pwd)install_dir=${working_dir}/musl-installpushd musl-${musl_version}env CFLAGS="$CFLAGS -Os -ffunction-sections -fdata-sections" LDFLAGS='-Wl,--gc-sections' ./configure --prefix=${install_dir}make installpopd # musl-${musl-version}echo "= setting CC to musl-gcc"export CC=${working_dir}/musl-install/bin/musl-gccexport CFLAGS="-static"
elseecho "= WARNING: your platform does not support static binaries."echo "= (This is mainly due to non-static libc availability.)"
fiecho "= building tar"pushd tar-${tar_version}
env FORCE_UNSAFE_CONFIGURE=1 CFLAGS="$CFLAGS -Os -ffunction-sections -fdata-sections" LDFLAGS='-Wl,--gc-sections' ./configure
make
popd # tar-${tar_version}popd # buildif [ ! -d releases ]; thenmkdir releases
fiecho "= striptease"
strip -s -R .comment -R .gnu.version --strip-unneeded build/tar-${tar_version}/src/tar
echo "= compressing"
upx --ultra-brute build/tar-${tar_version}/src/tar
echo "= extracting tar binary"
cp build/tar-${tar_version}/src/tar releases
echo "= done"
说明:此编译脚本在X86平台和ARM平台都可以使用,亲测
/opt/build/tar-1.35/src编译后tar二进制文件在此目录,直接使用即可