INSTALL_STRIP=""
AC_SUBST(INSTALL_STRIP)
AC_ARG_WITH(optim, [ --with-optim set optimization flags ],
OPTIM="$withval",
OPTIM="")
AC_SUBST(OPTIM)
AC_ARG_ENABLE(debug, [ --enable-debug build with debugging symbols])
AC_ARG_ENABLE(debug_guards, [ --enable-debug-guards build with memory allocation guards])
AC_ARG_ENABLE(debug_printfs, [ --enable-debug-printfs build with CUPS_DEBUG_LOG support])
AC_ARG_ENABLE(unit_tests, [ --enable-unit-tests build and run unit tests])
if test x$enable_debug = xyes -a "x$OPTIM" = x; then
OPTIM="-g"
else
INSTALL_STRIP="-s"
fi
if test x$enable_debug_printfs = xyes; then
CFLAGS="$CFLAGS -DDEBUG"
CXXFLAGS="$CXXFLAGS -DDEBUG"
fi
if test x$enable_debug_guards = xyes; then
CFLAGS="$CFLAGS -DDEBUG_GUARDS"
CXXFLAGS="$CXXFLAGS -DDEBUG_GUARDS"
fi
if test x$enable_unit_tests = xyes; then
if test "$build" != "$host"; then
AC_MSG_ERROR([Sorry, cannot build unit tests when cross-compiling.])
fi
UNITTESTS="unittests"
else
UNITTESTS=""
fi
AC_SUBST(UNITTESTS)
AC_ARG_WITH(archflags, [ --with-archflags set default architecture flags ])
AC_ARG_WITH(ldarchflags, [ --with-ldarchflags set program architecture flags ])
if test -z "$with_archflags"; then
ARCHFLAGS=""
else
ARCHFLAGS="$with_archflags"
fi
if test -z "$with_ldarchflags"; then
if test "$host_os_name" = darwin; then
LDARCHFLAGS="`echo $ARCHFLAGS | sed -e '1,$s/-arch ppc64//'`"
else
LDARCHFLAGS="$ARCHFLAGS"
fi
else
LDARCHFLAGS="$with_ldarchflags"
fi
AC_SUBST(ARCHFLAGS)
AC_SUBST(LDARCHFLAGS)
AC_ARG_ENABLE(relro, [ --enable-relro build with the GCC relro option])
AC_ARG_ENABLE(sanitizer, [ --enable-sanitizer build with AddressSanitizer])
CXXLIBS="${CXXLIBS:=}"
AC_SUBST(CXXLIBS)
PIEFLAGS=""
AC_SUBST(PIEFLAGS)
RELROFLAGS=""
AC_SUBST(RELROFLAGS)
WARNING_OPTIONS=""
AC_SUBST(WARNING_OPTIONS)
if test -n "$GCC"; then
if test x$enable_sanitizer = xyes; then
OPTIM="$OPTIM -g -fsanitize=address"
else
CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
CXXFLAGS="$CXXFLAGS -D_FORTIFY_SOURCE=2"
fi
if test -z "$OPTIM"; then
OPTIM="-Os -g"
fi
if test $PICFLAG = 1; then
OPTIM="-fPIC $OPTIM"
fi
AC_MSG_CHECKING(whether compiler supports -fstack-protector)
OLDCFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -fstack-protector"
AC_TRY_LINK(,,
if test "x$LSB_BUILD" = xy; then
OPTIM="$OPTIM -fno-stack-protector"
else
OPTIM="$OPTIM -fstack-protector"
fi
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no))
CFLAGS="$OLDCFLAGS"
if test "x$LSB_BUILD" != xy; then
AC_MSG_CHECKING(whether compiler supports -fPIE)
OLDCFLAGS="$CFLAGS"
case "$host_os_name" in
darwin*)
CFLAGS="$CFLAGS -fPIE -Wl,-pie"
AC_TRY_COMPILE(,,[
PIEFLAGS="-fPIE -Wl,-pie"
AC_MSG_RESULT(yes)],
AC_MSG_RESULT(no))
;;
*)
CFLAGS="$CFLAGS -fPIE -pie"
AC_TRY_COMPILE(,,[
PIEFLAGS="-fPIE -pie"
AC_MSG_RESULT(yes)],
AC_MSG_RESULT(no))
;;
esac
CFLAGS="$OLDCFLAGS"
fi
WARNING_OPTIONS="-Wall -Wno-format-y2k -Wunused -Wno-unused-result -Wsign-conversion"
gccversion=`$CC --version | head -1 | awk '{print $NF}'`
case "$gccversion" in
7.* | 8.* | 9.*)
WARNING_OPTIONS="$WARNING_OPTIONS -Wno-format-truncation -Wno-tautological-compare"
;;
esac
if test -d .git; then
WARNING_OPTIONS="-Werror -Wno-error=deprecated-declarations $WARNING_OPTIONS"
fi
else
case $host_os_name in
sunos*)
if test -z "$OPTIM"; then
OPTIM="-xO2"
fi
if test $PICFLAG = 1; then
OPTIM="-KPIC $OPTIM"
fi
;;
*)
echo "Building CUPS with default compiler optimizations; contact the CUPS developers on Github"
echo "(https://github.com/apple/cups/issues) with the uname and compiler options needed for"
echo "your platform, or set the CFLAGS and LDFLAGS environment variables before running"
echo "configure."
;;
esac
fi
case $host_os_name in
linux*)
OPTIM="$OPTIM -D_GNU_SOURCE"
if test x$enable_relro = xyes; then
RELROFLAGS="-Wl,-z,relro,-z,now"
fi
;;
esac