Created
August 11, 2021 13:59
-
-
Save rampageX/6953c1b91e520559e5c38b174c099785 to your computer and use it in GitHub Desktop.
Cross Build Static aarch64 Ubound Binary on Alpine x86_x64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
OPENSSL_TAG=OpenSSL_1_1_1k | |
LIBEXPAT_TAG=R_2_4_1 | |
LIBEVENT_TAG=release-2.1.12-stable | |
LIBSODIUM_TAG=1.0.18-RELEASE | |
STANDARD="c++17" | |
RESULT="`pwd`/result" | |
install_dir="`pwd`/aarch64" | |
include_dir="${install_dir}/include" | |
lib_dir="${install_dir}/lib" | |
PATH="${install_dir}/bin:${HOME}/bin${PATH:+:${PATH}}" | |
LD_LIBRARY_PATH="-L${lib_dir}" | |
PKG_CONFIG_PATH="-L${lib_dir}/pkgconfig" | |
custom_flags_set() { | |
CXXFLAGS="-std=${STANDARD}" | |
CPPFLAGS="--static -static -I${include_dir}" | |
LDFLAGS="--static -static -Wl,--no-as-needed -L${lib_dir} -lpthread -pthread" | |
} | |
custom_flags_reset() { | |
CXXFLAGS="-std=${STANDARD}" | |
CPPFLAGS="" | |
LDFLAGS="" | |
} | |
custom_flags_reset | |
reset_libs () { | |
rm -rf aarch64/ | |
#openssl | |
rm -rf openssl/ | |
git clone https://github.com/openssl/openssl.git --branch $OPENSSL_TAG --single-branch --depth 1 | |
cd openssl | |
custom_flags_set | |
./Configure linux-aarch64 --cross-compile-prefix=aarch64-linux-musl- --prefix="${install_dir}" threads no-shared no-dso no-comp CXXFLAGS="${CXXFLAGS}" CPPFLAGS="${CPPFLAGS}" LDFLAGS="${LDFLAGS}" | |
make -j${nproc} | |
make install_sw install_ssldirs | |
cd .. | |
#libexpat | |
rm -rf libexpat/ | |
git clone https://github.com/libexpat/libexpat.git --branch $LIBEXPAT_TAG --single-branch --depth 1 | |
cd libexpat | |
custom_flags_set | |
cd expat | |
rm -rf build | |
mkdir build | |
./buildconf.sh | |
cd ./build | |
../configure --prefix="${install_dir}" --host=aarch64-linux-musl | |
make -j${nproc} | |
make install | |
cd ../../../ | |
#libevent | |
rm -rf libevent/ | |
git clone https://github.com/libevent/libevent.git --branch $LIBEVENT_TAG --single-branch --depth 1 | |
cd libevent | |
./autogen.sh | |
custom_flags_set | |
./configure --prefix="${install_dir}" --host=aarch64-linux-musl CC=aarch64-linux-musl-gcc CXX=aarch64-linux-musl-g++ CPPFLAGS="${CPPFLAGS}" LDFLAGS="${LDFLAGS}" | |
make -j${nproc} | |
make install | |
cd .. | |
#libsodium | |
rm -rf libsodium/ | |
git clone https://github.com/jedisct1/libsodium.git --branch $LIBSODIUM_TAG --single-branch --depth 1 | |
cd libsodium | |
./autogen.sh | |
custom_flags_set | |
./configure --prefix="${install_dir}" --host=aarch64-linux-musl CC=aarch64-linux-musl-gcc CXX=aarch64-linux-musl-g++ CPPFLAGS="${CPPFLAGS}" LDFLAGS="${LDFLAGS}" | |
make -j${nproc} | |
make install | |
cd .. | |
} | |
RESET="$2" | |
[ -n "$RESET" -a "$RESET" = "reset" ] && reset_libs | |
#unbound | |
rm -rf unbound/ | |
git clone --depth=1 https://github.com/NLnetLabs/unbound.git | |
cd unbound | |
COND="$1" | |
[ $# -eq 0 ] && COND="full" | |
case $COND in | |
full) | |
./configure --prefix=/usr/local --disable-flto --enable-subnet --enable-cachedb --enable-dnscrypt --with-libevent="${install_dir}" --with-ssl="${install_dir}" --with-libexpat="${install_dir}" --host=aarch64-linux-musl | |
;; | |
normal) | |
./configure --prefix=/usr/local --disable-flto --enable-subnet --with-libevent="${install_dir}" --with-ssl="${install_dir}" --with-libexpat="${install_dir}" --host=aarch64-linux-musl | |
;; | |
lite) | |
./configure --prefix=/usr/local -disable-flto --disable-sha1 --disable-sha2 --disable-gost --disable-ecdsa --disable-dsa --disable-ed25519 --disable-ed448 --enable-subnet --with-libevent="${install_dir}" --with-ssl="${install_dir}" --with-libexpat="${install_dir}" --host=aarch64-linux-musl | |
# --with-ssl=/mmc -with-libexpat=/mmc | |
;; | |
*) | |
echo "Usage: $0 (full|normal|lite) [reset]" | |
exit 1 | |
esac | |
[ $? -ne 0 ] && { echo "configure error."; exit 2; } | |
sed -i '/LDFLAGS/ s/$/ -all-static -s/' ./Makefile | |
sed -i '/LIBS/ s/$/ -ldl/' ./Makefile | |
make -j${nproc} | |
make install DESTDIR=$RESULT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment