2019-12-27 01:00:10 -05:00
#!/bin/sh
2020-01-03 00:20:05 -05:00
ARCH = " $1 "
2019-12-27 01:00:10 -05:00
set -exu
# change to the directory this script is in
cd " $( dirname " $0 " ) "
# 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
# 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
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 ) "
LIBSODIUM_VERSION = 1.0.18
curl -O https://download.libsodium.org/libsodium/releases/libsodium-${ LIBSODIUM_VERSION } -stable-mingw.tar.gz -O https://curl.haxx.se/windows/dl-7.67.0_5/openssl-1.1.1d_5-win64-mingw.zip -O https://curl.haxx.se/windows/dl-7.67.0_5/openssl-1.1.1d_5-win32-mingw.zip
2020-01-06 00:50:32 -05:00
echo " 241d6c88c2d79e13dae9f4943804a5a855c7d2904b21f74ebd31b15d056e3a4f libsodium- ${ LIBSODIUM_VERSION } -stable-mingw.tar.gz " > libs.sha256
2020-01-03 00:20:05 -05:00
echo '4f474918a1597d6d1d35e524cf79827623f8ce511259b0047ee95bc0fddbf29c openssl-1.1.1d_5-win32-mingw.zip' >> libs.sha256
echo '936260c5a865c8e3f6af35a5394dd1acc43063a40a206c717350f1a341d8d822 openssl-1.1.1d_5-win64-mingw.zip' >> libs.sha256
sha256sum -c libs.sha256
tar xzvf libsodium-${ LIBSODIUM_VERSION } -stable-mingw.tar.gz
unzip openssl-1.1.1d_5-win32-mingw.zip
unzip openssl-1.1.1d_5-win64-mingw.zip
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
make CC = i686-w64-mingw32-cc PEGH_OPENSSL_WIN = " ${ STATIC_LIB_DIR } /openssl-1.1.1d-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
make CC = i686-w64-mingw32-cc PEGH_OPENSSL_WIN = " ${ STATIC_LIB_DIR } /openssl-1.1.1d-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
make CC = x86_64-w64-mingw32-cc PEGH_OPENSSL_WIN = " ${ STATIC_LIB_DIR } /openssl-1.1.1d-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
make CC = x86_64-w64-mingw32-cc PEGH_OPENSSL_WIN = " ${ STATIC_LIB_DIR } /openssl-1.1.1d-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-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 :'(
export TEST_BINS = "./pegh.static.openssl ./pegh.static.libsodium-openssl ./pegh.static.libsodium"
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-01-03 00:20:05 -05:00
fi