From fe405bda51528493beda3461255cbe3eac361c6b Mon Sep 17 00:00:00 2001
From: Marina Polyakova <m.polyakova@postgrespro.ru>
Date: Sat, 19 Nov 2022 18:57:12 +0300
Subject: [PATCH v2 3/3] Build with ICU by default

Add the option --without-icu to turn it off.
---
 configure                      | 35 ++++++++-------
 configure.ac                   | 18 ++++++--
 doc/src/sgml/installation.sgml | 82 ++++++++++++++++------------------
 meson.build                    |  2 +
 4 files changed, 74 insertions(+), 63 deletions(-)

diff --git a/configure b/configure
index 3966368b8d..1b3ecf9d11 100755
--- a/configure
+++ b/configure
@@ -1558,7 +1558,7 @@ Optional Packages:
                           set WAL block size in kB [8]
   --with-CC=CMD           set compiler (deprecated)
   --with-llvm             build with LLVM based JIT support
-  --with-icu              build with ICU support
+  --without-icu           build without ICU support
   --with-tcl              build Tcl modules (PL/Tcl)
   --with-tclconfig=DIR    tclConfig.sh is in DIR
   --with-perl             build Perl modules (PL/Perl)
@@ -8320,7 +8320,9 @@ $as_echo "#define USE_ICU 1" >>confdefs.h
   esac
 
 else
-  with_icu=no
+  with_icu=yes
+
+$as_echo "#define USE_ICU 1" >>confdefs.h
 
 fi
 
@@ -8389,31 +8391,27 @@ fi
 	# Put the nasty error message in config.log where it belongs
 	echo "$ICU_PKG_ERRORS" >&5
 
-	as_fn_error $? "Package requirements (icu-uc icu-i18n) were not met:
-
-$ICU_PKG_ERRORS
-
-Consider adjusting the PKG_CONFIG_PATH environment variable if you
-installed software in a non-standard prefix.
+	as_fn_error $? "ICU library not found
+If you have ICU already installed, see config.log for details on the
+failure.  It is possible pkg-config isn't looking in the proper directory.
 
 Alternatively, you may set the environment variables ICU_CFLAGS
 and ICU_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details." "$LINENO" 5
