From 7bca4aee1771d7b39208af57858b5508b942d51f Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 10 Nov 2024 02:33:38 +0200
Subject: [PATCH 44/44] 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                    | 27 +++++++++++++--------------
 4 files changed, 28 insertions(+), 37 deletions(-)

diff --git a/bootstrap/Makefile.am b/bootstrap/Makefile.am
index 5872ed8673..af6d1ce5f9 100644
--- a/bootstrap/Makefile.am
+++ b/bootstrap/Makefile.am
@@ -105,7 +105,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..26ebc9d22f 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)"
+. ../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 90b59a9527..13dcb15239 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1378,14 +1378,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_22_cflags])
 AC_SUBST([gui_gtk3_22_libs])
 AC_SUBST([gui_gtk3_22_ldflags])
diff --git a/meson.build b/meson.build
index f81d072213..4aaac3b9b5 100644
--- a/meson.build
+++ b/meson.build
@@ -1101,15 +1101,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'),
@@ -1524,8 +1524,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'))
@@ -3309,7 +3308,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'))
@@ -3398,7 +3397,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'))
@@ -3677,7 +3676,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'))
@@ -3819,7 +3818,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'))
@@ -3951,7 +3950,7 @@ custom_target('mi_sdl3',
               input: 'bootstrap/org.freeciv.sdl3.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'))
@@ -4052,7 +4051,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'))
@@ -4090,7 +4089,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'))
@@ -4135,7 +4134,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'))
@@ -4280,7 +4279,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

