From f45d3faee1e11604bd8e04b4070d8d104b999298 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Tue, 21 Dec 2021 04:12:18 +0200
Subject: [PATCH 46/46] Replace --with-qt5 / --with-qt6 with
 --with-qtver=(qt5|qt6)

- Introduce new --with-qtver=(qt5|qt6) configure option
- Deprecate --with-qt5 / --with-qt6. They are not completely
  removed yet, to ease transition (many build scripts
  rely on them)

See osdn #43445

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 INSTALL                             |  6 +++---
 configure.ac                        | 20 +++++++++++++++++---
 doc/README.packaging                |  4 ++--
 scripts/ci-build.sh                 |  6 +++---
 windows/installer_cross/winbuild.sh |  2 +-
 windows/installer_msys2/Makefile    |  8 ++++----
 6 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/INSTALL b/INSTALL
index 93d9c4872f..1595abdff1 100644
--- a/INSTALL
+++ b/INSTALL
@@ -4,7 +4,7 @@ Installing Freeciv:
 
 This file describes how to compile and install Freeciv. Last time we
 made sure this file is up to date was 16-Jul-06.
-Last minor update was 10-Sep-21.
+Last minor update was 21-Dec-21.
 
 There may be a localized version of this file in the ./doc directory,
 named INSTALL.<locale> (e.g., INSTALL.de).
@@ -244,7 +244,7 @@ following order: pkg-config, Glib, Atk, Pango, Gdk-Pixbuf, Gtk+.
 
    Qt-client is written in C++, so you need appropriate compiler.
    Compiler needs to support c++17 standard, or,
-   in case of --with-qt5 build, just c++11 standard
+   in case of --with-qtver=qt5 build, just c++11 standard
 
    In Freeciv development, g++ has been the primary C++ compiler.
    Also clang++ has been used.
@@ -262,7 +262,7 @@ following order: pkg-config, Glib, Atk, Pango, Gdk-Pixbuf, Gtk+.
 
  - Qt6Core, Qt6Gui, and Qt6Widgets libraries and headers.
    At least version 6.0 is required.
-   If one configures with Qt5 compatibility switch --with-qt5,
+   If one configures with Qt5 compatibility switch --with-qtver=qt5,
    required libraries and headers are Qt5Core, Qt5Gui, and Qt5Widgets
    and at least version 5.11 of Qt is required.
 
diff --git a/configure.ac b/configure.ac
index 5bf2cba488..029936cecf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -661,9 +661,23 @@ dnl when setting compiler flags.
 AC_ARG_WITH([qt5],
   AS_HELP_STRING([--with-qt5], [build Qt5 versions of Qt programs]),
 [case "${withval}" in
- yes) qt_ver="Qt5" ;;
- *)   qt_ver="Qt6" ;;
-esac], [qt_ver="Qt6"])
+ yes) qt_default="Qt5" ;;
+ *)   qt_default="Qt6" ;;
+esac])
+
+if test "x$qt_default" = "x" ; then
+  qt_default="Qt6"
+else
+  AC_MSG_WARN([--with-qt5 deprecated. Please use --with-qtver=[qt5|qt6] instead])
+fi
+
+AC_ARG_WITH([qtver],
+  AS_HELP_STRING([--with-qtver], [which Qt version to build against qt5/qt6]),
+[case "${withval}" in
+ qt5|Qt5) qt_ver="Qt5" ;;
+ qt6|Qt6) qt_ver="Qt6" ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --with-qtver]) ;;
+esac], [qt_ver="$qt_default"])
 
 if test "x$qt_ver" = "xQt5" ; then
   AC_DEFINE([FC_QT5_MODE], [1], [this is Qt5 based build])
diff --git a/doc/README.packaging b/doc/README.packaging
index ba46636d3e..cee94c4b1a 100644
--- a/doc/README.packaging
+++ b/doc/README.packaging
@@ -18,8 +18,8 @@ Updating from 3.1 to 3.2
    ~/.freeciv-client-rc-3.0 generated by Freeciv 3.0,
    or ~/.civclientrc generated by Freeciv version <= 2.1).
 * Gtk3-client has been dropped
-* Qt6-mode is used by default. --with-qt6 configure option has been
-  replaced by --with-qt5 option.
+* Qt6-mode is used by default. Configure option --with-qtver=qt5
+  can be used to still build against Qt5
 
 ----------------------------------------------------------------------
 Compatibility of modified versions
