aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/c-compiler.m435
-rwxr-xr-xconfigure41
-rw-r--r--src/include/pg_config.h.in2
3 files changed, 61 insertions, 17 deletions
diff --git a/config/c-compiler.m4 b/config/c-compiler.m4
index fb58c94d4b0..af2dea1c2ab 100644
--- a/config/c-compiler.m4
+++ b/config/c-compiler.m4
@@ -21,21 +21,36 @@ fi])# PGAC_C_SIGNED
# -----------------------
# Select the format archetype to be used by gcc to check printf-type functions.
# We prefer "gnu_printf", as that most closely matches the features supported
-# by src/port/snprintf.c (particularly the %m conversion spec).
+# by src/port/snprintf.c (particularly the %m conversion spec). However,
+# on some NetBSD versions, that doesn't work while "__syslog__" does.
+# If all else fails, use "printf".
AC_DEFUN([PGAC_PRINTF_ARCHETYPE],
[AC_CACHE_CHECK([for printf format archetype], pgac_cv_printf_archetype,
+[pgac_cv_printf_archetype=gnu_printf
+PGAC_TEST_PRINTF_ARCHETYPE
+if [[ "$ac_archetype_ok" = no ]]; then
+ pgac_cv_printf_archetype=__syslog__
+ PGAC_TEST_PRINTF_ARCHETYPE
+ if [[ "$ac_archetype_ok" = no ]]; then
+ pgac_cv_printf_archetype=printf
+ fi
+fi])
+AC_DEFINE_UNQUOTED([PG_PRINTF_ATTRIBUTE], [$pgac_cv_printf_archetype],
+[Define to best printf format archetype, usually gnu_printf if available.])
+])# PGAC_PRINTF_ARCHETYPE
+
+# Subroutine: test $pgac_cv_printf_archetype, set $ac_archetype_ok to yes or no
+AC_DEFUN([PGAC_TEST_PRINTF_ARCHETYPE],
[ac_save_c_werror_flag=$ac_c_werror_flag
ac_c_werror_flag=yes
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
-[extern int
-pgac_write(int ignore, const char *fmt,...)
-__attribute__((format(gnu_printf, 2, 3)));], [])],
- [pgac_cv_printf_archetype=gnu_printf],
- [pgac_cv_printf_archetype=printf])
-ac_c_werror_flag=$ac_save_c_werror_flag])
-AC_DEFINE_UNQUOTED([PG_PRINTF_ATTRIBUTE], [$pgac_cv_printf_archetype],
- [Define to gnu_printf if compiler supports it, else printf.])
-])# PGAC_PRINTF_ARCHETYPE
+[extern void pgac_write(int ignore, const char *fmt,...)
+__attribute__((format($pgac_cv_printf_archetype, 2, 3)));],
+[pgac_write(0, "error %s: %m", "foo");])],
+ [ac_archetype_ok=yes],
+ [ac_archetype_ok=no])
+ac_c_werror_flag=$ac_save_c_werror_flag
+])# PGAC_TEST_PRINTF_ARCHETYPE
# PGAC_TYPE_64BIT_INT(TYPE)
diff --git a/configure b/configure
index 0448c6bfebf..b7250d7f5b8 100755
--- a/configure
+++ b/configure
@@ -13583,28 +13583,57 @@ $as_echo_n "checking for printf format archetype... " >&6; }
if ${pgac_cv_printf_archetype+:} false; then :
$as_echo_n "(cached) " >&6
else
- ac_save_c_werror_flag=$ac_c_werror_flag
+ pgac_cv_printf_archetype=gnu_printf
+ac_save_c_werror_flag=$ac_c_werror_flag
ac_c_werror_flag=yes
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
-extern int
-pgac_write(int ignore, const char *fmt,...)
-__attribute__((format(gnu_printf, 2, 3)));
+extern void pgac_write(int ignore, const char *fmt,...)
+__attribute__((format($pgac_cv_printf_archetype, 2, 3)));
int
main ()
{
+pgac_write(0, "error %s: %m", "foo");
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_archetype_ok=yes
+else
+ ac_archetype_ok=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_c_werror_flag=$ac_save_c_werror_flag
+if [ "$ac_archetype_ok" = no ]; then
+ pgac_cv_printf_archetype=__syslog__
+ ac_save_c_werror_flag=$ac_c_werror_flag
+ac_c_werror_flag=yes
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+extern void pgac_write(int ignore, const char *fmt,...)
+__attribute__((format($pgac_cv_printf_archetype, 2, 3)));
+int
+main ()
+{
+pgac_write(0, "error %s: %m", "foo");
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
- pgac_cv_printf_archetype=gnu_printf
+ ac_archetype_ok=yes
else
- pgac_cv_printf_archetype=printf
+ ac_archetype_ok=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
ac_c_werror_flag=$ac_save_c_werror_flag
+
+ if [ "$ac_archetype_ok" = no ]; then
+ pgac_cv_printf_archetype=printf
+ fi
+fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_printf_archetype" >&5
$as_echo "$pgac_cv_printf_archetype" >&6; }
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 7894caa8c12..9798bd24b44 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -804,7 +804,7 @@
/* PostgreSQL major version as a string */
#undef PG_MAJORVERSION
-/* Define to gnu_printf if compiler supports it, else printf. */
+/* Define to best printf format archetype, usually gnu_printf if available. */
#undef PG_PRINTF_ATTRIBUTE
/* PostgreSQL version as a string */