2019-12-27 01:00:10 -05:00
#!/bin/sh
set -exu
# dependencies to build+test pegh
2019-12-31 02:52:57 -05:00
apk add build-base clang bash libsodium-dev libsodium-static openssl-dev openssl-libs-static
2019-12-27 01:00:10 -05:00
# gcc is apparantly incapable of building a static binary, even gcc -static helloworld.c ends up linked to libc, instead of solving, use clang
2019-12-30 02:55:42 -05:00
make clean all PEGH_LIBSODIUM = 1 CC = clang LDFLAGS = "-static"
2019-12-27 01:00:10 -05:00
mv pegh pegh.static.libsodium
2019-12-30 02:55:42 -05:00
make clean all PEGH_OPENSSL = 1 CC = clang LDFLAGS = "-static"
2019-12-27 01:00:10 -05:00
mv pegh pegh.static.openssl
2019-12-30 02:55:42 -05:00
make clean all PEGH_LIBSODIUM = 1 PEGH_OPENSSL = 1 CC = clang LDFLAGS = "-static"
2019-12-30 00:10:18 -05:00
mv pegh pegh.static.libsodium-openssl
2019-12-27 01:00:10 -05:00
2019-12-30 00:33:05 -05:00
./pegh.static.libsodium-openssl -h
2019-12-27 01:00:10 -05:00
ls -lah pegh.static.*
strip pegh.static.*
# print out some info about this, size, and to ensure it's actually fully static
ls -lah pegh.static.*
file pegh.static.*
ldd pegh.static.* || true
2020-01-01 02:17:35 -05:00
export TEST_BINS = "./pegh.static.openssl ./pegh.openssl ./pegh.static.libsodium-openssl ./pegh.libsodium-openssl ./pegh.static.libsodium ./pegh.libsodium"
2019-12-27 01:00:10 -05:00
2020-11-23 22:34:05 -05:00
# as of 27-Nov-2020 aarch64 openssl has a bug which causes the tests to fail, should try to report upstream...
[ " $ARCH " = = "aarch64" ] && export TEST_BINS = "./pegh.static.libsodium-openssl ./pegh.libsodium-openssl ./pegh.static.libsodium ./pegh.libsodium"
2019-12-27 01:00:10 -05:00
# compile dynamically linked versions (with gcc) to openssl and libsodium, then test all 4 against each other
./test.sh
echo "successfully built and tested static pegh against libsodium and openssl!"
2020-01-03 00:20:05 -05:00
2020-11-23 22:34:05 -05:00
# tests have all passed, move binaries to release directory for later
mkdir -p release
mv pegh.static.libsodium " ./release/pegh-linux- $ARCH -libsodium "
# as of 27-Nov-2020 aarch64 openssl has a bug which causes the tests to fail, should try to report upstream...
if [ " $ARCH " = = "aarch64" ]
then
rm -f pegh.static.openssl pegh.static.libsodium-openssl
else
mv pegh.static.openssl " ./release/pegh-linux- $ARCH -openssl "
mv pegh.static.libsodium-openssl " ./release/pegh-linux- $ARCH -libsodium-openssl "
fi
# for our native arch, just once, go ahead and archive the git repo too for later release
if [ " $ARCH " = = "amd64" ]
then
apk add git
git archive HEAD -9 --format zip -o ./release/pegh-source.zip
git archive HEAD -9 --format tar.gz -o ./release/pegh-source.tar.gz
fi
2020-01-03 00:20:05 -05:00
if [ " $ARCH " = = "amd64" ] || [ " $ARCH " = = "i386" ]
then
echo 'going to try to build windows here...'
2020-01-03 23:15:43 -05:00
apk add mingw-w64-gcc curl wine
2020-01-03 00:20:05 -05:00
STATIC_LIB_DIR = " $( pwd ) "
2020-11-23 22:34:05 -05:00
LIBSODIUM_VERSION = '1.0.18'
OPENSSL_VERSION = '1.1.1h_3'
OPENSSL_CURL_VERSION = '7.73.0_3'
if [ ! -d " ${ STATIC_LIB_DIR } /libsodium-win32 " ]
then
2020-01-03 00:20:05 -05:00
2020-11-23 22:34:05 -05:00
# only need to grab/unpack these once
curl -L -O https://download.libsodium.org/libsodium/releases/libsodium-${ LIBSODIUM_VERSION } -mingw.tar.gz -O https://curl.se/windows/dl-${ OPENSSL_CURL_VERSION } /openssl-${ OPENSSL_VERSION } -win64-mingw.zip -O https://curl.se/windows/dl-${ OPENSSL_CURL_VERSION } /openssl-${ OPENSSL_VERSION } -win32-mingw.zip
2020-01-03 00:20:05 -05:00
2020-11-23 22:34:05 -05:00
echo " e499c65b1c511cbc6700e436deb3771c3baa737981114c9e9f85f2ec90176861 libsodium- ${ LIBSODIUM_VERSION } -mingw.tar.gz " > libs.sha256
echo " fcaa181d848ac56150f00bc46d204d81fde4448a9afe9ef3ca04cc21d3132cb4 openssl- ${ OPENSSL_VERSION } -win32-mingw.zip " >> libs.sha256
echo " 913ddfa264ed9bae51f9deaa8ebce9d9450fa89fdf4c74ab41a6dfffb5880c67 openssl- ${ OPENSSL_VERSION } -win64-mingw.zip " >> libs.sha256
2020-01-03 00:20:05 -05:00
2020-11-23 22:34:05 -05:00
# fail if any of these hashes have changed
sha256sum -c libs.sha256
2020-01-03 00:20:05 -05:00
2020-11-23 22:34:05 -05:00
tar xzvf libsodium-${ LIBSODIUM_VERSION } -mingw.tar.gz
unzip openssl-${ OPENSSL_VERSION } -win32-mingw.zip
unzip openssl-${ OPENSSL_VERSION } -win64-mingw.zip
fi
2020-01-03 00:20:05 -05:00
if [ " $ARCH " = = "i386" ]
then
make CC = i686-w64-mingw32-cc PEGH_LIBSODIUM_WIN = " ${ STATIC_LIB_DIR } /libsodium-win32 " clean all
2020-01-04 03:04:22 -05:00
mv pegh.exe pegh-windows-i386-libsodium.exe
2020-01-03 00:20:05 -05:00
2020-11-23 22:34:05 -05:00
make CC = i686-w64-mingw32-cc PEGH_OPENSSL_WIN = " ${ STATIC_LIB_DIR } /openssl- ${ OPENSSL_VERSION } -win32-mingw " clean all
2020-01-04 03:04:22 -05:00
mv pegh.exe pegh-windows-i386-openssl.exe
2020-01-03 00:20:05 -05:00
2020-11-23 22:34:05 -05:00
make CC = i686-w64-mingw32-cc PEGH_OPENSSL_WIN = " ${ STATIC_LIB_DIR } /openssl- ${ OPENSSL_VERSION } -win32-mingw " PEGH_LIBSODIUM_WIN = " ${ STATIC_LIB_DIR } /libsodium-win32 " clean all
2020-01-04 03:04:22 -05:00
mv pegh.exe pegh-windows-i386-libsodium-openssl.exe
2020-01-03 00:20:05 -05:00
fi
2020-01-03 23:15:43 -05:00
export wine = "wine"
2020-01-03 00:20:05 -05:00
if [ " $ARCH " = = "amd64" ]
then
2020-01-03 23:15:43 -05:00
export wine = "wine64"
2020-01-03 00:20:05 -05:00
make CC = x86_64-w64-mingw32-cc PEGH_LIBSODIUM_WIN = " ${ STATIC_LIB_DIR } /libsodium-win64 " clean all
2020-01-04 03:04:22 -05:00
mv pegh.exe pegh-windows-amd64-libsodium.exe
2020-01-03 00:20:05 -05:00
2020-11-23 22:34:05 -05:00
make CC = x86_64-w64-mingw32-cc PEGH_OPENSSL_WIN = " ${ STATIC_LIB_DIR } /openssl- ${ OPENSSL_VERSION } -win64-mingw " clean all
2020-01-04 03:04:22 -05:00
mv pegh.exe pegh-windows-amd64-openssl.exe
2020-01-03 00:20:05 -05:00
2020-11-23 22:34:05 -05:00
make CC = x86_64-w64-mingw32-cc PEGH_OPENSSL_WIN = " ${ STATIC_LIB_DIR } /openssl- ${ OPENSSL_VERSION } -win64-mingw " PEGH_LIBSODIUM_WIN = " ${ STATIC_LIB_DIR } /libsodium-win64 " clean all
2020-01-04 03:04:22 -05:00
mv pegh.exe pegh-windows-amd64-libsodium-openssl.exe
2020-01-03 00:20:05 -05:00
fi
ls -lah *.exe
strip *.exe
ls -lah *.exe
file *.exe
2020-11-23 22:34:05 -05:00
# running the test script sometimes locks up wine, I think due to races on creating ~/.wine, so do that first...
$wine ./pegh-windows-$ARCH -libsodium.exe -h
2020-01-03 23:15:43 -05:00
# now test windows binaries against the static ones with wine
# no binfmt here where executing .exe *just works*, so do it hacky way :'(
2020-11-23 22:34:05 -05:00
export TEST_BINS = " ./release/pegh-linux- $ARCH -openssl ./release/pegh-linux- $ARCH -libsodium-openssl ./release/pegh-linux- $ARCH -libsodium "
# we've really already tested all of the above against each other, let's just test windows against one
export TEST_BINS = " ./release/pegh-linux- $ARCH -openssl "
2020-01-03 23:15:43 -05:00
for exe in *.exe
do
script = " $exe .sh "
cat > " $script " <<EOF
#!/bin/sh
exec $wine " ./ $exe " "\$@"
EOF
chmod +x " $script "
export TEST_BINS = " ./ $script $TEST_BINS "
done
./test.sh
echo "windows binaries pass tests through wine!"
2020-11-23 22:34:05 -05:00
killall pegh-windows-amd64-libsodium-openssl.exe pegh-windows-amd64-libsodium.exe pegh-windows-amd64-openssl.exe pegh-windows-i386-libsodium-openssl.exe pegh-windows-i386-libsodium.exe pegh-windows-i386-openssl.exe || true
sleep 5
killall -9 pegh-windows-amd64-libsodium-openssl.exe pegh-windows-amd64-libsodium.exe pegh-windows-amd64-openssl.exe pegh-windows-i386-libsodium-openssl.exe pegh-windows-i386-libsodium.exe pegh-windows-i386-openssl.exe || true
sleep 5
rm -rf ~/.wine /tmp/.wine*
# for later release
mv *.exe ./release/
2020-01-03 00:20:05 -05:00
fi