diff --git a/scripts/ci-build.sh b/scripts/ci-build.sh
index cacdd071b3..36168d952c 100755
--- a/scripts/ci-build.sh
+++ b/scripts/ci-build.sh
@@ -51,7 +51,7 @@ cd build
 ../autogen.sh --no-configure-run
 ../configure \
  --enable-debug \
- --enable-sys-lua --with-qt6 \
+ --enable-sys-lua --with-qtver=qt6 \
  --enable-client=gtk3.22,sdl2,qt,gtk4 \
  --enable-fcmp=gtk3,gtk4,qt,cli \
  --enable-freeciv-manual \
@@ -74,7 +74,7 @@ cd build
  --enable-sys-lua \
  --enable-sys-tolua-cmd \
  --disable-fcdb \
- --with-qt5 \
+ --with-qtver=qt5 \
  --enable-client=gtk3.22,qt,sdl2,stub \
  --enable-fcmp=cli,gtk3,qt \
  --enable-freeciv-manual \
@@ -98,7 +98,7 @@ cd build
 ../autogen.sh \
  CFLAGS="-O3" \
  CXXFLAGS="-O3" \
- --with-qt5 \
+ --with-qtver=qt5 \
  --enable-client=gtk3.22,qt,sdl2,stub \
  --enable-fcmp=cli,gtk3,qt \
  --enable-freeciv-manual \
diff --git a/windows/installer_cross/winbuild.sh b/windows/installer_cross/winbuild.sh
index 5f2c436505..0bf4539fdd 100755
--- a/windows/installer_cross/winbuild.sh
+++ b/windows/installer_cross/winbuild.sh
@@ -155,7 +155,7 @@ else
   GITREVP=""
 fi
 
-if ! ../../../configure MOCCMD=${DLLSPATH}/bin/moc FREECIV_LABEL_FORCE="<base>-crs" CPPFLAGS="-I${DLLSPATH}/include -D_WIN32_WINNT=${MIN_WINVER}" CFLAGS="-Wno-error" PKG_CONFIG_LIBDIR="${DLLSPATH}/lib/pkgconfig" --with-qt5 --enable-sys-tolua-cmd --with-magickwand="${DLLSPATH}/bin" --prefix="/" $GITREVP --enable-client=$CLIENTS --enable-fcmp=$FCMP --enable-debug ${NLS} --host=$TARGET --build=$(../../../bootstrap/config.guess) --with-libiconv-prefix=${DLLSPATH} --with-sqlite3-prefix=${DLLSPATH} --with-followtag="crosser" --enable-crosser ${AIS} --disable-freeciv-manual --enable-sdl-mixer=sdl2 --with-qt5-includes=${DLLSPATH}/include --with-qt5-libs=${DLLSPATH}/lib --with-tinycthread --enable-server=$SERVER --enable-ruledit=$RULEDIT $EXTRA_CONFIG
+if ! ../../../configure MOCCMD=${DLLSPATH}/bin/moc FREECIV_LABEL_FORCE="<base>-crs" CPPFLAGS="-I${DLLSPATH}/include -D_WIN32_WINNT=${MIN_WINVER}" CFLAGS="-Wno-error" PKG_CONFIG_LIBDIR="${DLLSPATH}/lib/pkgconfig" --with-qtver=qt5 --enable-sys-tolua-cmd --with-magickwand="${DLLSPATH}/bin" --prefix="/" $GITREVP --enable-client=$CLIENTS --enable-fcmp=$FCMP --enable-debug ${NLS} --host=$TARGET --build=$(../../../bootstrap/config.guess) --with-libiconv-prefix=${DLLSPATH} --with-sqlite3-prefix=${DLLSPATH} --with-followtag="crosser" --enable-crosser ${AIS} --disable-freeciv-manual --enable-sdl-mixer=sdl2 --with-qt5-includes=${DLLSPATH}/include --with-qt5-libs=${DLLSPATH}/lib --with-tinycthread --enable-server=$SERVER --enable-ruledit=$RULEDIT $EXTRA_CONFIG
 then
   echo "Configure failed" >&2
   exit 1
diff --git a/windows/installer_msys2/Makefile b/windows/installer_msys2/Makefile
index da055fbc2e..9f6a4033bb 100644
--- a/windows/installer_msys2/Makefile
+++ b/windows/installer_msys2/Makefile
@@ -59,10 +59,10 @@ sdl2-installer:
 qt-installer: qt5-installer
 
 qt5-installer:
