From b0d0013ecf78d990a2d273c3598007ecb19aa104 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 10 Nov 2024 02:35:48 +0200
Subject: [PATCH 31/31] Meson: Fix metainfo generation

See RM #1098

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 bootstrap/Makefile.am          |  2 +-
 bootstrap/generate_metainfo.sh | 28 ++++++++++++++--------------
 configure.ac                   |  8 --------
 meson.build                    | 25 ++++++++++++-------------
 4 files changed, 27 insertions(+), 36 deletions(-)

diff --git a/bootstrap/Makefile.am b/bootstrap/Makefile.am
index 1f100f2fba..64256393ed 100644
--- a/bootstrap/Makefile.am
+++ b/bootstrap/Makefile.am
@@ -109,7 +109,7 @@ langstat_ruledit.txt:
 
 $(metainfofile_DATA) : %.metainfo.xml: %.metainfo.xml.in generate_metainfo.sh $(top_srcdir)/fc_version
 	@if ! $(AM_V_P) ; then echo "  metainfo $@" ; fi
-	$(AM_V_at) "$(top_srcdir)/bootstrap/generate_metainfo.sh" "$@" "$(top_builddir)/bootstrap" "@RELEASE_TYPE@" "@RELEASE_DATE@" "@NEWS_URL@"
+	$(AM_V_at) "$(top_srcdir)/bootstrap/generate_metainfo.sh" "$@" "$(top_builddir)/bootstrap"
 
 metainfo_stamp: $(metainfofile_DATA)
 
diff --git a/bootstrap/generate_metainfo.sh b/bootstrap/generate_metainfo.sh
index 97c8fd3c3c..a585bc990b 100755
--- a/bootstrap/generate_metainfo.sh
+++ b/bootstrap/generate_metainfo.sh
@@ -13,9 +13,8 @@
 #
 #***********************************************************************/
 
-if test "$1" = "-h" || test "$1" = "--help" || test "$1" = "" || test "$2" = "" ||
-   test "$3" = "" ; then
-  echo "Usage: $(basename $0) <target file> <build root directory> <stable/development> [date] [URL]"
+if test "$1" = "-h" || test "$1" = "--help" || test "$1" = "" || test "$2" = "" ; then
+  echo "Usage: $(basename $0) <target file> <build root directory>"
   exit
 fi
 
@@ -23,28 +22,29 @@ export BDIR="$(cd ${2} | exit 1 ; pwd)"
 
 cd "$(dirname $0)"
 
-FCVER="$(../fc_version)"
+VERSION_SCRIPT_SILENT=yes . ../fc_version
 
-if test "$3" != "stable" && test "$3" != "development" ; then
-  echo "Unknown release type \"$3\"" >&2
+FCVER="${VERSION_STRING}${VERSION_REV}"
+
+if test "${RELEASE_TYPE}" != "stable" && test "${RELEASE_TYPE}" != "development" ; then
+  echo "Unknown release type \"${RELEASE_TYPE}\"" >&2
   exit 1
 fi
-RELTYPE="$3"
 
-if test "$4" != "" ; then
-  if test "$5" != "" ; then
-    RELEASETAG="<release version=\"${FCVER}\" type=\"${RELTYPE}\" date=\"$4\"><url>$5</url></release>"
+if test "${RELEASE_DATE}" != "" ; then
+  if test "${NEWS_URL}" != "" ; then
+    RELEASETAG="<release version=\"${FCVER}\" type=\"${RELEASE_TYPE}\" date=\"${RELEASE_DATE}\"><url>${NEWS_URL}</url></release>"
   else
-    RELEASETAG="<release version=\"${FCVER}\" type=\"${RELTYPE}\" date=\"$4\" />"
+    RELEASETAG="<release version=\"${FCVER}\" type=\"${RELEASE_TYPE}\" date=\"${RELEASE_DATE}\" />"
   fi
 else
   # Tag with no date causes format checker warning, but
   # flatpak builder outright errors if there's no <release> tag
   # at all within <releases> ... </releases> list
-  if test "$5" = "" ; then
-    RELEASETAG="<release version=\"${FCVER}\" type=\"${RELTYPE}\" />"
+  if test "${NEWS_URL}" = "" ; then
+    RELEASETAG="<release version=\"${FCVER}\" type=\"${RELEASE_TYPE}\" />"
   else
-    RELEASETAG="<release version=\"${FCVER}\" type=\"${RELTYPE}\"><url>$5</url></release>"
+    RELEASETAG="<release version=\"${FCVER}\" type=\"${RELEASE_TYPE}\"><url>${NEWS_URL}</url></release>"
   fi
 fi
 
