From 9f7c96dfab4d807e668c9d32b44db5f4ff122e15 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Mon, 8 Jul 2024 15:55:56 -0700
Subject: [PATCH v1 2/2] Don't define HAVE_[GSSAPI_]GSSAPI_EXT_H

The check for gssapi_ext.h was added in f7431bca8b0. As we require
gssapi_ext.h to be present, there's no point in defining symbols for the
header presence.

While at it, use cc.has_header() instead of cc.check_header(), that's a bit
cheaper and it seems improbably that gssapi.h would compile while gssapi_ext.h
would not.

Author:
Reviewed-by:
Discussion: https://postgr.es/m/
Backpatch:
---
 meson.build                | 15 ++++-----------
 configure.ac               |  4 ++--
 src/include/pg_config.h.in |  6 ------
 configure                  | 12 ------------
 4 files changed, 6 insertions(+), 31 deletions(-)

diff --git a/meson.build b/meson.build
index 102b1e98a27..f1912d83ce6 100644
--- a/meson.build
+++ b/meson.build
@@ -620,25 +620,18 @@ if not gssapiopt.disabled()
   if not have_gssapi
   elif cc.check_header('gssapi/gssapi.h', dependencies: gssapi, required: false,
       args: test_c_args, include_directories: postgres_inc)
+    cc.has_header('gssapi/gssapi_ext.h', dependencies: gssapi, required: true,
+      args: test_c_args, include_directories: postgres_inc)
     cdata.set('HAVE_GSSAPI_GSSAPI_H', 1)
   elif cc.check_header('gssapi.h', dependencies: gssapi, required: gssapiopt,
       args: test_c_args, include_directories: postgres_inc)
+    cc.has_header('gssapi_ext.h', dependencies: gssapi, required: true,
+      args: test_c_args, include_directories: postgres_inc)
     cdata.set('HAVE_GSSAPI_H', 1)
   else
     have_gssapi = false
   endif
 
-  if not have_gssapi
-  elif cc.check_header('gssapi/gssapi_ext.h', dependencies: gssapi, required: false,
-      args: test_c_args, include_directories: postgres_inc)
-    cdata.set('HAVE_GSSAPI_GSSAPI_EXT_H', 1)
-  elif cc.check_header('gssapi_ext.h', dependencies: gssapi, required: gssapiopt,
-      args: test_c_args, include_directories: postgres_inc)
-    cdata.set('HAVE_GSSAPI_EXT_H', 1)
-  else
-    have_gssapi = false
-  endif
-
   if not have_gssapi
   elif cc.has_function('gss_store_cred_into', dependencies: gssapi,
       args: test_c_args, include_directories: postgres_inc)
diff --git a/configure.ac b/configure.ac
index ab2d51c21ce..7cd7e95ae49 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1532,8 +1532,8 @@ fi
 if test "$with_gssapi" = yes ; then
   AC_CHECK_HEADERS(gssapi/gssapi.h, [],
 	[AC_CHECK_HEADERS(gssapi.h, [], [AC_MSG_ERROR([gssapi.h header file is required for GSSAPI])])])
-  AC_CHECK_HEADERS(gssapi/gssapi_ext.h, [],
-	[AC_CHECK_HEADERS(gssapi_ext.h, [], [AC_MSG_ERROR([gssapi_ext.h header file is required for GSSAPI])])])
+  AC_CHECK_HEADER(gssapi/gssapi_ext.h, [],
+	[AC_CHECK_HEADER(gssapi_ext.h, [], [AC_MSG_ERROR([gssapi_ext.h header file is required for GSSAPI])])])
 fi
 
 PGAC_PATH_PROGS(OPENSSL, openssl)
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index f8d3e3b6b84..e0c0b51c5c1 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -180,12 +180,6 @@
 /* Define to 1 if you have the `getpeerucred' function. */
 #undef HAVE_GETPEERUCRED
 
-/* Define to 1 if you have the <gssapi_ext.h> header file. */
-#undef HAVE_GSSAPI_EXT_H
-
-/* Define to 1 if you have the <gssapi/gssapi_ext.h> header file. */
-#undef HAVE_GSSAPI_GSSAPI_EXT_H
-
 /* Define to 1 if you have the <gssapi/gssapi.h> header file. */
 #undef HAVE_GSSAPI_GSSAPI_H
 
diff --git a/configure b/configure
index 76f06bd8fda..2a9d467be04 100755
--- a/configure
+++ b/configure
@@ -13677,32 +13677,20 @@ fi
 
 done
 
-  for ac_header in gssapi/gssapi_ext.h
-do :
   ac_fn_c_check_header_mongrel "$LINENO" "gssapi/gssapi_ext.h" "ac_cv_header_gssapi_gssapi_ext_h" "$ac_includes_default"
 if test "x$ac_cv_header_gssapi_gssapi_ext_h" = xyes; then :
-  cat >>confdefs.h <<_ACEOF
-#define HAVE_GSSAPI_GSSAPI_EXT_H 1
-_ACEOF
 
 else
-  for ac_header in gssapi_ext.h
-do :
   ac_fn_c_check_header_mongrel "$LINENO" "gssapi_ext.h" "ac_cv_header_gssapi_ext_h" "$ac_includes_default"
 if test "x$ac_cv_header_gssapi_ext_h" = xyes; then :
-  cat >>confdefs.h <<_ACEOF
-#define HAVE_GSSAPI_EXT_H 1
-_ACEOF
 
 else
   as_fn_error $? "gssapi_ext.h header file is required for GSSAPI" "$LINENO" 5
 fi
 
-done
 
 fi
 
-done
 
 fi
 
-- 
2.44.0.279.g3bd955d269