-	make GUI=qt5 CLIENT=qt FCMP=qt EXTRA_CONFIG="--with-qt5 --with-qt5-includes=/$(ARCHDIR)/include --with-qt5-libs=/$(ARCHDIR)/lib $(EXTRA_CONFIG)" wrap-qt5
+	make GUI=qt5 CLIENT=qt FCMP=qt EXTRA_CONFIG="--with-qtver=qt5 --with-qt5-includes=/$(ARCHDIR)/include --with-qt5-libs=/$(ARCHDIR)/lib $(EXTRA_CONFIG)" wrap-qt5
 
 qt6-installer:
-	make GUI=qt6 CLIENT=qt FCMP=qt EXTRA_CONFIG="--with-qt6-includes=/$(ARCHDIR)/include/qt6 --with-qt6-libs=/$(ARCHDIR)/lib $(EXTRA_CONFIG)" MOCCMD="$(QT6_MOCCMD)" wrap-qt6
+	make GUI=qt6 CLIENT=qt FCMP=qt EXTRA_CONFIG="--with-qtver=qt6 --with-qt6-includes=/$(ARCHDIR)/include/qt6 --with-qt6-libs=/$(ARCHDIR)/lib $(EXTRA_CONFIG)" MOCCMD="$(QT6_MOCCMD)" wrap-qt6
 
 ruledit-installer: ruledit-installer-qt5
 
@@ -99,13 +99,13 @@ configure-freeciv-ruledit-qt5:
 	# create build directory
 	mkdir -p build-$(WINARCH)-ruledit-qt5
 	# configure
-	cd build-$(WINARCH)-ruledit-qt5; ../../../configure FREECIV_LABEL_FORCE="<base>-msys2" CPPFLAGS="-D_WIN32_WINNT=$(MIN_WIN_VER)" --with-qt5 --disable-client --disable-server --disable-fcmp --disable-freeciv-manual --disable-sys-lua --enable-ruledit --enable-ai-static=stub --with-cacert-path="./ssl/certs/ca-bundle.crt" --with-qt5-includes=/$(ARCHDIR)/include --with-qt5-libs=/$(ARCHDIR)/lib $(EXTRA_CONFIG)
+	cd build-$(WINARCH)-ruledit-qt5; ../../../configure FREECIV_LABEL_FORCE="<base>-msys2" CPPFLAGS="-D_WIN32_WINNT=$(MIN_WIN_VER)" --with-qtver=qt5 --disable-client --disable-server --disable-fcmp --disable-freeciv-manual --disable-sys-lua --enable-ruledit --enable-ai-static=stub --with-cacert-path="./ssl/certs/ca-bundle.crt" --with-qt5-includes=/$(ARCHDIR)/include --with-qt5-libs=/$(ARCHDIR)/lib $(EXTRA_CONFIG)
 
 configure-freeciv-ruledit-qt6:
 	# create build directory
 	mkdir -p build-$(WINARCH)-ruledit-qt6
 	# configure
-	cd build-$(WINARCH)-ruledit-qt6; ../../../configure FREECIV_LABEL_FORCE="<base>-msys2" CPPFLAGS="-D_WIN32_WINNT=$(MIN_WIN_VER)" --disable-client --disable-server --disable-fcmp --disable-freeciv-manual --disable-sys-lua --enable-ruledit --enable-ai-static=stub --with-cacert-path="./ssl/certs/ca-bundle.crt" --with-qt6-includes=/$(ARCHDIR)/include/qt6 --with-qt6-libs=/$(ARCHDIR)/lib $(EXTRA_CONFIG)
+	cd build-$(WINARCH)-ruledit-qt6; ../../../configure FREECIV_LABEL_FORCE="<base>-msys2" CPPFLAGS="-D_WIN32_WINNT=$(MIN_WIN_VER)" --with-qtver=qt6 --disable-client --disable-server --disable-fcmp --disable-freeciv-manual --disable-sys-lua --enable-ruledit --enable-ai-static=stub --with-cacert-path="./ssl/certs/ca-bundle.crt" --with-qt6-includes=/$(ARCHDIR)/include/qt6 --with-qt6-libs=/$(ARCHDIR)/lib $(EXTRA_CONFIG)
 
 # install Freeciv
 
-- 
2.34.1