From 962fc25a4908913d72a7a53dbdf8dd57e32d8ff6 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Tue, 2 Apr 2024 22:02:14 +0300
Subject: [PATCH 41/41] AppImage: Add build_appimages.sh

See RM #396

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 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/Makefile.am b/Makefile.am
index 49f0e1b277..f6538f7f69 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -86,6 +86,7 @@ EXTRA_DIST =	autogen.sh 			\
 		m4/testmatic.m4			\
 		meson.build			\
 		meson_options.txt		\
+		platforms/appimage/build_appimages.sh		\
 		platforms/emscripten/emsbuild.sh		\
 		platforms/emscripten/setups/cross-ems.tmpl	\
 		platforms/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

