Skip to content

Commit adb3551

Browse files
committed
Allow CFLAGS from configure's environment to override automatic CFLAGS.
Previously, configure would add any switches that it chose of its own accord to the end of the user-specified CFLAGS string. Since most compilers process these left-to-right, this meant that configure's choices would override the user-specified flags in case of conflicts. We'd rather that worked the other way around, so adjust the logic to put the user's string at the end not the beginning. There does not seem to be a need for a similar behavior change for CPPFLAGS or LDFLAGS: in those, the earlier switches tend to win (think -I or -L behavior) so putting the user's string at the front is fine. Backpatch to 9.4 but not earlier. I'm not planning to run buildfarm member guar on older branches, and it seems a bit risky to change this behavior in long-stable branches.
1 parent 045c7d3 commit adb3551

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

configure

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4357,6 +4357,10 @@ else
43574357
fi
43584358
fi
43594359

4360+
# CFLAGS we determined above will be added back at the end
4361+
user_CFLAGS=$CFLAGS
4362+
CFLAGS=""
4363+
43604364
# set CFLAGS_VECTOR from the environment, if available
43614365
if test "$ac_env_CFLAGS_VECTOR_set" = set; then
43624366
CFLAGS_VECTOR=$ac_env_CFLAGS_VECTOR_value
@@ -4368,7 +4372,7 @@ fi
43684372
# but has its own. Also check other compiler-specific flags here.
43694373

43704374
if test "$GCC" = yes -a "$ICC" = no; then
4371-
CFLAGS="$CFLAGS -Wall -Wmissing-prototypes -Wpointer-arith"
4375+
CFLAGS="-Wall -Wmissing-prototypes -Wpointer-arith"
43724376
# These work in some but not all gcc versions
43734377
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Wdeclaration-after-statement" >&5
43744378
$as_echo_n "checking whether $CC supports -Wdeclaration-after-statement... " >&6; }
@@ -4875,7 +4879,12 @@ if test "$PORTNAME" = "win32"; then
48754879
CPPFLAGS="$CPPFLAGS -I$srcdir/src/include/port/win32 -DEXEC_BACKEND"
48764880
fi
48774881

4878-
# Check if the compiler still works with the template settings
4882+
# Now that we're done automatically adding stuff to CFLAGS, put back the
4883+
# user-specified flags (if any) at the end. This lets users override
4884+
# the automatic additions.
4885+
CFLAGS="$CFLAGS $user_CFLAGS"
4886+
4887+
# Check if the compiler still works with the final flag settings
48794888
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler still works" >&5
48804889
$as_echo_n "checking whether the C compiler still works... " >&6; }
48814890
cat confdefs.h - <<_ACEOF >conftest.$ac_ext

configure.in

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ else
409409
fi
410410
fi
411411

412+
# CFLAGS we determined above will be added back at the end
413+
user_CFLAGS=$CFLAGS
414+
CFLAGS=""
415+
412416
# set CFLAGS_VECTOR from the environment, if available
413417
if test "$ac_env_CFLAGS_VECTOR_set" = set; then
414418
CFLAGS_VECTOR=$ac_env_CFLAGS_VECTOR_value
@@ -420,7 +424,7 @@ fi
420424
# but has its own. Also check other compiler-specific flags here.
421425

422426
if test "$GCC" = yes -a "$ICC" = no; then
423-
CFLAGS="$CFLAGS -Wall -Wmissing-prototypes -Wpointer-arith"
427+
CFLAGS="-Wall -Wmissing-prototypes -Wpointer-arith"
424428
# These work in some but not all gcc versions
425429
PGAC_PROG_CC_CFLAGS_OPT([-Wdeclaration-after-statement])
426430
PGAC_PROG_CC_CFLAGS_OPT([-Wendif-labels])
@@ -483,7 +487,12 @@ if test "$PORTNAME" = "win32"; then
483487
CPPFLAGS="$CPPFLAGS -I$srcdir/src/include/port/win32 -DEXEC_BACKEND"
484488
fi
485489

486-
# Check if the compiler still works with the template settings
490+
# Now that we're done automatically adding stuff to CFLAGS, put back the
491+
# user-specified flags (if any) at the end. This lets users override
492+
# the automatic additions.
493+
CFLAGS="$CFLAGS $user_CFLAGS"
494+
495+
# Check if the compiler still works with the final flag settings
487496
AC_MSG_CHECKING([whether the C compiler still works])
488497
AC_TRY_LINK([], [return 0;],
489498
[AC_MSG_RESULT(yes)],

0 commit comments

Comments
 (0)