view build-win32.sh @ 298:02d2dec01f0f

Fixes to the win32 build script.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 10 May 2023 14:19:32 +0300
parents 958451fcd85a
children 3cca82bced54
line wrap: on
line source

#!/bin/sh
INSTALL_USB="/mnt/sdb1"
INSTALL_WINE="$HOME/.wine/drive_c/Syntilista/"
TMPFILE="unix2dos.tmp"

MINGW_CPP="i686-w64-mingw32-g++"
BINPATH="win32/"

QT_VERSION_PREFIX="Qt5"
QT_BASE="/misc/packages/qt5-src/qtbase"



fatal()
{
    echo "ERROR: $1"
    exit 1
}


do_cp()
{
    cp -f "$1" "$2" || fatal "Could not copy file '$1' to '$2'."
}


do_mkdir()
{
    mkdir -p "$1" || fatal "Could not create directory '$1'."
}


do_cpinstall()
{
    # $1 src base path
    # $2 dst base path
    # $3 common sub path
    # $4 filename

    do_mkdir "$2/$3"
    do_cp "$1/$3/$4" "$2/$3/$4"
}


do_install()
{
    TARGET="$1"

    if test -d "$TARGET"; then
        rm -fr "$TARGET"
    elif test -e "$TARGET"; then
        fatal "Target '$TARGET' exists but is not a directory!"
    fi

    mkdir -p "$TARGET" || fatal "Could not create target directory '$TARGET'."

    echo "Installing to '${TARGET}' ..."

    do_cpinstall "${QT_BASE}/plugins/" "$TARGET" "platforms" "qwindows.dll"
    do_cpinstall "${QT_BASE}/plugins/" "$TARGET" "sqldrivers" "qsqlite.dll"
    do_cpinstall "${QT_BASE}/plugins/" "$TARGET" "printsupport" "windowsprintersupport.dll"

    for i in Core Gui Sql Widgets PrintSupport Network; do
        do_cp "${QT_BASE}/lib/${QT_VERSION_PREFIX}${i}.dll" "$TARGET"
    done

    for i in libstdc++-6 libgcc_s_sjlj-1; do
        do_cp "${MINGW_PATH}/${i}.dll" "$TARGET"
        strip "${TARGET}/${i}.dll"
    done

    for i in zlib1.dll; do
        do_cp "${MINGW_LIBS}/${i}" "$TARGET"
    done

    do_cp "$BINPATH/Syntilista.exe" "$TARGET"
    unix2dos -n "COPYING.html" "$TMPFILE" || fatal "Could not unix2dos."
    do_cp "$TMPFILE" "$TARGET/COPYING.txt"
    rm -f "$TMPFILE"
}


### Check dirs
MINGW_PATH="$(dirname $(realpath $($MINGW_CPP -print-prog-name=cc1)))"
MINGW_LIBS="$(dirname $(realpath $($MINGW_CPP -print-file-name=zlib1.dll)))"
test -d "$MINGW_PATH" || fatal "Could not find MinGW C++ compiler path!"
test -d "$MINGW_LIBS" || fatal "Could not find MinGW library path (zlib1.dll not found)"

### Build the binaries
echo "QT: ${QT_BASE} / MinGW: ${MINGW_PATH}"
make -f Makefile.cross-mingw QT_PREFIX="$QT_BASE" BINPATH="$BINPATH" || fatal "Compilation failed."

### Install to targets
if test -d "$INSTALL_USB" && mount|grep -q "$INSTALL_USB"; then
    do_install "$INSTALL_USB/Syntilista"
else
    echo "INFO: '$INSTALL_USB' is not mounted. Not installing."
fi
#do_install "$INSTALL_WINE"