From 090cb0af627b6d07d9e754c0ceda3d61cc72a897 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Tue, 2 Apr 2024 22:07:24 +0300
Subject: [PATCH 21/21] AppImage: Add build_appimages.sh

See RM #396

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

diff --git a/Makefile.am b/Makefile.am
index 6438f42270..6d75a35fbd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -100,7 +100,8 @@ EXTRA_DIST =	autogen.sh 			\
 		flatpak/org.freeciv.qt.yml	\
 		flatpak/org.freeciv.sdl2.yml	\
 		flatpak/org.freeciv.ruledit.yml	\
-		platforms/macos/homebrew-appbundle.sh \
+		platforms/appimage/build_appimages.sh	\
+		platforms/macos/homebrew-appbundle.sh	\
 		scripts/mapimg2anim		\
 		scripts/setup_auth_server.sh	\
 		scripts/replace			\
diff --git a/platforms/appimage/build_appimages.sh b/platforms/appimage/build_appimages.sh
new file mode 100755
index 0000000000..fd3f6401f4
--- /dev/null
+++ b/platforms/appimage/build_appimages.sh
@@ -0,0 +1,58 @@
+#!/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 -Dack_experimental=true -Dappimage=true -Dprefix=/usr -Ddefault_library=static \
+                 -Dclients=[] -Dfcmp=[] -Druledit=false "${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

