mirror of
https://github.com/postgres/postgres.git
synced 2025-04-18 13:44:19 +03:00
If a C23 compiler is detected, try asking for C17.
Branches before 16 can't be compiled with a C23 compiler (see deprecation warnings silenced by commit f9a56e72, and non-back-patchable changes made in 16 by commit 1c27d16e). Test __STDC_VERSION__, and if it's above C17 then try appending -std=gnu17. The test is done with the user's CFLAGS, so an acceptable language version can also be configured manually that way. This is done in branches 15 and older, back to 9.2, per policy of keeping them buildable with modern tools. Discussion: https://postgr.es/m/87o72eo9iu.fsf%40gentoo.org
This commit is contained in:
parent
8f3be9661f
commit
102be6634e
124
configure
vendored
124
configure
vendored
@ -3949,6 +3949,130 @@ else
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# We use C constructs that became invalid in C23. Check if the compiler
|
||||||
|
# reports a standard higher than C17, with the flags selected above (so the
|
||||||
|
# user can control the language level explicitly to avoid the gcc/clang-only
|
||||||
|
# fallback logic below if preferred).
|
||||||
|
{ $as_echo "$as_me:$LINENO: checking whether $CC reports a C standard higher than ISO C17" >&5
|
||||||
|
$as_echo_n "checking whether $CC reports a C standard higher than ISO C17... " >&6; }
|
||||||
|
cat >conftest.$ac_ext <<_ACEOF
|
||||||
|
/* confdefs.h. */
|
||||||
|
_ACEOF
|
||||||
|
cat confdefs.h >>conftest.$ac_ext
|
||||||
|
cat >>conftest.$ac_ext <<_ACEOF
|
||||||
|
/* end confdefs.h. */
|
||||||
|
|
||||||
|
int
|
||||||
|
main ()
|
||||||
|
{
|
||||||
|
#if __STDC_VERSION__ > 201710L
|
||||||
|
choke me
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
_ACEOF
|
||||||
|
rm -f conftest.$ac_objext
|
||||||
|
if { (ac_try="$ac_compile"
|
||||||
|
case "(($ac_try" in
|
||||||
|
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
|
||||||
|
*) ac_try_echo=$ac_try;;
|
||||||
|
esac
|
||||||
|
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
|
||||||
|
$as_echo "$ac_try_echo") >&5
|
||||||
|
(eval "$ac_compile") 2>conftest.er1
|
||||||
|
ac_status=$?
|
||||||
|
grep -v '^ *+' conftest.er1 >conftest.err
|
||||||
|
rm -f conftest.er1
|
||||||
|
cat conftest.err >&5
|
||||||
|
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||||
|
(exit $ac_status); } && {
|
||||||
|
test -z "$ac_c_werror_flag" ||
|
||||||
|
test ! -s conftest.err
|
||||||
|
} && test -s conftest.$ac_objext; then
|
||||||
|
POSTC17=no
|
||||||
|
else
|
||||||
|
$as_echo "$as_me: failed program was:" >&5
|
||||||
|
sed 's/^/| /' conftest.$ac_ext >&5
|
||||||
|
|
||||||
|
POSTC17=yes
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||||
|
{ $as_echo "$as_me:$LINENO: result: ${POSTC17}" >&5
|
||||||
|
$as_echo "${POSTC17}" >&6; }
|
||||||
|
|
||||||
|
# If a too recent standard was detected with the user's CFLAGS, try asking for
|
||||||
|
# C17 with GNU extensions explicitly.
|
||||||
|
if test "$POSTC17" = yes; then
|
||||||
|
old_CFLAGS="$CFLAGS"
|
||||||
|
{ $as_echo "$as_me:$LINENO: checking whether $CC supports -std=gnu17" >&5
|
||||||
|
$as_echo_n "checking whether $CC supports -std=gnu17... " >&6; }
|
||||||
|
if test "${pgac_cv_prog_cc_cflags__std_gnu17+set}" = set; then
|
||||||
|
$as_echo_n "(cached) " >&6
|
||||||
|
else
|
||||||
|
pgac_save_CFLAGS=$CFLAGS
|
||||||
|
CFLAGS="$pgac_save_CFLAGS -std=gnu17"
|
||||||
|
ac_save_c_werror_flag=$ac_c_werror_flag
|
||||||
|
ac_c_werror_flag=yes
|
||||||
|
cat >conftest.$ac_ext <<_ACEOF
|
||||||
|
/* confdefs.h. */
|
||||||
|
_ACEOF
|
||||||
|
cat confdefs.h >>conftest.$ac_ext
|
||||||
|
cat >>conftest.$ac_ext <<_ACEOF
|
||||||
|
/* end confdefs.h. */
|
||||||
|
|
||||||
|
int
|
||||||
|
main ()
|
||||||
|
{
|
||||||
|
|
||||||
|
;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
_ACEOF
|
||||||
|
rm -f conftest.$ac_objext
|
||||||
|
if { (ac_try="$ac_compile"
|
||||||
|
case "(($ac_try" in
|
||||||
|
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
|
||||||
|
*) ac_try_echo=$ac_try;;
|
||||||
|
esac
|
||||||
|
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
|
||||||
|
$as_echo "$ac_try_echo") >&5
|
||||||
|
(eval "$ac_compile") 2>conftest.er1
|
||||||
|
ac_status=$?
|
||||||
|
grep -v '^ *+' conftest.er1 >conftest.err
|
||||||
|
rm -f conftest.er1
|
||||||
|
cat conftest.err >&5
|
||||||
|
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||||
|
(exit $ac_status); } && {
|
||||||
|
test -z "$ac_c_werror_flag" ||
|
||||||
|
test ! -s conftest.err
|
||||||
|
} && test -s conftest.$ac_objext; then
|
||||||
|
pgac_cv_prog_cc_cflags__std_gnu17=yes
|
||||||
|
else
|
||||||
|
$as_echo "$as_me: failed program was:" >&5
|
||||||
|
sed 's/^/| /' conftest.$ac_ext >&5
|
||||||
|
|
||||||
|
pgac_cv_prog_cc_cflags__std_gnu17=no
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||||
|
ac_c_werror_flag=$ac_save_c_werror_flag
|
||||||
|
CFLAGS="$pgac_save_CFLAGS"
|
||||||
|
fi
|
||||||
|
{ $as_echo "$as_me:$LINENO: result: $pgac_cv_prog_cc_cflags__std_gnu17" >&5
|
||||||
|
$as_echo "$pgac_cv_prog_cc_cflags__std_gnu17" >&6; }
|
||||||
|
if test x"$pgac_cv_prog_cc_cflags__std_gnu17" = x"yes"; then
|
||||||
|
CFLAGS="$CFLAGS -std=gnu17"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test "$CFLAGS" = "$old_CFLAGS"; then
|
||||||
|
{ { $as_echo "$as_me:$LINENO: error: cannot proceed" >&5
|
||||||
|
$as_echo "$as_me: error: cannot proceed" >&2;}
|
||||||
|
{ (exit 1); exit 1; }; }
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# set CFLAGS_VECTOR from the environment, if available
|
# set CFLAGS_VECTOR from the environment, if available
|
||||||
if test "$ac_env_CFLAGS_VECTOR_set" = set; then
|
if test "$ac_env_CFLAGS_VECTOR_set" = set; then
|
||||||
CFLAGS_VECTOR=$ac_env_CFLAGS_VECTOR_value
|
CFLAGS_VECTOR=$ac_env_CFLAGS_VECTOR_value
|
||||||
|
20
configure.in
20
configure.in
@ -400,6 +400,26 @@ else
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# We use C constructs that became invalid in C23. Check if the compiler
|
||||||
|
# reports a standard higher than C17, with the flags selected above (so the
|
||||||
|
# user can control the language level explicitly to avoid the gcc/clang-only
|
||||||
|
# fallback logic below if preferred).
|
||||||
|
AC_MSG_CHECKING([whether $CC reports a C standard higher than ISO C17])
|
||||||
|
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [@%:@if __STDC_VERSION__ > 201710L
|
||||||
|
choke me
|
||||||
|
@%:@endif])], [POSTC17=no], [POSTC17=yes])
|
||||||
|
AC_MSG_RESULT(${POSTC17})
|
||||||
|
|
||||||
|
# If a too recent standard was detected with the user's CFLAGS, try asking for
|
||||||
|
# C17 with GNU extensions explicitly.
|
||||||
|
if test "$POSTC17" = yes; then
|
||||||
|
old_CFLAGS="$CFLAGS"
|
||||||
|
PGAC_PROG_CC_CFLAGS_OPT([-std=gnu17])
|
||||||
|
if test "$CFLAGS" = "$old_CFLAGS"; then
|
||||||
|
AC_MSG_ERROR([cannot proceed])
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# set CFLAGS_VECTOR from the environment, if available
|
# set CFLAGS_VECTOR from the environment, if available
|
||||||
if test "$ac_env_CFLAGS_VECTOR_set" = set; then
|
if test "$ac_env_CFLAGS_VECTOR_set" = set; then
|
||||||
CFLAGS_VECTOR=$ac_env_CFLAGS_VECTOR_value
|
CFLAGS_VECTOR=$ac_env_CFLAGS_VECTOR_value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user