Forked from harv/cross_and_static_compile_shadowsocks-libev.sh
Last active
February 28, 2023 22:56
-
-
Save honwen/e57359378cd4699d19d10eb34f8069b4 to your computer and use it in GitHub Desktop.
cross & static compile shadowsocks-libev
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/bash | |
export http_proxy=http://127.0.0.1:8080 | |
export https_proxy=http://127.0.0.1:8080 | |
export CC=clang | |
export CXX=clang++ | |
# git init | |
git config --global user.name 'docker' | |
git config --global user.email '[email protected]' | |
# cross & static compile shadowsocks(r)-libev | |
_get_src_ver(){ | |
curl -sSL "$1" | sed -n 's/PKG_SOURCE_VERSION:=//p' | |
} | |
_get_ver(){ | |
curl -sSL "$1" | sed -n 's/PKG_RELEASE:=//p' | |
} | |
PCRE_VER=8.44 | |
PCRE_FILE="https://ftp.pcre.org/pub/pcre/pcre-$PCRE_VER.tar.gz" | |
MBEDTLS_VER=2.16.3 | |
MBEDTLS_FILE="https://tls.mbed.org/download/mbedtls-$MBEDTLS_VER-gpl.tgz" | |
LIBSODIUM_VER=1.0.18 | |
LIBSODIUM_FILE="https://github.com/jedisct1/libsodium/releases/download/$LIBSODIUM_VER-RELEASE/libsodium-$LIBSODIUM_VER.tar.gz" | |
LIBEV_VER=4.33 | |
LIBEV_FILE="https://fossies.org/linux/misc/libev-$LIBEV_VER.tar.gz" | |
LIBC_ARES_VER=1.14.0 | |
LIBC_ARES_FILE="https://c-ares.haxx.se/download/c-ares-$LIBC_ARES_VER.tar.gz" | |
SHADOWSOCKS_LIBEV_VER=$(curl -skSL https://api.github.com/repos/shadowsocks/shadowsocks-libev/releases | jq -r 'first(.[].tag_name)') | |
SHADOWSOCKS_LIBEV_FILE="https://github.com/shadowsocks/shadowsocks-libev" | |
SIMPLE_OBFS_VER=$(_get_src_ver "https://github.com/aa65535/openwrt-simple-obfs/raw/master/Makefile") | |
SIMPLE_OBFS_FILE="https://github.com/shadowsocks/simple-obfs" | |
SHADOWSOCKSR_LIBEV_VER=$(_get_ver "https://github.com/chenhw2/openwrt-shadowsocksr/raw/master/Makefile") | |
SHADOWSOCKSR_LIBEV_FILE="https://github.com/shadowsocksrr/shadowsocksr-libev" | |
cur_dir=$(pwd) | |
prepare() { | |
rm -rf $cur_dir/build && mkdir $cur_dir/build | |
} | |
compile_pcre() { | |
[ -d "$prefix/pcre" ] && return | |
cd $cur_dir/build | |
wget --no-check-certificate $PCRE_FILE | |
tar xvf pcre-$PCRE_VER.tar.gz | |
cd pcre-$PCRE_VER | |
CPPFLAGS="-DNEED_PRINTF" ./configure --prefix=$prefix/pcre --host=$host --enable-jit --enable-utf8 --enable-unicode-properties --disable-shared | |
make -j$(getconf _NPROCESSORS_ONLN) && make install | |
} | |
compile_mbedtls() { | |
[ -d "$prefix/mbedtls" ] && return | |
cd $cur_dir/build | |
wget --no-check-certificate $MBEDTLS_FILE | |
tar xvf mbedtls-$MBEDTLS_VER-gpl.tgz | |
cd mbedtls-$MBEDTLS_VER | |
prefix_reg=$(echo $prefix | sed "s/\//\\\\\//g") | |
sed -i "s/DESTDIR=\/usr\/local/DESTDIR=$prefix_reg\/mbedtls/g" Makefile | |
[ -z $host ] && make install -j$(getconf _NPROCESSORS_ONLN) || CC=$host-gcc AR=$host-ar LD=$host-ld make install -j$(getconf _NPROCESSORS_ONLN) | |
} | |
compile_libsodium() { | |
[ -d "$prefix/libsodium" ] && return | |
cd $cur_dir/build | |
wget --no-check-certificate $LIBSODIUM_FILE | |
tar xvf libsodium-$LIBSODIUM_VER.tar.gz | |
cd libsodium-$LIBSODIUM_VER | |
./configure --prefix=$prefix/libsodium --host=$host --disable-ssp --disable-shared | |
make -j$(getconf _NPROCESSORS_ONLN) && make install | |
} | |
compile_libev() { | |
[ -d "$prefix/libev" ] && return | |
cd $cur_dir/build | |
wget --no-check-certificate $LIBEV_FILE | |
tar xvf libev-$LIBEV_VER.tar.gz | |
cd libev-$LIBEV_VER | |
./configure --prefix=$prefix/libev --host=$host --disable-shared | |
make -j$(getconf _NPROCESSORS_ONLN) && make install | |
} | |
compile_libc_ares() { | |
[ -d "$prefix/libc-ares" ] && return | |
cd $cur_dir/build | |
wget --no-check-certificate $LIBC_ARES_FILE | |
tar xvf c-ares-$LIBC_ARES_VER.tar.gz | |
cd c-ares-$LIBC_ARES_VER | |
./configure --prefix=$prefix/libc-ares --host=$host --disable-shared | |
make -j$(getconf _NPROCESSORS_ONLN) && make install | |
} | |
compile_shadowsocks_libev() { | |
[ -f "$prefix/shadowsocks-libev/bin/ss-local" ] && return | |
cd $cur_dir/build | |
git clone $SHADOWSOCKS_LIBEV_FILE | |
cd shadowsocks-libev | |
git checkout $SHADOWSOCKS_LIBEV_VER | |
git submodule update --init --recursive | |
./autogen.sh | |
LIBS="-lpthread -lm" LDFLAGS="-Wl,-static -static-libgcc -L$prefix/libc-ares/lib -L$prefix/libev/lib" CFLAGS="-I$prefix/libc-ares/include -I$prefix/libev/include" ./configure --prefix=$prefix/shadowsocks-libev --host=$host --disable-ssp --disable-documentation --with-mbedtls=$prefix/mbedtls --with-pcre=$prefix/pcre --with-sodium=$prefix/libsodium | |
make -j$(getconf _NPROCESSORS_ONLN) && make install | |
} | |
compile_simple_obfs() { | |
[ -f "$prefix/shadowsocks-libev/bin/obfs-local" ] && return | |
cd $cur_dir/build | |
git clone $SIMPLE_OBFS_FILE | |
cd simple-obfs | |
git checkout $SIMPLE_OBFS_VER | |
git submodule update --init --recursive | |
./autogen.sh | |
LIBS="-lpthread -lm" LDFLAGS="-Wl,-static -static-libgcc -L$prefix/libc-ares/lib -L$prefix/libev/lib -L$prefix/libsodium/lib" CFLAGS="-I$prefix/libc-ares/include -I$prefix/libev/include -I$prefix/libsodium/include" ./configure --prefix=$prefix/shadowsocks-libev --host=$host --disable-ssp --disable-documentation | |
make -j$(getconf _NPROCESSORS_ONLN) && make install | |
} | |
compile_shadowsocksr_libev() { | |
[ -f "$prefix/shadowsocksr-libev/bin/ssr-local" ] && return | |
cd $cur_dir/build | |
git clone $SHADOWSOCKSR_LIBEV_FILE | |
cd shadowsocksr-libev | |
git checkout $SHADOWSOCKSR_LIBEV_VER | |
mkdir patches | |
wget -P patches https://github.com/chenhw2/openwrt-shadowsocksr/raw/master/patches/0001-Refine-Usage.patch | |
wget -P patches https://github.com/chenhw2/openwrt-shadowsocksr/raw/master/patches/0002-Refine-Version.patch | |
git am patches/*.patch | |
./autogen.sh | |
LIBS="-lpthread -lm" LDFLAGS="-Wl,-static -static -static-libgcc -L$prefix/libev/lib" CFLAGS="-I$prefix/libev/include" ./configure --prefix=$prefix/shadowsocksr-libev --host=$host --disable-ssp --disable-documentation --with-crypto-library=mbedtls --with-mbedtls=$prefix/mbedtls --with-pcre=$prefix/pcre --with-sodium=$prefix/libsodium | |
make -j$(getconf _NPROCESSORS_ONLN) && make install | |
ls $prefix/shadowsocksr-libev/bin | sed -n '/^ss-/p' | while read bin; do | |
mv "$prefix/shadowsocksr-libev/bin/$bin" "$prefix/shadowsocksr-libev/bin/$(echo -n $bin | sed 's/ss-/ssr-/g')" | |
done | |
} | |
clean() { | |
cd $cur_dir | |
rm -rf $cur_dir/build | |
} | |
squash(){ | |
if hash upx 2>/dev/null; then | |
find $prefix | grep 'libev/bin/' | grep -v nat | xargs upx -9 | |
fi | |
} | |
while [ ! -z $1 ]; do | |
case $1 in | |
-h | --help) | |
echo "Useage: sh $0 [--host=<host>] [--prefix=<path>]" | |
echo "" | |
echo "Options:" | |
echo " --host=<host> the machine that you are building for" | |
echo " --prefix=<path> install architecture-independent files in prefix[$cur_dir/dists]" | |
exit 0 | |
;; | |
--host) | |
shift | |
host=$1 | |
;; | |
--host=*) | |
arr=(${1//=/ }) | |
host=${arr[1]} | |
;; | |
--prefix) | |
shift | |
prefix=$1 | |
;; | |
--prefix=*) | |
arr=(${1//=/ }) | |
prefix=${arr[1]} | |
;; | |
esac | |
shift | |
done | |
red="\033[0;31m" | |
green="\033[0;32m" | |
plain="\033[0m" | |
[ -z $host ] && compiler=${CC:-gcc} || compiler=$host-${CC:-gcc} | |
if [ -f "$(which $compiler)" ]; then | |
echo -e "found cross compiler ${green}$(which ${compiler})${plain}" | |
else | |
echo -e "${red}Error:${plain} not found cross compiler ${green}${compiler}${plain}" | |
exit -1 | |
fi | |
[ -z $prefix ] && prefix=$cur_dir/dists | |
echo -e "binaries will be installed in ${green}${prefix}${plain}" | |
prepare | |
compile_pcre | |
compile_mbedtls | |
compile_libsodium | |
compile_libev | |
compile_libc_ares | |
compile_shadowsocks_libev | |
[ -e $prefix/shadowsocks-libev/bin/ss-local ] || exit 1 | |
compile_simple_obfs | |
[ -e $prefix/shadowsocks-libev/bin/obfs-local ] || exit 1 | |
compile_shadowsocksr_libev | |
[ -e $prefix/shadowsocksr-libev/bin/ssr-local ] || exit 1 | |
clean | |
squash >/dev/null 2>&1 | |
find $prefix | grep 'libev/bin/' | sed 's/^/#### Release Binary: /g' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment