Skip to content

Commit

Permalink
style: Reformat windows cross compile shell script.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Nov 23, 2024
1 parent 8cd1b73 commit d5e71dd
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 88 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# cmake-format: off
# SPDX-License-Identifier: GPL-3.0-or-later.
# Copyright © 2019 by The qTox Project Contributors.
# Copyright © 2024 The TokTok team.
# Copyright © 2019 by The qTox Project Contributors
# Copyright © 2024 The TokTok team
# cmake-format: on

# ##############################################################################
#
Expand Down
168 changes: 82 additions & 86 deletions windows/cross-compile/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,29 @@ set -euo pipefail

RUN_TESTS=0

while (( $# > 0 )); do
case $1 in
--src-dir) QTOX_SRC_DIR=$2; shift 2 ;;
--arch) ARCH=$2; shift 2 ;;
--run-tests) RUN_TESTS=1; shift ;;
--build-type) BUILD_TYPE=$2; shift 2;;
*) "Unexpected argument $1"; exit 1 ;;
esac
while (($# > 0)); do
case $1 in
--src-dir)
QTOX_SRC_DIR=$2
shift 2
;;
--arch)
ARCH=$2
shift 2
;;
--run-tests)
RUN_TESTS=1
shift
;;
--build-type)
BUILD_TYPE=$2
shift 2
;;
*)
"Unexpected argument $1"
exit 1
;;
esac
done

# Common directory paths
Expand All @@ -30,14 +45,12 @@ readonly QTOX_PREFIX_DIR
QTOX_PACKAGE_DIR="$(realpath package-prefix)"
readonly QTOX_PACKAGE_DIR

if [ -z "$ARCH" ]
then
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
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
Expand All @@ -46,60 +59,55 @@ if [ -z "$QTOX_SRC_DIR" ]; then
echo "--src-dir must be specified"
fi

if [ -z "$BUILD_TYPE" ]
then
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
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

export PKG_CONFIG_PATH=/windows/lib64/pkgconfig

# Spell check on windows currently not supported, disable
if [[ "$BUILD_TYPE" == "Release" ]]
then
if [[ "$BUILD_TYPE" == "Release" ]]; then
cmake -DCMAKE_TOOLCHAIN_FILE=/build/windows-toolchain.cmake \
-DCMAKE_LIBRARY_PATH=/windows/lib64 \
-DCMAKE_PREFIX_PATH=/windows \
-DCMAKE_BUILD_TYPE=Release \
-DSPELL_CHECK=OFF \
-DDESKTOP_NOTIFICATIONS=OFF \
-DUPDATE_CHECK=ON \
-DSTRICT_OPTIONS=ON \
-DTEST_CROSSCOMPILING_EMULATOR=wine \
-GNinja \
"$QTOX_SRC_DIR"
elif [[ "$BUILD_TYPE" == "Debug" ]]
then
-DCMAKE_LIBRARY_PATH=/windows/lib64 \
-DCMAKE_PREFIX_PATH=/windows \
-DCMAKE_BUILD_TYPE=Release \
-DSPELL_CHECK=OFF \
-DDESKTOP_NOTIFICATIONS=OFF \
-DUPDATE_CHECK=ON \
-DSTRICT_OPTIONS=ON \
-DTEST_CROSSCOMPILING_EMULATOR=wine \
-GNinja \
"$QTOX_SRC_DIR"
elif [[ "$BUILD_TYPE" == "Debug" ]]; then
cmake -DCMAKE_TOOLCHAIN_FILE=/build/windows-toolchain.cmake \
-DCMAKE_LIBRARY_PATH=/windows/lib64 \
-DCMAKE_PREFIX_PATH=/windows \
-DCMAKE_BUILD_TYPE=Debug \
-DSPELL_CHECK=OFF \
-DDESKTOP_NOTIFICATIONS=OFF \
-DUPDATE_CHECK=ON \
-DSTRICT_OPTIONS=ON \
-DTEST_CROSSCOMPILING_EMULATOR=wine \
-GNinja \
-DCMAKE_EXE_LINKER_FLAGS="-mconsole" \
"$QTOX_SRC_DIR"
-DCMAKE_LIBRARY_PATH=/windows/lib64 \
-DCMAKE_PREFIX_PATH=/windows \
-DCMAKE_BUILD_TYPE=Debug \
-DSPELL_CHECK=OFF \
-DDESKTOP_NOTIFICATIONS=OFF \
-DUPDATE_CHECK=ON \
-DSTRICT_OPTIONS=ON \
-DTEST_CROSSCOMPILING_EMULATOR=wine \
-GNinja \
-DCMAKE_EXE_LINKER_FLAGS="-mconsole" \
"$QTOX_SRC_DIR"
fi

cmake --build .

