alertik/toolchain/toolchain.sh

134 lines
3.1 KiB
Bash
Raw Normal View History

2024-05-30 07:05:29 +02:00
#!/bin/bash
#
# Alertik: a tiny 'syslog' server & notification tool for Mikrotik routers.
# This is free and unencumbered software released into the public domain.
#
2024-05-30 08:07:19 +02:00
set -e
2024-05-30 07:05:29 +02:00
# Backup current folder
pushd .
export CURDIR="$( cd "$(dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd "$CURDIR/"
export PATH="$PATH:$CURDIR/armv6-linux-musleabi-cross/bin"
export MUSL_PREFIX="$CURDIR/armv6-linux-musleabi-cross/armv6-linux-musleabi"
# Misc
MUSL_ARMv6_LINK="https://musl.cc/armv6-linux-musleabi-cross.tgz"
CURL_LINK="https://github.com/curl/curl/releases/download/curl-8_8_0/curl-8.8.0.tar.xz"
BEARSSL_REPO="https://www.bearssl.org/git/BearSSL"
BEARSSL_HASH="79c060eea3eea1257797f15ea1608a9a9923aa6f"
download_musl_armv6() {
echo "[+] Downloading musl ..."
wget "$MUSL_ARMv6_LINK" -O armv6-musl.tgz
tar xvf armv6-musl.tgz
popd
}
download_build_bearssl() {
echo "[+] Cloning BearSSL ..."
git clone "$BEARSSL_REPO"
cd BearSSL/
git checkout "$BEARSSL_HASH"
cp ../armv6.mk conf/
echo "[+] Building ..."
make CONF=armv6
# Copy to the right path
echo "[+] Installing ..."
cp armv6/libbearssl.a "$MUSL_PREFIX/lib"
cp inc/* "$MUSL_PREFIX/include"
popd
}
download_build_libcurl() {
echo "[+] Downloading cURL ..."
wget "$CURL_LINK" -O curl.tar.xz
tar xvf curl.tar.xz
echo "[+] Building cURL ..."
cd curl*/
2024-05-30 08:07:19 +02:00
mkdir -p build && cd build/
2024-05-30 19:27:18 +02:00
export CFLAGS="-Os -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables -flto"
export LDFLAGS="-Wl,-s -Wl,-Bsymbolic -Wl,--gc-sections"
2024-05-30 07:05:29 +02:00
../configure \
--prefix="$MUSL_PREFIX" \
--target=armv6-linux-musleabi \
--host=armv6-linux-musleabi \
--build=x86_64-linux-gnu \
--with-bearssl \
2024-05-30 08:07:19 +02:00
--without-zlib \
2024-05-30 19:27:18 +02:00
--without-zstd \
2024-05-30 08:07:19 +02:00
--without-brotli \
2024-05-30 19:27:18 +02:00
--without-librtmp \
--disable-headers-api \
--disable-verbose \
--disable-http-auth \
--disable-cookies \
2024-05-30 07:05:29 +02:00
--disable-ipv6 \
--disable-ftp \
--disable-gopher \
--disable-imap \
--disable-ipfs \
--disable-ipns \
--disable-mqtt \
--disable-pop3 \
--disable-rtsp \
--disable-smtp \
--disable-telnet \
--disable-tftp \
2024-05-30 08:07:19 +02:00
--disable-hsts \
2024-05-30 19:27:18 +02:00
--disable-doh \
2024-05-30 08:07:19 +02:00
--disable-largefile \
--disable-dependency-tracking \
--disable-shared \
--disable-proxy \
--disable-dict \
--disable-file \
--disable-unix-sockets \
--disable-alt-svc \
--disable-manual \
--disable-docs \
--disable-libcurl-option \
--disable-sspi \
--disable-progress-meter \
--disable-netrc \
--disable-dateparse \
--disable-mime \
--enable-pthreads
2024-05-30 07:05:29 +02:00
make -j$(nproc)
make install
popd
}
# This is slightly better than using the CI file
# because our env vars are already set!
build_alertik_armv6() {
popd
echo "[+] Building Alertik!"
make CROSS=armv6
echo "[+] File type:"
file alertik
echo "[+] File size:"
ls -lah alertik
2024-05-30 19:32:16 +02:00
echo "[+] File hash:"
sha256sum alertik
2024-05-30 07:05:29 +02:00
}
# Dispatcher
if [ "$1" == "download_musl_armv6" ]; then
download_musl_armv6
elif [ "$1" == "download_build_bearssl" ]; then
download_build_bearssl
elif [ "$1" == "download_build_libcurl" ]; then
download_build_libcurl
elif [ "$1" == "build_alertik_armv6" ]; then
build_alertik_armv6
else
echo "No option found!"
2024-05-30 07:18:15 +02:00
exit 1
2024-05-30 07:05:29 +02:00
fi