dnl
-dnl "$Id: cups-compiler.m4 181 2006-06-22 20:01:18Z jlovell $"
+dnl Compiler stuff for CUPS.
dnl
-dnl Compiler stuff for the Common UNIX Printing System (CUPS).
+dnl Copyright 2007-2020 by Apple Inc.
+dnl Copyright 1997-2007 by Easy Software Products, all rights reserved.
dnl
-dnl Copyright 1997-2006 by Easy Software Products, all rights reserved.
-dnl
-dnl These coded instructions, statements, and computer programs are the
-dnl property of Easy Software Products and are protected by Federal
-dnl copyright law. Distribution and use rights are outlined in the file
-dnl "LICENSE.txt" which should have been included with this file. If this
-dnl file is missing or damaged please contact Easy Software Products
-dnl at:
-dnl
-dnl Attn: CUPS Licensing Information
-dnl Easy Software Products
-dnl 44141 Airport View Drive, Suite 204
-dnl Hollywood, Maryland 20636 USA
-dnl
-dnl Voice: (301) 373-9600
-dnl EMail: cups-info@cups.org
-dnl WWW: http://www.cups.org
+dnl Licensed under Apache License v2.0. See the file "LICENSE" for more information.
dnl
dnl Clear the debugging and non-shared library options unless the user asks
dnl for them...
-OPTIM=""
+INSTALL_STRIP=""
+AC_SUBST(INSTALL_STRIP)
+
+AC_ARG_WITH(optim, [ --with-optim set optimization flags ],
+ OPTIM="$withval",
+ OPTIM="")
AC_SUBST(OPTIM)
-AC_ARG_WITH(optim, [ --with-optim="flags" set optimization flags ])
-AC_ARG_ENABLE(debug, [ --enable-debug turn on debugging, default=no],
- [if test x$enable_debug = xyes; then
- OPTIM="-g"
- fi])
+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])
+
+dnl For debugging, keep symbols, otherwise strip them...
+if test x$enable_debug = xyes -a "x$OPTIM" = x; then
+ OPTIM="-g"
+else
+ INSTALL_STRIP="-s"
+fi
+
+dnl Debug printfs can slow things down, so provide a separate option for that
+if test x$enable_debug_printfs = xyes; then
+ CFLAGS="$CFLAGS -DDEBUG"
+ CXXFLAGS="$CXXFLAGS -DDEBUG"
+fi
+
+dnl Debug guards use an extra 4 bytes for some structures like strings in the
+dnl string pool, so provide a separate option for that
+if test x$enable_debug_guards = xyes; then
+ CFLAGS="$CFLAGS -DDEBUG_GUARDS"
+ CXXFLAGS="$CXXFLAGS -DDEBUG_GUARDS"
+fi
+
+dnl Unit tests take up time during a compile...
+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)
dnl Setup general architecture flags...
-AC_ARG_WITH(archflags, [ --with-archflags="flags"
- set default architecture flags ])
+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=""
ARCHFLAGS="$with_archflags"
fi
-AC_SUBST(ARCHFLAGS)
-
-dnl Setup support for separate 32/64-bit library generation...
-AC_ARG_ENABLE(32bit, [ --enable-32bit generate 32-bit libraries on 32/64-bit systems, default=no])
-AC_ARG_WITH(arch32flags, [ --with-arch32flags="flags"
- specifies 32-bit architecture flags])
-
-ARCH32FLAGS=""
-INSTALL32=""
-LIB32CUPS=""
-LIB32CUPSIMAGE=""
-LIB32DIR=""
-UNINSTALL32=""
-
-AC_SUBST(ARCH32FLAGS)
-AC_SUBST(INSTALL32)
-AC_SUBST(LIB32CUPS)
-AC_SUBST(LIB32CUPSIMAGE)
-AC_SUBST(LIB32DIR)
-AC_SUBST(UNINSTALL32)
-
-AC_ARG_ENABLE(64bit, [ --enable-64bit generate 64-bit libraries on 32/64-bit systems, default=no])
-AC_ARG_WITH(arch64flags, [ --with-arch64flags="flags"
- specifies 64-bit architecture flags])
+if test -z "$with_ldarchflags"; then
+ if test "$host_os_name" = darwin; then
+ # Only create Intel programs by default
+ LDARCHFLAGS="`echo $ARCHFLAGS | sed -e '1,$s/-arch ppc64//'`"
+ else
+ LDARCHFLAGS="$ARCHFLAGS"
+ fi
+else
+ LDARCHFLAGS="$with_ldarchflags"
+fi
-ARCH64FLAGS=""
-INSTALL64=""
-LIB64CUPS=""
-LIB64CUPSIMAGE=""
-LIB64DIR=""
-UNINSTALL64=""
+AC_SUBST(ARCHFLAGS)
+AC_SUBST(LDARCHFLAGS)
-AC_SUBST(ARCH64FLAGS)
-AC_SUBST(INSTALL64)
-AC_SUBST(LIB64CUPS)
-AC_SUBST(LIB64CUPSIMAGE)
-AC_SUBST(LIB64DIR)
-AC_SUBST(UNINSTALL64)
+dnl Read-only data/program support on Linux...
+AC_ARG_ENABLE(relro, [ --enable-relro build with the GCC relro option])
-dnl Position-Independent Executable support on Linux and *BSD...
-AC_ARG_ENABLE(pie, [ --enable-pie use GCC -fPIE option, default=no])
+dnl Clang/GCC address sanitizer...
+AC_ARG_ENABLE(sanitizer, [ --enable-sanitizer build with AddressSanitizer])
dnl Update compiler options...
-CXXLIBS=""
+CXXLIBS="${CXXLIBS:=}"
AC_SUBST(CXXLIBS)
PIEFLAGS=""
AC_SUBST(PIEFLAGS)
+RELROFLAGS=""
+AC_SUBST(RELROFLAGS)
+
+WARNING_OPTIONS=""
+AC_SUBST(WARNING_OPTIONS)
+
if test -n "$GCC"; then
+ # Add GCC-specific compiler options...
+
+ # Address sanitizer is a useful tool to use when developing/debugging
+ # code but adds about 2x overhead...
+ if test x$enable_sanitizer = xyes; then
+ # Use -fsanitize=address with debugging...
+ OPTIM="$OPTIM -g -fsanitize=address"
+ else
+ # Otherwise use the Fortify enhancements to catch any unbounded
+ # string operations...
+ CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
+ CXXFLAGS="$CXXFLAGS -D_FORTIFY_SOURCE=2"
+ fi
+
+ # Default optimization options...
if test -z "$OPTIM"; then
- if test "x$with_optim" = x; then
- # Default to optimize-for-size and debug
- OPTIM="-Os -g"
- else
- OPTIM="$with_optim $OPTIM"
- fi
+ # Default to optimize-for-size and debug
+ OPTIM="-Os -g"
fi
- if test $PICFLAG = 1 -a $uname != AIX; then
+ # Generate position-independent code as needed...
+ if test $PICFLAG = 1; then
OPTIM="-fPIC $OPTIM"
fi
- case $uname in
- Linux*)
- if test x$enable_pie = xyes; then
- PIEFLAGS="-pie -fPIE"
- fi
- ;;
-
- *)
- if test x$enable_pie = xyes; then
- echo "Sorry, --enable-pie is not supported on this OS!"
- fi
- ;;
- esac
-
- if test "x$with_optim" = x; then
- # Add useful warning options for tracking down problems...
- OPTIM="-Wall -Wno-format-y2k $OPTIM"
- # Additional warning options for alpha testing...
- OPTIM="-Wshadow -Wunused $OPTIM"
+ # The -fstack-protector option is available with some versions of
+ # GCC and adds "stack canaries" which detect when the return address
+ # has been overwritten, preventing many types of exploit attacks.
+ AC_MSG_CHECKING(whether compiler supports -fstack-protector)
+ OLDCFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS -fstack-protector"
+ AC_TRY_LINK(,,
+ if test "x$LSB_BUILD" = xy; then
+ # Can't use stack-protector with LSB binaries...
+ 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
+ # The -fPIE option is available with some versions of GCC and
+ # adds randomization of addresses, which avoids another class of
+ # exploits that depend on a fixed address for common functions.
+ #
+ # Not available to LSB binaries...
+ 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
- case "$uname" in
- IRIX)
- if test "x$enable_32bit" = xyes; then
- # Build 32-bit libraries, 64-bit base...
- if test -z "$with_arch32flags"; then
- ARCH32FLAGS="-n32 -mips3"
- else
- ARCH32FLAGS="$with_arch32flags"
- fi
- INSTALL32="install32bit"
- LIB32CUPS="32bit/libcups.so.2"
- LIB32CUPSIMAGE="32bit/libcupsimage.so.2"
- LIB32DIR="$prefix/lib32"
- UNINSTALL32="uninstall32bit"
-
- if test -z "$with_archflags"; then
- if test -z "$with_arch64flags"; then
- ARCHFLAGS="-64 -mips4"
- else
- ARCHFLAGS="$with_arch64flags"
- fi
- fi
- fi
-
- if test "x$enable_64bit" = xyes; then
- # Build 64-bit libraries, 32-bit base...
- if test -z "$with_arch64flags"; then
- ARCH64FLAGS="-64 -mips4"
- else
- ARCH64FLAGS="$with_arch64flags"
- fi
- INSTALL64="install64bit"
- LIB64CUPS="64bit/libcups.so.2"
- LIB64CUPSIMAGE="64bit/libcupsimage.so.2"
- LIB64DIR="$prefix/lib64"
- UNINSTALL64="uninstall64bit"
-
- if test -z "$with_archflags"; then
- if test -z "$with_arch32flags"; then
- ARCHFLAGS="-n32 -mips3"
- else
- ARCHFLAGS="$with_arch32flags"
- fi
- fi
- fi
- ;;
-
- Linux*)
- if test "x$enable_32bit" = xyes; then
- # Build 32-bit libraries, 64-bit base...
- if test -z "$with_arch32flags"; then
- ARCH32FLAGS="-m32"
- else
- ARCH32FLAGS="$with_arch32flags"
- fi
- INSTALL32="install32bit"
- LIB32CUPS="32bit/libcups.so.2"
- LIB32CUPSIMAGE="32bit/libcupsimage.so.2"
- LIB32DIR="$exec_prefix/lib"
- if test -d /usr/lib32; then
- LIB32DIR="${LIB32DIR}32"
- fi
- UNINSTALL32="uninstall32bit"
-
- if test -z "$with_archflags"; then
- if test -z "$with_arch64flags"; then
- ARCHFLAGS="-m64"
- else
- ARCHFLAGS="$with_arch64flags"
- fi
- fi
- fi
-
- if test "x$enable_64bit" = xyes; then
- # Build 64-bit libraries, 32-bit base...
- if test -z "$with_arch64flags"; then
- ARCH64FLAGS="-m64"
- else
- ARCH64FLAGS="$with_arch64flags"
- fi
- INSTALL64="install64bit"
- LIB64CUPS="64bit/libcups.so.2"
- LIB64CUPSIMAGE="64bit/libcupsimage.so.2"
- LIB64DIR="$exec_prefix/lib"
- if test -d /usr/lib64; then
- LIB64DIR="${LIB64DIR}64"
- fi
- UNINSTALL64="uninstall64bit"
-
- if test -z "$with_archflags"; then
- if test -z "$with_arch32flags"; then
- ARCHFLAGS="-m32"
- else
- ARCHFLAGS="$with_arch32flags"
- fi
- fi
- fi
- ;;
+ # Add useful warning options for tracking down problems...
+ WARNING_OPTIONS="-Wall -Wno-format-y2k -Wunused -Wno-unused-result -Wsign-conversion -Wno-unused-but-set-variable -Wno-unused-variable"
- SunOS*)
- if test "x$enable_32bit" = xyes; then
- # Build 32-bit libraries, 64-bit base...
- if test -z "$with_arch32flags"; then
- ARCH32FLAGS="-m32"
- else
- ARCH32FLAGS="$with_arch32flags"
- fi
- INSTALL32="install32bit"
- LIB32CUPS="32bit/libcups.so.2"
- LIB32CUPSIMAGE="32bit/libcupsimage.so.2"
- LIB32DIR="$exec_prefix/lib/32"
- UNINSTALL32="uninstall32bit"
-
- if test -z "$with_archflags"; then
- if test -z "$with_arch64flags"; then
- ARCHFLAGS="-m64"
- else
- ARCHFLAGS="$with_arch64flags"
- fi
- fi
- fi
-
- if test "x$enable_64bit" = xyes; then
- # Build 64-bit libraries, 32-bit base...
- if test -z "$with_arch64flags"; then
- ARCH64FLAGS="-m64"
- else
- ARCH64FLAGS="$with_arch64flags"
- fi
- INSTALL64="install64bit"
- LIB64CUPS="64bit/libcups.so.2"
- LIB64CUPSIMAGE="64bit/libcupsimage.so.2"
- LIB64DIR="$exec_prefix/lib/64"
- UNINSTALL64="uninstall64bit"
-
- if test -z "$with_archflags"; then
- if test -z "$with_arch32flags"; then
- ARCHFLAGS="-m32"
- else
- ARCHFLAGS="$with_arch32flags"
- fi
- fi
- fi
+ # Test GCC version for certain warning flags since -Werror
+ # doesn't trigger...
+ 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
-else
- case $uname in
- AIX*)
- if test -z "$OPTIM"; then
- if test "x$with_optim" = x; then
- OPTIM="-O2 -qmaxmem=6000"
- else
- OPTIM="$with_optim $OPTIM"
- fi
- fi
- ;;
- HP-UX*)
- if test -z "$OPTIM"; then
- if test "x$with_optim" = x; then
- OPTIM="+O2"
- else
- OPTIM="$with_optim $OPTIM"
- fi
- fi
- CFLAGS="-Ae $CFLAGS"
- # Warning 336 is "empty translation unit"
- # Warning 829 is passing constant string as char *
- CXXFLAGS="+W336,829 $CXXFLAGS"
-
- if test -z "$with_archflags"; then
- # Build portable binaries for all HP systems...
- ARCHFLAGS="+DAportable"
- fi
-
- if test $PICFLAG = 1; then
- OPTIM="+z $OPTIM"
- fi
- ;;
- IRIX)
- if test -z "$OPTIM"; then
- if test "x$with_optim" = x; then
- OPTIM="-O2"
- else
- OPTIM="$with_optim $OPTIM"
- fi
- fi
-
- if test "x$with_optim" = x; then
- OPTIM="-fullwarn -woff 1183,1209,1349,1506,3201 $OPTIM"
- fi
-
- if test "x$enable_32bit" = xyes; then
- # Build 32-bit libraries, 64-bit base...
- if test -z "$with_arch32flags"; then
- ARCH32FLAGS="-n32 -mips3"
- else
- ARCH32FLAGS="$with_arch32flags"
- fi
- INSTALL32="install32bit"
- LIB32CUPS="32bit/libcups.so.2"
- LIB32CUPSIMAGE="32bit/libcupsimage.so.2"
- LIB32DIR="$prefix/lib32"
- UNINSTALL32="uninstall32bit"
-
- if test -z "$with_archflags"; then
- if test -z "$with_arch64flags"; then
- ARCHFLAGS="-64 -mips4"
- else
- ARCHFLAGS="$with_arch64flags"
- fi
- fi
- fi
-
- if test "x$enable_64bit" = xyes; then
- # Build 64-bit libraries, 32-bit base...
- if test -z "$with_arch64flags"; then
- ARCH64FLAGS="-64 -mips4"
- else
- ARCH64FLAGS="$with_arch64flags"
- fi
- INSTALL64="install64bit"
- LIB64CUPS="64bit/libcups.so.2"
- LIB64CUPSIMAGE="64bit/libcupsimage.so.2"
- LIB64DIR="$prefix/lib64"
- UNINSTALL64="uninstall64bit"
-
- if test -z "$with_archflags"; then
- if test -z "$with_arch32flags"; then
- ARCHFLAGS="-n32 -mips3"
- else
- ARCHFLAGS="$with_arch32flags"
- fi
- fi
- fi
- ;;
- SunOS*)
+ # Additional warning options for development testing...
+ if test -d .git; then
+ WARNING_OPTIONS="-Werror -Wno-error=deprecated-declarations -Wno-unknown-warning-option $WARNING_OPTIONS"
+ fi
+else
+ # Add vendor-specific compiler options...
+ case $host_os_name in
+ sunos*)
# Solaris
if test -z "$OPTIM"; then
- if test "x$with_optim" = x; then
- OPTIM="-xO2"
- else
- OPTIM="$with_optim $OPTIM"
- fi
- fi
-
- if test $PICFLAG = 1; then
- OPTIM="-KPIC $OPTIM"
- fi
-
- if test "x$enable_32bit" = xyes; then
- # Compiling on a Solaris system, build 64-bit
- # binaries with separate 32-bit libraries...
- ARCH32FLAGS="-xarch=generic"
- INSTALL32="install32bit"
- LIB32CUPS="32bit/libcups.so.2"
- LIB32CUPSIMAGE="32bit/libcupsimage.so.2"
- LIB32DIR="$exec_prefix/lib/32"
- UNINSTALL32="uninstall32bit"
-
- if test "x$with_optim" = x; then
- # Suppress all of Sun's questionable
- # warning messages, and default to
- # 64-bit compiles of everything else...
- OPTIM="-w $OPTIM"
- fi
-
- if test -z "$with_archflags"; then
- if test -z "$with_arch64flags"; then
- ARCHFLAGS="-xarch=generic64"
- else
- ARCHFLAGS="$with_arch64flags"
- fi
- fi
- else
- if test "x$enable_64bit" = xyes; then
- # Build 64-bit libraries...
- ARCH64FLAGS="-xarch=generic64"
- INSTALL64="install64bit"
- LIB64CUPS="64bit/libcups.so.2"
- LIB64CUPSIMAGE="64bit/libcupsimage.so.2"
- LIB64DIR="$exec_prefix/lib/64"
- UNINSTALL64="uninstall64bit"
- fi
-
- if test "x$with_optim" = x; then
- # Suppress all of Sun's questionable
- # warning messages, and default to
- # 32-bit compiles of everything else...
- OPTIM="-w $OPTIM"
- fi
-
- if test -z "$with_archflags"; then
- if test -z "$with_arch32flags"; then
- ARCHFLAGS="-xarch=generic"
- else
- ARCHFLAGS="$with_arch32flags"
- fi
- fi
- fi
- ;;
- UNIX_SVR*)
- # UnixWare
- if test -z "$OPTIM"; then
- if test "x$with_optim" = x; then
- OPTIM="-O"
- else
- OPTIM="$with_optim $OPTIM"
- fi
+ OPTIM="-xO2"
fi
if test $PICFLAG = 1; then
fi
;;
*)
- # Running some other operating system; inform the user they
- # should contribute the necessary options to
- # cups-support@cups.org...
- echo "Building CUPS with default compiler optimizations; contact"
- echo "cups-bugs@cups.org with uname and compiler options needed"
- echo "for your platform, or set the CFLAGS and CXXFLAGS"
- echo "environment variable before running configure."
+ # Running some other operating system; inform the user
+ # they should contribute the necessary options via
+ # Github...
+ 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
-if test $uname = HP-UX; then
- # HP-UX 10.20 (at least) needs this definition to get the
- # h_errno global...
- OPTIM="$OPTIM -D_XOPEN_SOURCE_EXTENDED"
-
- # HP-UX 11.00 (at least) needs this definition to get the
- # u_short type used by the IP headers...
- OPTIM="$OPTIM -D_INCLUDE_HPUX_SOURCE"
-fi
-
-dnl
-dnl End of "$Id: cups-compiler.m4 181 2006-06-22 20:01:18Z jlovell $".
-dnl
+# Add general compiler options per platform...
+case $host_os_name in
+ linux*)
+ # glibc 2.8 and higher breaks peer credentials unless you
+ # define _GNU_SOURCE...
+ OPTIM="$OPTIM -D_GNU_SOURCE"
+
+ # The -z relro option is provided by the Linux linker command to
+ # make relocatable data read-only.
+ if test x$enable_relro = xyes; then
+ RELROFLAGS="-Wl,-z,relro,-z,now"
+ fi
+ ;;
+esac