Skip to content

Instantly share code, notes, and snippets.

@0neday
Last active November 24, 2023 11:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 0neday/20b95dc30157af177cb10c38f936d3ef to your computer and use it in GitHub Desktop.
Save 0neday/20b95dc30157af177cb10c38f936d3ef to your computer and use it in GitHub Desktop.
cross build shadowsocks-libev arm static binary using bootlin toolchains.
#!/bin/bash
set -e
set -x
BASE=`pwd`
########### #################################################################
# zlib # ####################################################################
########### #################################################################
wget -c https://zlib.net/zlib-1.2.11.tar.gz
tar -xzvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
CC=aarch64-linux-gcc \
./configure --prefix=/n1/dists/zlib --static
make -j$(nproc) && make install
cd $BASE
########### #################################################################
# openssl # #################################################################
########### #################################################################
wget -c https://github.com/openssl/openssl/archive/OpenSSL_1_0_2m.tar.gz
tar -xzvf OpenSSL_1_0_2m.tar.gz
cd openssl-OpenSSL_1_0_2m
CC=aarch64-linux-gcc \
./Configure --prefix=/n1/dists/openssl-v1.0.2m linux-aarch64 -static zlib threads \
no-shared --with-zlib-lib=/n1/dists/zlib/lib --with-zlib-include=/n1/dists/zlib/include
make -j$(nproc) && make install
cd $BASE
########### #################################################################
# pcre # ####################################################################
########### #################################################################
ver=8.43
if [ ! -d "pcre-$ver" ]; then
wget https://ftp.pcre.org/pub/pcre/pcre-$ver.tar.gz
tar zxf pcre-$ver.tar.gz
fi
cd $BASE/pcre-$ver
CC=aarch64-linux-gcc CXX=aarch64-linux-g++ AR=aarch64-linux-ar RANLIB=aarch64-linux-ranlib ./configure --prefix=/n1/dists/pcre --host=aarch64-linux \
--disable-shared --enable-utf8 --enable-unicode-properties
make -j`nproc` && make install
cd $BASE
########### #################################################################
# libsodium##################################################################
########### #################################################################
ver=1.0.18
if [ ! -d "libsodium-$ver" ]; then
wget https://download.libsodium.org/libsodium/releases/libsodium-$ver.tar.gz
tar zxf libsodium-$ver.tar.gz
fi
cd libsodium-$ver
CC=aarch64-linux-gcc ./configure --prefix=/n1/dists/libsodium --host=aarch64-linux --with-pthreads --disable-shared
make -j`nproc` && make install
cd $BASE
########### #################################################################
# libev ####################################################################
########### #################################################################
if [ ! -d "libev" ]; then
git clone https://github.com/shadowsocks/libev
fi
cd libev
CC=aarch64-linux-gcc ./configure --prefix=/n1/dists/libev --host=aarch64-linux --disable-shared
make -j`nproc` && make install
cd $BASE
########### #################################################################
# libudns ##################################################################
########### #################################################################
if [ ! -d "libudns" ]; then
git clone https://github.com/shadowsocks/libudns
fi
cd libudns
./autogen.sh
CC=aarch64-linux-gcc ./configure --prefix=/n1/dists/libudns --host=aarch64-linux
make -j`nproc` && make install
cd $BASE
########### #################################################################
# c-ares ####################################################################
########### #################################################################
ver=1.14.0
if [ ! -d "c-ares-$ver" ]; then
wget https://c-ares.haxx.se/download/c-ares-$ver.tar.gz
tar zxf c-ares-$ver.tar.gz
fi
cd c-ares-$ver
CC=aarch64-linux-gcc ./configure --prefix=/n1/dists/c-ares --host=aarch64-linux --disable-shared
make -j`nproc` && make install
cd $BASE
########### #################################################################
# shadowsocks-libev-2.6.3 ###################################################
########### #################################################################
# for openssl
git clone https://github.com/0neday/shadowsocks-libev-no-encryption
cd shadowsocks-libev-no-encryption
CC=aarch64-linux-gcc \
LIBS="-lpthread -lm" \
LDFLAGS="-Wl,-static -static -static-libgcc -L/n1/dists/libsodium/lib -lsodium -L/n1/dists/libudns/lib -ludns \
-L/n1/dists/libev/lib -lev -L/n1/dists/pcre/lib -lpcre -L/n1/dists/openssl-v1.0.2m/lib -lcrypto -lssl -L/n1/dists/zlib/lib -lz" \
CFLAGS="-Wno-stringop-truncation -Wno-format-truncation -Wno-unused-variable -I/n1/dists/libsodium/include -I/n1/dists/libudns/include \
-I/n1/dists/libev/include -I/n1/dists/pcre/include -I/n1/dists/openssl-v1.0.2m/include -I/n1/dists/zlib/include" \
./configure --host=aarch64-linux --prefix=/n1/dists/shadowsocks-libev-2.6.3 --disable-documentation --with-pcre=/n1/dists/pcre --disable-ssp
# bypass ld library from toolchains sysroot/usr/lib
sed -i 's/^LIBS = -lev -ludns .*/LIBS = -lpthread -lm/' Makefile
sed -i 's/^LIBS = -lev -ludns .*/LIBS = -lpthread -lm/' src/Makefile
# delete ss-nat
sed -i '/^bin_SCRIPTS = ss-nat/d' src/Makefile
make -j`nproc` && make install
#!/bin/bash
##### use buildroot, gcc version < 10, and enable ssp
set -e
set -x
BASE=`pwd`
########### #################################################################
# zlib # ####################################################################
########### #################################################################
wget -c https://zlib.net/zlib-1.2.11.tar.gz
tar -xzvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
CC=arm-linux-gcc \
./configure --prefix=/mnt/dists/zlib --static
make -j$(nproc) && make install
cd $BASE
########### #################################################################
# openssl # #################################################################
########### #################################################################
wget -c https://github.com/openssl/openssl/archive/OpenSSL_1_0_2m.tar.gz
tar -xzvf OpenSSL_1_0_2m.tar.gz
cd openssl-OpenSSL_1_0_2m
CC=arm-linux-gcc \
./Configure --prefix=/mnt/dists/openssl-v1.0.2m linux-armv4 -static zlib threads \
no-shared --with-zlib-lib=/mnt/dists/zlib/lib --with-zlib-include=/mnt/dists/zlib/include
make -j$(nproc) && make install
########### #################################################################
# mbedtls # #################################################################
########### #################################################################
ver=2.16.3
if [ ! -d "mbedtls-$ver" ]; then
wget --no-check-certificate https://tls.mbed.org/download/mbedtls-$ver-gpl.tgz && tar -xvf mbedtls-$ver-gpl.tgz
fi
cd $BASE/mbedtls-$ver
sed -i "s/DESTDIR=\/usr\/local/DESTDIR=\/mnt\/dists\/mbedtls/g" Makefile
CC=arm-linux-gcc CFLAGS="-Wno-implicit-function-declaration" AR=arm-linux-ar LD=arm-linux-ld LDFLAGS=-static make install
cd $BASE
########### #################################################################
# pcre # ####################################################################
########### #################################################################
ver=8.43
if [ ! -d "pcre-$ver" ]; then
wget https://ftp.pcre.org/pub/pcre/pcre-$ver.tar.gz
tar zxf pcre-$ver.tar.gz
fi
cd $BASE/pcre-$ver
CC=arm-linux-gcc CXX=arm-linux-g++ AR=arm-linux-ar RANLIB=arm-linux-ranlib ./configure --prefix=/mnt/dists/pcre --host=arm-linux \
--disable-shared --enable-utf8 --enable-unicode-properties
make -j`nproc` && make install
cd $BASE
########### #################################################################
# libsodium##################################################################
########### #################################################################
ver=1.0.18
if [ ! -d "libsodium-$ver" ]; then
wget https://download.libsodium.org/libsodium/releases/libsodium-$ver.tar.gz
tar zxf libsodium-$ver.tar.gz
fi
cd libsodium-$ver
CC=arm-linux-gcc ./configure --prefix=/mnt/dists/libsodium --host=arm-linux --with-pthreads --disable-shared
make -j`nproc` && make install
cd $BASE
########### #################################################################
# libev ####################################################################
########### #################################################################
if [ ! -d "libev" ]; then
git clone https://github.com/shadowsocks/libev
fi
cd libev
CC=arm-linux-gcc ./configure --prefix=/mnt/dists/libev --host=arm-linux --disable-shared
make -j`nproc` && make install
cd $BASE
########### #################################################################
# libudns ##################################################################
########### #################################################################
if [ ! -d "libudns" ]; then
git clone https://github.com/shadowsocks/libudns
fi
cd libudns
./autogen.sh
CC=arm-linux-gcc ./configure --prefix=/mnt/dists/libudns --host=arm-linux
make -j`nproc` && make install
cd $BASE
########### #################################################################
# c-ares ####################################################################
########### #################################################################
ver=1.14.0
if [ ! -d "c-ares-$ver" ]; then
wget https://c-ares.haxx.se/download/c-ares-$ver.tar.gz
tar zxf c-ares-$ver.tar.gz
fi
cd c-ares-$ver
CC=arm-linux-gcc ./configure --prefix=/mnt/dists/c-ares --host=arm-linux --disable-shared
make -j`nproc` && make install
cd $BASE
########### #################################################################
# shadowsocks-libev-2.6.3-no-encryption #####################################
########### #################################################################
# for openssl
git clone https://github.com/0neday/shadowsocks-libev-no-encryption
cd shadowsocks-libev-no-encryption
CC=arm-linux-gcc \
LIBS="-lpthread -lm" \
LDFLAGS="-Wl,-static -static -static-libgcc -L/mnt/dists/libsodium/lib -lsodium -L/mnt/dists/libudns/lib -ludns \
-L/mnt/dists/libev/lib -lev -L/mnt/dists/pcre/lib -lpcre -L/mnt/dists/openssl-v1.0.2m/lib -lcrypto -lssl -L/mnt/dists/zlib/lib -lz" \
CFLAGS="-Wno-stringop-truncation -Wno-format-truncation -Wno-unused-variable -I/mnt/dists/libsodium/include -I/mnt/dists/libudns/include \
-I/mnt/dists/libev/include -I/mnt/dists/pcre/include -I/mnt/dists/openssl-v1.0.2m/include -I/mnt/dists/zlib/include" \
./configure --host=arm-linux --prefix=/mnt/dists/shadowsocks-libev-2.6.3 --disable-documentation --with-pcre=/mnt/dists/pcre
# bypass ld library from toolchains sysroot/usr/lib
sed -i 's/^LIBS = -lev -ludns .*/LIBS = -lpthread -lm/' Makefile
sed -i 's/^LIBS = -lev -ludns .*/LIBS = -lpthread -lm/' src/Makefile
# delete ss-nat
sed -i '/^bin_SCRIPTS = ss-nat/d' src/Makefile
make -j`nproc` && make install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment