2017-07-25 18:55:40 +08:00
#!/usr/bin/env bash
# MIT License
#
2021-10-11 05:15:55 +08:00
# Copyright (c) 2017-2021 Maxim Biro <nurupo.contributions@gmail.com>
2017-07-25 18:55:40 +08:00
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# Known issues:
# - Doesn't build qTox updater, because it wasn't ported to cmake yet and
2017-10-14 19:55:44 +08:00
# because it requires static Qt, which means we'd need to build Qt twice, and
# building Qt takes really long time.
2017-07-25 18:55:40 +08:00
set -euo pipefail
2022-01-10 04:55:55 +08:00
RUN_TESTS = 0
2017-07-25 18:55:40 +08:00
2021-11-08 13:27:45 +08:00
while ( ( $# > 0 ) ) ; do
case $1 in
--src-dir) QTOX_SRC_DIR = $2 ; shift 2 ; ;
--arch) ARCH = $2 ; shift 2 ; ;
2022-01-10 04:55:55 +08:00
--run-tests) RUN_TESTS = 1; shift ; ;
2021-11-08 13:27:45 +08:00
--build-type) BUILD_TYPE = $2 ; shift 2; ;
*) " Unexpected argument $1 " ; exit 1 ; ;
esac
done
2017-07-25 18:55:40 +08:00
2021-11-08 13:27:45 +08:00
# Common directory paths
2017-07-25 18:55:40 +08:00
2021-11-08 13:27:45 +08:00
QTOX_PREFIX_DIR = " $( realpath install-prefix) "
readonly QTOX_PREFIX_DIR
QTOX_PACKAGE_DIR = " $( realpath package-prefix) "
readonly QTOX_PACKAGE_DIR
2017-07-25 18:55:40 +08:00
if [ -z " $ARCH " ]
then
echo "Error: No architecture was specified. Please specify either 'i686' or 'x86_64', case sensitive, as the first argument to the script."
exit 1
fi
if [ [ " $ARCH " != "i686" ] ] && [ [ " $ARCH " != "x86_64" ] ]
then
echo "Error: Incorrect architecture was specified. Please specify either 'i686' or 'x86_64', case sensitive, as the first argument to the script."
exit 1
fi
2021-11-08 13:27:45 +08:00
if [ -z " $QTOX_SRC_DIR " ] ; then
echo "--src-dir must be specified"
fi
2017-07-25 18:55:40 +08:00
if [ -z " $BUILD_TYPE " ]
then
echo "Error: No build type was specified. Please specify either 'release' or 'debug', case sensitive, as the second argument to the script."
exit 1
fi
if [ [ " $BUILD_TYPE " != "release" ] ] && [ [ " $BUILD_TYPE " != "debug" ] ]
then
echo "Error: Incorrect build type was specified. Please specify either 'release' or 'debug', case sensitive, as the second argument to the script."
exit 1
fi
2018-05-19 05:06:19 +08:00
# Spell check on windows currently not supported, disable
2017-07-25 18:55:40 +08:00
if [ [ " $BUILD_TYPE " = = "release" ] ]
then
2021-11-08 13:27:45 +08:00
cmake -DCMAKE_TOOLCHAIN_FILE= /build/windows-toolchain.cmake \
-DCMAKE_PREFIX_PATH= /windows \
2017-07-25 18:55:40 +08:00
-DCMAKE_BUILD_TYPE= Release \
2018-05-19 05:06:19 +08:00
-DSPELL_CHECK= OFF \
2020-08-18 06:05:51 +08:00
-DDESKTOP_NOTIFICATIONS= ON \
2019-01-08 13:46:30 +08:00
-DUPDATE_CHECK= ON \
2020-04-12 16:34:31 +08:00
-DSTRICT_OPTIONS= ON \
2022-01-10 04:55:55 +08:00
-DTEST_CROSSCOMPILING_EMULATOR= wine \
2021-11-08 13:27:45 +08:00
" $QTOX_SRC_DIR "
2017-07-25 18:55:40 +08:00
elif [ [ " $BUILD_TYPE " = = "debug" ] ]
then
2021-11-08 13:27:45 +08:00
cmake -DCMAKE_TOOLCHAIN_FILE= /build/windows-toolchain.cmake \
-DCMAKE_PREFIX_PATH= /windows \
2017-07-25 18:55:40 +08:00
-DCMAKE_BUILD_TYPE= Debug \
2018-05-19 05:06:19 +08:00
-DSPELL_CHECK= OFF \
2020-08-18 06:05:51 +08:00
-DDESKTOP_NOTIFICATIONS= ON \
2019-01-08 13:46:30 +08:00
-DUPDATE_CHECK= ON \
2020-04-12 16:34:31 +08:00
-DSTRICT_OPTIONS= ON \
2022-01-10 04:55:55 +08:00
-DTEST_CROSSCOMPILING_EMULATOR= wine \
2021-11-08 13:27:45 +08:00
" $QTOX_SRC_DIR "
2017-07-25 18:55:40 +08:00
fi
2021-11-08 13:27:45 +08:00
make -j $( nproc)
2017-07-25 18:55:40 +08:00
2021-11-08 13:27:45 +08:00
mkdir -p " ${ QTOX_PREFIX_DIR } "
2017-07-25 18:55:40 +08:00
cp qtox.exe $QTOX_PREFIX_DIR
2021-11-08 13:27:45 +08:00
cp -r /export/* $QTOX_PREFIX_DIR
2020-06-05 02:51:26 +08:00
2022-01-10 04:55:55 +08:00
# Run tests
2020-06-05 02:51:26 +08:00
set +u
2022-01-10 04:55:55 +08:00
if [ [ $RUN_TESTS -ne 0 ] ]
2020-06-05 02:51:26 +08:00
then
2021-11-08 13:27:45 +08:00
export WINEPATH = '/export;/windows/bin'
2017-10-24 15:10:03 +08:00
export CTEST_OUTPUT_ON_FAILURE = 1
make test
fi
set -u
2017-07-25 18:55:40 +08:00
# Strip
set +e
if [ [ " $BUILD_TYPE " = = "release" ] ]
then
$ARCH -w64-mingw32-strip -s $QTOX_PREFIX_DIR /*.exe
fi
$ARCH -w64-mingw32-strip -s $QTOX_PREFIX_DIR /*.dll
$ARCH -w64-mingw32-strip -s $QTOX_PREFIX_DIR /*/*.dll
set -e
2021-11-08 13:27:45 +08:00
if [ [ " $BUILD_TYPE " = = "debug" ] ]
then
cp -r /debug_export/* ${ QTOX_PREFIX_DIR }
fi
2018-04-04 09:19:49 +08:00
# Create zip
2021-11-08 13:27:45 +08:00
pushd $QTOX_PREFIX_DIR
2018-04-03 03:31:29 +08:00
zip qtox-" $ARCH " -" $BUILD_TYPE " .zip -r *
2021-11-08 13:27:45 +08:00
popd
2018-04-04 09:19:49 +08:00
2018-04-04 09:18:08 +08:00
# Create installer
2018-03-18 21:27:26 +08:00
if [ [ " $BUILD_TYPE " = = "release" ] ]
then
2021-11-08 13:27:45 +08:00
mkdir -p $QTOX_PACKAGE_DIR
pushd $QTOX_PACKAGE_DIR
2018-04-04 09:18:08 +08:00
# The installer creation script expects all the files to be in qtox/*
2021-11-08 13:27:45 +08:00
mkdir -p qtox
2018-04-04 09:18:08 +08:00
cp -r $QTOX_PREFIX_DIR /* ./qtox
2018-04-04 09:19:49 +08:00
rm ./qtox/*.zip
2018-03-18 21:27:26 +08:00
2021-11-08 13:27:45 +08:00
cp -r $QTOX_SRC_DIR /windows/* .
2018-03-18 21:27:26 +08:00
# Select the installer script for the correct architecture
if [ [ " $ARCH " = = "i686" ] ]
then
2018-04-04 09:18:08 +08:00
makensis qtox.nsi
2018-03-18 21:27:26 +08:00
elif [ [ " $ARCH " = = "x86_64" ] ]
then
2018-04-04 09:18:08 +08:00
makensis qtox64.nsi
2018-03-18 21:27:26 +08:00
fi
2021-11-08 13:27:45 +08:00
popd
2018-03-18 21:27:26 +08:00
fi
2021-10-31 07:44:30 +08:00
# dll check
# Create lists of all .exe and .dll files
find " $QTOX_PREFIX_DIR " -iname '*.dll' > dlls
find " $QTOX_PREFIX_DIR " -iname '*.exe' > exes
# Create a list of dlls that are loaded during the runtime (not listed in the PE
# import table, thus ldd doesn't print those)
echo " $QTOX_PREFIX_DIR /libsnore-qt5/libsnore_backend_windowstoast.dll
$QTOX_PREFIX_DIR /iconengines/qsvgicon.dll
$QTOX_PREFIX_DIR /imageformats/qgif.dll
$QTOX_PREFIX_DIR /imageformats/qico.dll
$QTOX_PREFIX_DIR /imageformats/qjpeg.dll
$QTOX_PREFIX_DIR /imageformats/qsvg.dll
$QTOX_PREFIX_DIR /platforms/qdirect2d.dll
$QTOX_PREFIX_DIR /platforms/qminimal.dll
$QTOX_PREFIX_DIR /platforms/qoffscreen.dll
$QTOX_PREFIX_DIR /platforms/qwindows.dll" > runtime-dlls
if [ [ " $ARCH " = = "i686" ] ]
then
echo " $QTOX_PREFIX_DIR /libssl-1_1.dll " >> runtime-dlls
elif [ [ " $ARCH " = = "x86_64" ] ]
then
echo " $QTOX_PREFIX_DIR /libssl-1_1-x64.dll " >> runtime-dlls
fi
# Create a tree of all required dlls
# Assumes all .exe files are directly in $QTOX_PREFIX_DIR, not in subdirs
while IFS = read -r line
do
if [ [ " $ARCH " = = "i686" ] ]
then
WINE_DLL_DIR = "/root/.wine/drive_c/windows/system32"
elif [ [ " $ARCH " = = "x86_64" ] ]
then
WINE_DLL_DIR = "/root/.wine/drive_c/windows/system32 /root/.wine/drive_c/windows/syswow64"
fi
2021-11-08 13:27:45 +08:00
python3 /usr/local/bin/mingw-ldd.py $line --dll-lookup-dirs $QTOX_PREFIX_DIR $WINE_DLL_DIR --output-format tree >> dlls-required
2021-10-31 07:44:30 +08:00
done < <( cat exes runtime-dlls)
# Check that no extra dlls get bundled
while IFS = read -r line
do
if ! grep -q " $line " dlls-required
then
echo " Error: extra dll included: $line . If this is a mistake and the dll is actually needed (e.g. it's loaded at runtime), please add it to the runtime dll list. "
exit 1
fi
done < dlls
# Check that no dll is missing
if grep -q 'not found' dlls-required
then
cat dlls-required
echo "Error: Missing some dlls."
exit 1
fi