diff --git a/configure.ac b/configure.ac
index fe2837f7f0..d24df71c13 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1444,14 +1444,6 @@ AC_DEFINE_UNQUOTED([AI_MOD_DEFAULT], ["${default_ai_set}"], [Default ai type nam
 AM_CONDITIONAL([SRV_LIB],
   [test "x$server" = "xyes" || test "x$fcmanual" = "xyes" || test "x$ruledit" = "xyes" || test "x$fcruleup" = "xyes"])
 
-AC_SUBST([RELEASE_TYPE])
-
-if test "$RELEASE_TYPE" = "stable" ; then
-  AC_SUBST([RELEASE_DATE])
-  AC_SUBST([NEWS_URL])
-  :
-fi
-
 AC_SUBST([gui_gtk3_cflags])
 AC_SUBST([gui_gtk3_libs])
 AC_SUBST([gui_gtk3_ldflags])
diff --git a/meson.build b/meson.build
index 07193fa3f9..cfdea556cd 100644
--- a/meson.build
+++ b/meson.build
@@ -889,15 +889,15 @@ verhdr = custom_target('verhdr', output: 'version_gen.h',
 
 ls_core = custom_target('langstat_core', output: 'langstat_core.txt',
               command: [sh_exe, files('bootstrap/generate_langstat.sh'), 'core',
-                        meson.project_source_root(), meson.project_build_root()])
+                        meson.project_source_root(), b_root])
 
 ls_nations = custom_target('langstat_nations', output: 'langstat_nations.txt',
                command: [sh_exe, files('bootstrap/generate_langstat.sh'), 'nations',
-                          meson.project_source_root(), meson.project_build_root()])
+                          meson.project_source_root(), b_root])
 
 ls_ruledit = custom_target('langstat_ruledit', output: 'langstat_ruledit.txt',
                 command: [sh_exe, files('bootstrap/generate_langstat.sh'), 'ruledit',
-                          meson.project_source_root(), meson.project_build_root()])
+                          meson.project_source_root(), b_root])
 
 specenum = custom_target('specenum_gen.h', output: 'specenum_gen.h',
                          command: [python_exe, files('utility/generate_specenum.py'),
@@ -1288,8 +1288,7 @@ if server_type != 'disabled'
                 input: 'bootstrap/org.freeciv.server.metainfo.xml.in',
                 output: '@BASENAME@',
                 command: [sh_exe, files('bootstrap/generate_metainfo.sh'),
-                          '@OUTPUT@',
-                          meson.project_build_root(), 'development'],
+                          '@OUTPUT@', b_root],
                 depend_files: files('fc_version'),
                 install: true,
                 install_dir: join_paths(get_option('datadir'), 'metainfo'))
@@ -3036,7 +3035,7 @@ custom_target('mi_gtk322',
               input: 'bootstrap/org.freeciv.gtk322.metainfo.xml.in',
               output: '@BASENAME@',
               command: [sh_exe, files('bootstrap/generate_metainfo.sh'),
-                        '@OUTPUT@', b_root, 'development'],
+                        '@OUTPUT@', b_root],
               depend_files: files('fc_version'),
               install: true,
               install_dir: join_paths(get_option('datadir'), 'metainfo'))
@@ -3124,7 +3123,7 @@ custom_target('mi_gtk4',
               input: 'bootstrap/org.freeciv.gtk4.metainfo.xml.in',
               output: '@BASENAME@',
               command: [sh_exe, files('bootstrap/generate_metainfo.sh'),
-                        '@OUTPUT@', b_root, 'development'],
+                        '@OUTPUT@', b_root],
               depend_files: files('fc_version'),
               install: true,
               install_dir: join_paths(get_option('datadir'), 'metainfo'))
@@ -3401,7 +3400,7 @@ custom_target('mi_qt',
               input: 'bootstrap/org.freeciv.qt.metainfo.xml.in',
               output: '@BASENAME@',
               command: [sh_exe, files('bootstrap/generate_metainfo.sh'),
-                        '@OUTPUT@', b_root, 'development'],
+                        '@OUTPUT@', b_root],
               depend_files: files('fc_version'),
               install: true,
               install_dir: join_paths(get_option('datadir'), 'metainfo'))
@@ -3534,7 +3533,7 @@ custom_target('mi_sdl2',
               input: 'bootstrap/org.freeciv.sdl2.metainfo.xml.in',
               output: '@BASENAME@',
               command: [sh_exe, files('bootstrap/generate_metainfo.sh'),
-                        '@OUTPUT@', b_root, 'development'],
+                        '@OUTPUT@', b_root],
               depend_files: files('fc_version'),
               install: true,
               install_dir: join_paths(get_option('datadir'), 'metainfo'))
@@ -3588,7 +3587,7 @@ custom_target('mi_mp_gtk3',
               input: 'bootstrap/org.freeciv.gtk3.mp.metainfo.xml.in',
               output: '@BASENAME@',
               command: [sh_exe, files('bootstrap/generate_metainfo.sh'),
-                        '@OUTPUT@', b_root, 'development'],
+                        '@OUTPUT@', b_root],
               depend_files: files('fc_version'),
               install: true,
               install_dir: join_paths(get_option('datadir'), 'metainfo'))
@@ -3625,7 +3624,7 @@ custom_target('mi_mp_gtk4',
               input: 'bootstrap/org.freeciv.gtk4.mp.metainfo.xml.in',
               output: '@BASENAME@',
               command: [sh_exe, files('bootstrap/generate_metainfo.sh'),
-                        '@OUTPUT@', b_root, 'development'],
+                        '@OUTPUT@', b_root],
               depend_files: files('fc_version'),
               install: true,
               install_dir: join_paths(get_option('datadir'), 'metainfo'))
@@ -3669,7 +3668,7 @@ custom_target('mi_mp_qt',
               input: 'bootstrap/org.freeciv.qt.mp.metainfo.xml.in',
               output: '@BASENAME@',
               command: [sh_exe, files('bootstrap/generate_metainfo.sh'),
-                        '@OUTPUT@', b_root, 'development'],
+                        '@OUTPUT@', b_root],
               depend_files: files('fc_version'),
               install: true,
               install_dir: join_paths(get_option('datadir'), 'metainfo'))
@@ -3798,7 +3797,7 @@ custom_target('mi_ruledit',
               input: 'bootstrap/org.freeciv.ruledit.metainfo.xml.in',
               output: '@BASENAME@',
               command: [sh_exe, files('bootstrap/generate_metainfo.sh'),
-                        '@OUTPUT@', b_root, 'development'],
+                        '@OUTPUT@', b_root],
               depend_files: files('fc_version'),
               install: true,
               install_dir: join_paths(get_option('datadir'), 'metainfo'))
-- 
2.45.2

