Test for -Wno-pointer-sign, move CFLAGS tests into a macro

This commit is contained in:
Matt Johnston 2018-02-08 22:21:47 +08:00
parent f581ef9453
commit debb208553

View File

@ -9,7 +9,6 @@ AC_PREREQ(2.59)
AC_INIT AC_INIT
AC_CONFIG_SRCDIR(buffer.c) AC_CONFIG_SRCDIR(buffer.c)
OLDCFLAGS="$CFLAGS"
# Checks for programs. # Checks for programs.
AC_PROG_CC AC_PROG_CC
AC_PROG_MAKE_SET AC_PROG_MAKE_SET
@ -19,19 +18,28 @@ if test -z "$LD" ; then
fi fi
AC_SUBST(LD) AC_SUBST(LD)
AC_DEFUN(DB_TRYADDCFLAGS,
[{
OLDFLAGS="$CFLAGS"
TESTFLAGS="$1"
CFLAGS="$CFLAGS $TESTFLAGS"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
[AC_MSG_NOTICE([Setting $TESTFLAGS])],
[AC_MSG_NOTICE([Not setting $TESTFLAGS]); CFLAGS="$OLDFLAGS" ]
)
}])
# set compile flags prior to other tests # set compile flags prior to other tests
if test -z "$OLDCFLAGS" && test "$GCC" = "yes"; then if test -z "$OLDCFLAGS" && test "$GCC" = "yes"; then
AC_MSG_NOTICE(No \$CFLAGS set... using "-Os -W -Wall" for GCC) AC_MSG_NOTICE(No \$CFLAGS set... using "-Os -W -Wall" for GCC)
CFLAGS="-Os -W -Wall -Wno-pointer-sign" CFLAGS="-Os -W -Wall"
fi fi
AC_MSG_CHECKING([if compiler '$CC' supports -fno-strict-overflow]) AC_MSG_NOTICE([Checking if compiler '$CC' supports -Wno-pointer-sign])
OLDCFLAGS="$CFLAGS" DB_TRYADDCFLAGS([-Wno-pointer-sign])
CFLAGS="$CFLAGS -fno-strict-overflow"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], AC_MSG_NOTICE([Checking if compiler '$CC' supports -fno-strict-overflow])
[AC_MSG_RESULT(yes)], DB_TRYADDCFLAGS([-fno-strict-overflow])
[AC_MSG_RESULT(no); CFLAGS="$OLDCFLAGS" ]
)
STATIC=0 STATIC=0
AC_ARG_ENABLE(static, AC_ARG_ENABLE(static,
@ -59,13 +67,8 @@ if test "$hardenbuild" -eq 1; then
# relocation flags don't make sense for static builds # relocation flags don't make sense for static builds
if test "$STATIC" -ne 1; then if test "$STATIC" -ne 1; then
# pie # pie
OLDCFLAGS="$CFLAGS" DB_TRYADDCFLAGS([-fPIE])
TESTFLAGS="-fPIE"
CFLAGS="$CFLAGS $TESTFLAGS"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
[AC_MSG_NOTICE([Setting $TESTFLAGS])],
[AC_MSG_NOTICE([Not setting $TESTFLAGS]); CFLAGS="$OLDCFLAGS" ]
)
OLDLDFLAGS="$LDFLAGS" OLDLDFLAGS="$LDFLAGS"
TESTFLAGS="-Wl,-pie" TESTFLAGS="-Wl,-pie"
LDFLAGS="$LDFLAGS $TESTFLAGS" LDFLAGS="$LDFLAGS $TESTFLAGS"
@ -107,13 +110,7 @@ if test "$hardenbuild" -eq 1; then
] ]
) )
# FORTIFY_SOURCE # FORTIFY_SOURCE
OLDCFLAGS="$CFLAGS" DB_TRYADDCFLAGS([-D_FORTIFY_SOURCE=2])
TESTFLAGS="-D_FORTIFY_SOURCE=2"
CFLAGS="$CFLAGS $TESTFLAGS"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
[AC_MSG_NOTICE([Setting $TESTFLAGS])],
[AC_MSG_NOTICE([Not setting $TESTFLAGS]); CFLAGS="$OLDCFLAGS" ]
)
fi fi
# large file support is useful for scp # large file support is useful for scp