From a0e4f451b1a0ee8f2a36ca6afddaed3f67c76d48 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Thu, 30 May 2024 02:14:50 +0300
Subject: [PATCH 78/78] meson-installer_build.sh: Support building from a
 separate builddir

See RM #686

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 .../installer_cross/meson-installer_build.sh  | 98 ++++++++++---------
 1 file changed, 50 insertions(+), 48 deletions(-)

diff --git a/platforms/windows/installer_cross/meson-installer_build.sh b/platforms/windows/installer_cross/meson-installer_build.sh
index 97e5720496..a823cb5744 100755
--- a/platforms/windows/installer_cross/meson-installer_build.sh
+++ b/platforms/windows/installer_cross/meson-installer_build.sh
@@ -76,7 +76,7 @@ add_gtk3_env() {
   mkdir -p $2/etc &&
   cp -R $1/etc/gtk-3.0 $2/etc/ &&
   cp $1/bin/gtk-update-icon-cache.exe $2/bin/ &&
-  cp ./helpers/installer-helper-gtk3.cmd $2/bin/installer-helper.cmd
+  cp "${SRC_DIR}/helpers/installer-helper-gtk3.cmd" $2/bin/installer-helper.cmd
 }
 
 add_gtk4_env() {
@@ -87,7 +87,7 @@ add_gtk4_env() {
   cp $1/bin/libtiff-6.dll $2/ &&
   cp $1/bin/gdbus.exe $2/ &&
   cp $1/bin/gtk4-update-icon-cache.exe $2/bin/ &&
-  cp ./helpers/installer-helper-gtk4.cmd $2/bin/installer-helper.cmd
+  cp "${SRC_DIR}/helpers/installer-helper-gtk4.cmd" $2/bin/installer-helper.cmd
 }
 
 add_qt6_env() {
@@ -98,7 +98,7 @@ add_qt6_env() {
   cp $1/bin/Qt6Widgets.dll $2/ &&
   cp $1/bin/libpcre2-16-0.dll $2/ &&
   mkdir -p $2/bin &&
-  cp ./helpers/installer-helper-qt.cmd $2/bin/installer-helper.cmd
+  cp "${SRC_DIR}/helpers/installer-helper-qt.cmd" $2/bin/installer-helper.cmd
 }
 
 add_sdl2_env() {
@@ -115,7 +115,7 @@ fi
 DLLSPATH="$1"
 GUI="$2"
 
-case $GUI in
+case ${GUI} in
   gtk3.22)
     GUINAME="GTK3.22"
     MPGUI="gtk3"
@@ -152,23 +152,24 @@ if ! test -d "$DLLSPATH" ; then
   exit 1
 fi
 
-if ! ./meson-winbuild.sh "$DLLSPATH" "$GUI" ; then
+SRC_DIR="$(cd "$(dirname "$0")" || exit 1 ; pwd)"
+SRC_ROOT="$(cd "${SRC_DIR}/../../.." || exit 1 ; pwd)"
+BUILD_ROOT="$(pwd)"
+
+if ! "${SRC_DIR}/meson-winbuild.sh" "${DLLSPATH}" "${GUI}" ; then
   exit 1
 fi
 
 SETUP=$(grep "CrosserSetup=" $DLLSPATH/crosser.txt | sed -e 's/CrosserSetup="//' -e 's/"//')
-
-SRC_ROOT="$(cd ../../.. || exit 1 ; pwd)"
-
 VERREV="$("${SRC_ROOT}/fc_version")"
 
-if ! ( cd "meson/build/${SETUP}-${GUI}" && ninja langstat_core.txt ) ; then
+if ! ( cd "${BUILD_ROOT}/meson/build/${SETUP}-${GUI}" && ninja langstat_core.txt ) ; then
   echo "langstat_core.txt creation failed!" >&2
   exit 1
 fi
 
-if test "$GUI" = "ruledit" &&
-   ! ( cd "meson/build/${SETUP}-${GUI}" && ninja langstat_ruledit.txt ) ; then
+if test "${GUI}" = "ruledit" &&
+   ! ( cd "${BUILD_ROOT}/meson/build/${SETUP}-${GUI}" && ninja langstat_ruledit.txt ) ; then
   echo "langstat_ruledit.txt creation failed!" >&2
   exit 1
 fi
@@ -179,35 +180,35 @@ if test "${INST_CROSS_MODE}" != "release" ; then
   fi
 fi
 
-INSTDIR="meson/install/freeciv-${VERREV}-${SETUP}-${GUI}"
+INSTDIR="${BUILD_ROOT}/meson/install/freeciv-${VERREV}-${SETUP}-${GUI}"
 
-if ! mv $INSTDIR/bin/* $INSTDIR/ ||
-   ! mv $INSTDIR/share/freeciv $INSTDIR/data ||
-   ! mv $INSTDIR/share/doc $INSTDIR/ ||
-   ! mkdir -p $INSTDIR/doc/freeciv/installer ||
-   ! cat licenses/header.txt "${SRC_ROOT}/COPYING" \
+if ! mv "${INSTDIR}/bin/"* "${INSTDIR}/" ||
+   ! mv "${INSTDIR}/share/freeciv" "${INSTDIR}/data" ||
+   ! mv "${INSTDIR}/share/doc" "${INSTDIR}/" ||
+   ! mkdir -p "${INSTDIR}/doc/freeciv/installer" ||
+   ! cat "${SRC_DIR}/licenses/header.txt" "${SRC_ROOT}/COPYING" \
      > "${INSTDIR}/doc/freeciv/installer/COPYING.installer" ||
-   ! rm -Rf $INSTDIR/lib ||
-   ! cp Freeciv.url $INSTDIR/
+   ! rm -Rf "${INSTDIR}/lib" ||
+   ! cp "${SRC_DIR}/Freeciv.url" "${INSTDIR}/"
 then
   echo "Rearranging install directory failed!" >&2
   exit 1
 fi
 
-if ! add_common_env "$DLLSPATH" "$INSTDIR" ; then
+if ! add_common_env "${DLLSPATH}" "${INSTDIR}" ; then
   echo "Copying common environment failed!" >&2
   exit 1
 fi
 
-NSI_DIR="meson/nsi"
+NSI_DIR="${BUILD_ROOT}/meson/nsi"
 
-if ! mkdir -p "$NSI_DIR" ; then
-  echo "Creating \"$NSI_DIR\" directory failed" >&2
+if ! mkdir -p "${NSI_DIR}" ; then
+  echo "Creating \"${NSI_DIR}\" directory failed" >&2
   exit 1
 fi
 
-if test "$GUI" = "ruledit" ; then
-  if ! cp freeciv-ruledit.cmd "${INSTDIR}/"
+if test "${GUI}" = "ruledit" ; then
+  if ! cp "${SRC_DIR}/freeciv-ruledit.cmd" "${INSTDIR}/"
   then
     echo "Adding cmd-file failed!" >&2
     exit 1
@@ -219,50 +220,51 @@ if test "$GUI" = "ruledit" ; then
 
   NSI_FILE="${NSI_DIR}/ruledit-${SETUP}-${VERREV}.nsi"
 
-  if ! ./create-freeciv-ruledit-nsi.sh \
-         "${INSTDIR}" "meson/output" "${VERREV}" "qt6" "Qt6" "${SETUP}" \
+  if ! "${SRC_DIR}/create-freeciv-ruledit-nsi.sh" \
+         "${INSTDIR}" "${BUILD_ROOT}/meson/output" "${VERREV}" "qt6" "Qt6" "${SETUP}" \
            > "${NSI_FILE}"
   then
     exit 1
   fi
 else
-  if ! cp freeciv-server.cmd freeciv-${CLIENT}.cmd freeciv-mp-${FCMP}.cmd $INSTDIR/
+  if ! cp "${SRC_DIR}/freeciv-server.cmd" "${SRC_DIR}/freeciv-${CLIENT}.cmd" \
+          "${SRC_DIR}/freeciv-mp-${FCMP}.cmd" "${INSTDIR}/"
   then
     echo "Adding cmd-files failed!" >&2
     exit 1
   fi
 
-  if ! add_sdl2_mixer_env "$DLLSPATH" "$INSTDIR" ; then
+  if ! add_sdl2_mixer_env "${DLLSPATH}" "${INSTDIR}" ; then
     echo "Copying SDL2_mixer environment failed!" >&2
     exit 1
   fi
 
-  case $GUI in
+  case ${GUI} in
     gtk3.22)
-      if ! add_gtk3_env "$DLLSPATH" "$INSTDIR" ; then
+      if ! add_gtk3_env "${DLLSPATH}" "${INSTDIR}" ; then
         echo "Copying gtk3 environment failed!" >&2
         exit 1
       fi
       ;;
     gtk4|gtk4x)
-      if ! add_gtk4_env "$DLLSPATH" "$INSTDIR" ; then
+      if ! add_gtk4_env "${DLLSPATH}" "${INSTDIR}" ; then
         echo "Copying gtk4 environment failed!" >&2
         exit 1
       fi
       ;;
     sdl2)
       # For gtk4 modpack installer
-      if ! add_gtk4_env "$DLLSPATH" "$INSTDIR" ; then
+      if ! add_gtk4_env "${DLLSPATH}" "${INSTDIR}" ; then
         echo "Copying gtk3 environment failed!" >&2
         exit 1
       fi
-      if ! add_sdl2_env "$DLLSPATH" "$INSTDIR" ; then
+      if ! add_sdl2_env "${DLLSPATH}" "${INSTDIR}" ; then
         echo "Copying sdl2 environment failed!" >&2
         exit 1
       fi
       ;;
     qt6)
-      if ! cp freeciv-ruledit.cmd "${INSTDIR}"
+      if ! cp "${SRC_DIR}/freeciv-ruledit.cmd" "${INSTDIR}"
       then
         echo "Adding cmd-file failed!" >&2
         exit 1
@@ -280,39 +282,39 @@ else
     EXE_ID="${GUI}"
   fi
 
-  if test "$GUI" = "gtk3.22" || test "$GUI" = "gtk4" ||
-     test "$GUI" = "gtk4x" || test "$GUI" = "sdl2" ; then
-    UNINSTALLER="helpers/uninstaller-helper-gtk3.sh"
+  if test "${GUI}" = "gtk3.22" || test "${GUI}" = "gtk4" ||
+     test "${GUI}" = "gtk4x" || test "${GUI}" = "sdl2" ; then
+    UNINSTALLER="${SRC_DIR}/helpers/uninstaller-helper-gtk3.sh"
   else
     UNINSTALLER=""
   fi
 
   NSI_FILE="${NSI_DIR}/client-${SETUP}-${VERREV}-${GUI}.nsi"
 
-  if test "$GUI" = "sdl2" ; then
-    if ! ./create-freeciv-sdl2-nsi.sh \
-           "$INSTDIR" "meson/output" "$VERREV" "$SETUP" "$UNINSTALLER" \
-             > "$NSI_FILE"
+  if test "${GUI}" = "sdl2" ; then
+    if ! "${SRC_DIR}/create-freeciv-sdl2-nsi.sh" \
+           "${INSTDIR}" "${BUILD_ROOT}/meson/output" "${VERREV}" "${SETUP}" "${UNINSTALLER}" \
+             > "${NSI_FILE}"
     then
       exit 1
     fi
   else
-    if ! ./create-freeciv-gtk-qt-nsi.sh \
-           "$INSTDIR" "meson/output" "$VERREV" "$GUI" "$GUINAME" \
-           "$SETUP" "$MPGUI" "$EXE_ID" "$UNINSTALLER" \
-             > "$NSI_FILE"
+    if ! "${SRC_DIR}/create-freeciv-gtk-qt-nsi.sh" \
+           "${INSTDIR}" "${BUILD_ROOT}/meson/output" "${VERREV}" "${GUI}" "${GUINAME}" \
+           "${SETUP}" "${MPGUI}" "${EXE_ID}" "${UNINSTALLER}" \
+             > "${NSI_FILE}"
     then
       exit 1
     fi
   fi
 fi
 
-if ! mkdir -p meson/output ; then
+if ! mkdir -p "${BUILD_ROOT}/meson/output" ; then
   echo "Creating meson/output directory failed" >&2
   exit 1
 fi
 
-if ! makensis -NOCD "$NSI_FILE"
+if ! makensis -NOCD "${NSI_FILE}"
 then
   echo "Creating installer failed!" >&2
   exit 1
-- 
2.43.0

