From d41bec7efe7838e678d4731ae4711c4e67b2088a Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Tue, 2 Apr 2024 21:58:59 +0300
Subject: [PATCH 57/57] AppImage: Add build_appimages.sh

See RM #396

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 platforms/Makefile.am                 |  1 +
 platforms/appimage/build_appimages.sh | 57 +++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)
 create mode 100755 platforms/appimage/build_appimages.sh

diff --git a/platforms/Makefile.am b/platforms/Makefile.am
index 8342c429c8..5d505d2f68 100644
--- a/platforms/Makefile.am
+++ b/platforms/Makefile.am
@@ -3,6 +3,7 @@
 SUBDIRS = windows
 
 EXTRA_DIST =						\
+		appimage/build_appimages.sh		\
 		emscripten/emsbuild.sh			\
 		emscripten/setups/cross-ems.tmpl	\
 		flatpak/build_flatpak.sh		\
diff --git a/platforms/appimage/build_appimages.sh b/platforms/appimage/build_appimages.sh
new file mode 100755
index 0000000000..c1e5633cf1
--- /dev/null
+++ b/platforms/appimage/build_appimages.sh
@@ -0,0 +1,57 @@
+#!/usr/bin/env bash
+
+# build_appimages.sh: Build freeciv AppImages
+#
+# (c) 2024 Freeciv team
+#
+# This script is licensed under Gnu General Public License version 2 or later.
+# See COPYING available from the same location you got this script.
+
+LINUXDEPLOY_VERSION="1-alpha-20240109-1"
+
+if test "$1" != "" ; then
+  echo "Usage: $0"
+  exit 1
+fi
+
+BUILD_ROOT="$(pwd)"
+PLATFORM_ROOT="$(cd $(dirname "$0") && pwd)"
+SRC_ROOT="$(cd "$PLATFORM_ROOT/../.." && pwd)"
+
+if test "${PLATFORM_ROOT}" = "${BUILD_ROOT}" ; then
+  echo "Run $0 from a separate build directory." >&2
+  exit 1
+fi
+
+if ! mkdir AppDir ||
+   ! mkdir server
+then
+  echo "Failed to create required directories!" >&2
+  exit 1
+fi
+
+if ! wget "https://github.com/linuxdeploy/linuxdeploy/releases/download/${LINUXDEPLOY_VERSION}/linuxdeploy-x86_64.AppImage"
+then
+  echo "Failed to download linuxdeploy!" >&2
+  exit 1
+fi
+chmod u+x linuxdeploy-x86_64.AppImage
+
+cd server
+if ! meson setup -Dappimage=true -Dprefix=/usr -Ddefault_library=static -Dclients=[] -Dfcmp=[] -Dtools=[] "${SRC_ROOT}"
+then
+  echo "Setup with meson failed!" >&2
+  exit 1
+fi
+
+if ! DESTDIR="${BUILD_ROOT}/AppDir" ninja install ; then
+  echo "Build with ninja failed!" >&2
+  exit 1
+fi
+
+cd "${BUILD_ROOT}"
+if ! ./linuxdeploy-x86_64.AppImage --appdir AppDir --output appimage
+then
+  echo "Image build with linuxdeploy failed!" >&2
+  exit 1
+fi
-- 
2.43.0