mkdir -p "${QTOX_PREFIX_DIR}"
cp qtox.exe $QTOX_PREFIX_DIR
cp -r /export/* $QTOX_PREFIX_DIR
mkdir -p "$QTOX_PREFIX_DIR"
cp qtox.exe "$QTOX_PREFIX_DIR"
cp -r /export/* "$QTOX_PREFIX_DIR"

# Run tests
set +u
if [[ $RUN_TESTS -ne 0 ]]
then
if [[ $RUN_TESTS -ne 0 ]]; then
export WINEPATH='/export;/windows/bin'
export CTEST_OUTPUT_ON_FAILURE=1
export PATH="$PATH:/opt/wine-stable/bin"
Expand All @@ -110,41 +118,36 @@ set -u

# Strip
set +e
if [[ "$BUILD_TYPE" == "Release" ]]
then
$ARCH-w64-mingw32-strip -s $QTOX_PREFIX_DIR/*.exe
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
"$ARCH-w64-mingw32-strip" -s "$QTOX_PREFIX_DIR"/*.dll
"$ARCH-w64-mingw32-strip" -s "$QTOX_PREFIX_DIR"/*/*.dll
set -e

if [[ "$BUILD_TYPE" == "Debug" ]]
then
cp -r /debug_export/* ${QTOX_PREFIX_DIR}
if [[ "$BUILD_TYPE" == "Debug" ]]; then
cp -r /debug_export/* "$QTOX_PREFIX_DIR"
fi

# Create zip
pushd $QTOX_PREFIX_DIR
zip qtox-"$ARCH"-"$BUILD_TYPE".zip -r *
pushd "$QTOX_PREFIX_DIR"
zip "qtox-$ARCH-$BUILD_TYPE.zip" -r *
popd

# Create installer
if [[ "$BUILD_TYPE" == "Release" ]]
then
mkdir -p $QTOX_PACKAGE_DIR
pushd $QTOX_PACKAGE_DIR
if [[ "$BUILD_TYPE" == "Release" ]]; then
mkdir -p "$QTOX_PACKAGE_DIR"
pushd "$QTOX_PACKAGE_DIR"
# The installer creation script expects all the files to be in qtox/*
mkdir -p qtox
cp -r $QTOX_PREFIX_DIR/* ./qtox
cp -r "$QTOX_PREFIX_DIR"/* ./qtox
rm ./qtox/*.zip

cp -r $QTOX_SRC_DIR/windows/* .
cp -r "$QTOX_SRC_DIR"/windows/* .
# Select the installer script for the correct architecture
if [[ "$ARCH" == "i686" ]]
then
if [[ "$ARCH" == "i686" ]]; then
makensis qtox.nsi
elif [[ "$ARCH" == "x86_64" ]]
then
elif [[ "$ARCH" == "x86_64" ]]; then
makensis qtox64.nsi
fi

Expand All @@ -153,8 +156,8 @@ fi

# dll check
# Create lists of all .exe and .dll files
find "$QTOX_PREFIX_DIR" -iname '*.dll' > dlls
find "$QTOX_PREFIX_DIR" -iname '*.exe' > exes
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)
Expand All @@ -180,42 +183,35 @@ 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="/usr/lib/x86_64-linux-gnu/wine/i386-windows"
elif [[ "$ARCH" == "x86_64" ]]
then
WINE_DLL_DIR="/usr/lib/x86_64-linux-gnu/wine/x86_64-windows /usr/lib/x86_64-linux-gnu/wine/i386-windows"
while IFS= read -r line; do
if [[ "$ARCH" == "i686" ]]; then
WINE_DLL_DIR=("/usr/lib/x86_64-linux-gnu/wine/i386-windows")
elif [[ "$ARCH" == "x86_64" ]]; then
WINE_DLL_DIR=("/usr/lib/x86_64-linux-gnu/wine/x86_64-windows" "/usr/lib/x86_64-linux-gnu/wine/i386-windows")
fi
python3 /usr/local/bin/mingw-ldd.py $line --dll-lookup-dirs $QTOX_PREFIX_DIR $WINE_DLL_DIR --output-format tree >> dlls-required
python3 /usr/local/bin/mingw-ldd.py "$line" --dll-lookup-dirs "$QTOX_PREFIX_DIR" "${WINE_DLL_DIR[@]}" --output-format tree >>dlls-required
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
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
done <dlls

# Check that no dll is missing. Ignore api-ms-win-*.dll, because they are
# symbolic names pointing at kernel32.dll, user32.dll, etc.
#
# See https://github.com/nurupo/mingw-ldd/blob/master/README.md#api-set-dlls
if grep -q 'not found' dlls-required | grep -q -v 'api-ms-win-'
then
if grep -q 'not found' dlls-required | grep -q -v 'api-ms-win-'; then
cat dlls-required
echo "Error: Missing some dlls."
exit 1
fi

# Check that OpenAL is bundled. It is availabe from WINE, but not on Windows systems
if grep -q '/opt/wine-stable/lib/wine/i386-windows/openal32.dll' dlls-required
then
if grep -q '/opt/wine-stable/lib/wine/i386-windows/openal32.dll' dlls-required; then
cat dlls-required
echo "Error: Missing OpenAL."
exit 1
Expand Down

0 comments on commit d5e71dd

Please sign in to comment.