+See the pkg-config man page for more details.
+
+Use --without-icu to disable ICU support." "$LINENO" 5
 elif test $pkg_failed = untried; then
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
-	{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "The pkg-config script could not be found or is too old.  Make sure it
-is in your PATH or set the PKG_CONFIG environment variable to the full
-path to pkg-config.
+	as_fn_error $? "ICU library not found
+If you have ICU already installed, see config.log for details on the
+failure.  It is possible pkg-config isn't looking in the proper directory.
 
 Alternatively, you may set the environment variables ICU_CFLAGS
 and ICU_LIBS to avoid the need to call pkg-config.
 See the pkg-config man page for more details.
 
-To get pkg-config, see <http://pkg-config.freedesktop.org/>.
-See \`config.log' for more details" "$LINENO" 5; }
+Use --without-icu to disable ICU support." "$LINENO" 5
 else
 	ICU_CFLAGS=$pkg_cv_ICU_CFLAGS
 	ICU_LIBS=$pkg_cv_ICU_LIBS
@@ -16715,7 +16713,10 @@ if test "$with_icu" = yes; then
 if test "x$ac_cv_header_unicode_ucol_h" = xyes; then :
 
 else
-  as_fn_error $? "header file <unicode/ucol.h> is required for ICU" "$LINENO" 5
+  as_fn_error $? "ICU header file <unicode/ucol.h> not found
+If you have ICU already installed, see config.log for details on the
+failure.  It is possible the compiler isn't looking in the proper directory.
+Use --without-icu to disable ICU support." "$LINENO" 5
 fi
 
 
diff --git a/configure.ac b/configure.ac
index f76b7ee31f..bf396f8d83 100644
--- a/configure.ac
+++ b/configure.ac
@@ -831,13 +831,22 @@ AC_SUBST(enable_thread_safety)
 # ICU
 #
 AC_MSG_CHECKING([whether to build with ICU support])
-PGAC_ARG_BOOL(with, icu, no, [build with ICU support],
+PGAC_ARG_BOOL(with, icu, yes, [build without ICU support],
               [AC_DEFINE([USE_ICU], 1, [Define to build with ICU support. (--with-icu)])])
 AC_MSG_RESULT([$with_icu])
 AC_SUBST(with_icu)
 
 if test "$with_icu" = yes; then
-  PKG_CHECK_MODULES(ICU, icu-uc icu-i18n)
+  PKG_CHECK_MODULES(ICU, icu-uc icu-i18n, [],
+                    [AC_MSG_ERROR([ICU library not found
+If you have ICU already installed, see config.log for details on the
+failure.  It is possible pkg-config isn't looking in the proper directory.
+
+Alternatively, you may set the environment variables ICU_CFLAGS
+and ICU_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.
+
+Use --without-icu to disable ICU support.])])
 fi
 
 #
@@ -1936,7 +1945,10 @@ if test "$with_icu" = yes; then
 
   # Verify we have ICU's header files
   AC_CHECK_HEADER(unicode/ucol.h, [],
-        [AC_MSG_ERROR([header file <unicode/ucol.h> is required for ICU])])
+        [AC_MSG_ERROR([ICU header file <unicode/ucol.h> not found
+If you have ICU already installed, see config.log for details on the
+failure.  It is possible the compiler isn't looking in the proper directory.
+Use --without-icu to disable ICU support.])])
 
   CPPFLAGS=$ac_save_CPPFLAGS
 fi
diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml
index df62573db1..e15f6f8643 100644
--- a/doc/src/sgml/installation.sgml
+++ b/doc/src/sgml/installation.sgml
@@ -913,49 +913,6 @@ build-postgresql:
        </listitem>
       </varlistentry>
 
-      <varlistentry>
-       <term><option>--with-icu</option></term>
-       <listitem>
-        <para>
-         Build with support for
-         the <productname>ICU</productname><indexterm><primary>ICU</primary></indexterm>
-         library, enabling use of ICU collation
-         features<phrase condition="standalone-ignore"> (see
-         <xref linkend="collation"/>)</phrase>.
-         This requires the <productname>ICU4C</productname> package
-         to be installed.  The minimum required version
-         of <productname>ICU4C</productname> is currently 4.2.
-        </para>
-
-        <para>
-         By default,
-         <productname>pkg-config</productname><indexterm><primary>pkg-config</primary></indexterm>
-         will be used to find the required compilation options.  This is
-         supported for <productname>ICU4C</productname> version 4.6 and later.
-         For older versions, or if <productname>pkg-config</productname> is
-         not available, the variables <envar>ICU_CFLAGS</envar>
-         and <envar>ICU_LIBS</envar> can be specified
-         to <filename>configure</filename>, like in this example:
-<programlisting>
-./configure ... --with-icu ICU_CFLAGS='-I/some/where/include' ICU_LIBS='-L/some/where/lib -licui18n -licuuc -licudata'
-</programlisting>
-         (If <productname>ICU4C</productname> is in the default search path
-         for the compiler, then you still need to specify nonempty strings in
-         order to avoid use of <productname>pkg-config</productname>, for
-         example, <literal>ICU_CFLAGS=' '</literal>.)
-        </para>
-
-        <note>
-         <para>
-          Building without
-          <productname>ICU</productname><indexterm><primary>ICU</primary></indexterm>
-          library is considered a marginal configuration and is not recommended
-          unless really necessary.
-         </para>
-        </note>
-       </listitem>
-      </varlistentry>
-
       <varlistentry id="configure-with-llvm">
        <term><option>--with-llvm</option></term>
        <listitem>
@@ -1266,6 +1223,45 @@ build-postgresql:
        </listitem>
       </varlistentry>
 
+      <varlistentry>
+       <term><option>--without-icu</option></term>
+       <listitem>
+        <para>
+         Prevents use of the
+         <productname>ICU</productname><indexterm><primary>ICU</primary></indexterm>
+         library. This disables support of ICU collation
+         features<phrase condition="standalone-ignore"> (see
+         <xref linkend="collation"/>)</phrase>.
+        </para>
+        <note>
+         <para>
+          Building with support for
+          the <productname>ICU</productname><indexterm><primary>ICU</primary></indexterm>
+          library requires the <productname>ICU4C</productname> package
+          to be installed.  The minimum required version
+          of <productname>ICU4C</productname> is currently 4.2.
+         </para>
+         <para>
+          By default,
+          <productname>pkg-config</productname><indexterm><primary>pkg-config</primary></indexterm>
+          will be used to find the required compilation options.  This is
+          supported for <productname>ICU4C</productname> version 4.6 and later.
+          For older versions, or if <productname>pkg-config</productname> is
+          not available, the variables <envar>ICU_CFLAGS</envar>
+          and <envar>ICU_LIBS</envar> can be specified
+          to <filename>configure</filename>, like in this example:
+ <programlisting>
+ ./configure ... ICU_CFLAGS='-I/some/where/include' ICU_LIBS='-L/some/where/lib -licui18n -licuuc -licudata'
+ </programlisting>
+          (If <productname>ICU4C</productname> is in the default search path
+          for the compiler, then you still need to specify nonempty strings in
+          order to avoid use of <productname>pkg-config</productname>, for
+          example, <literal>ICU_CFLAGS=' '</literal>.)
+         </para>
+        </note>
+       </listitem>
+      </varlistentry>
+
       <varlistentry>
        <term><option>--disable-spinlocks</option></term>
        <listitem>
diff --git a/meson.build b/meson.build
index 058382046e..5e3cd93a69 100644
--- a/meson.build
+++ b/meson.build
@@ -709,6 +709,8 @@ if not icuopt.disabled()
 
   if icu.found()
     cdata.set('USE_ICU', 1)
+  else
+    warning('did not find icu')
   endif
 
 else
-- 
2.25.1

