2 dnl Compiler stuff for CUPS.
4 dnl Copyright 2007-2018 by Apple Inc.
5 dnl Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 dnl Licensed under Apache License v2.0. See the file "LICENSE" for more information.
10 dnl Clear the debugging and non-shared library options unless the user asks
13 AC_SUBST(INSTALL_STRIP)
15 AC_ARG_WITH(optim, [ --with-optim set optimization flags ],
20 AC_ARG_ENABLE(debug, [ --enable-debug build with debugging symbols])
21 AC_ARG_ENABLE(debug_guards, [ --enable-debug-guards build with memory allocation guards])
22 AC_ARG_ENABLE(debug_printfs, [ --enable-debug-printfs build with CUPS_DEBUG_LOG support])
23 AC_ARG_ENABLE(unit_tests, [ --enable-unit-tests build and run unit tests])
25 dnl For debugging, keep symbols, otherwise strip them...
26 if test x$enable_debug = xyes -a "x$OPTIM" = x; then
32 dnl Debug printfs can slow things down, so provide a separate option for that
33 if test x$enable_debug_printfs = xyes; then
34 CFLAGS="$CFLAGS -DDEBUG"
35 CXXFLAGS="$CXXFLAGS -DDEBUG"
38 dnl Debug guards use an extra 4 bytes for some structures like strings in the
39 dnl string pool, so provide a separate option for that
40 if test x$enable_debug_guards = xyes; then
41 CFLAGS="$CFLAGS -DDEBUG_GUARDS"
42 CXXFLAGS="$CXXFLAGS -DDEBUG_GUARDS"
45 dnl Unit tests take up time during a compile...
46 if test x$enable_unit_tests = xyes; then
47 if test "$build" != "$host"; then
48 AC_MSG_ERROR([Sorry, cannot build unit tests when cross-compiling.])
57 dnl Setup general architecture flags...
58 AC_ARG_WITH(archflags, [ --with-archflags set default architecture flags ])
59 AC_ARG_WITH(ldarchflags, [ --with-ldarchflags set program architecture flags ])
61 if test -z "$with_archflags"; then
64 ARCHFLAGS="$with_archflags"
67 if test -z "$with_ldarchflags"; then
68 if test "$host_os_name" = darwin; then
69 # Only create Intel programs by default
70 LDARCHFLAGS="`echo $ARCHFLAGS | sed -e '1,$s/-arch ppc64//'`"
72 LDARCHFLAGS="$ARCHFLAGS"
75 LDARCHFLAGS="$with_ldarchflags"
81 dnl Read-only data/program support on Linux...
82 AC_ARG_ENABLE(relro, [ --enable-relro build with the GCC relro option])
84 dnl Clang/GCC address sanitizer...
85 AC_ARG_ENABLE(sanitizer, [ --enable-sanitizer build with AddressSanitizer])
87 dnl Update compiler options...
88 CXXLIBS="${CXXLIBS:=}"
98 AC_SUBST(WARNING_OPTIONS)
100 if test -n "$GCC"; then
101 # Add GCC-specific compiler options...
103 # Address sanitizer is a useful tool to use when developing/debugging
104 # code but adds about 2x overhead...
105 if test x$enable_sanitizer = xyes; then
106 # Use -fsanitize=address with debugging...
107 OPTIM="$OPTIM -g -fsanitize=address"
109 # Otherwise use the Fortify enhancements to catch any unbounded
110 # string operations...
111 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
112 CXXFLAGS="$CXXFLAGS -D_FORTIFY_SOURCE=2"
115 # Default optimization options...
116 if test -z "$OPTIM"; then
117 # Default to optimize-for-size and debug
121 # Generate position-independent code as needed...
122 if test $PICFLAG = 1; then
126 # The -fstack-protector option is available with some versions of
127 # GCC and adds "stack canaries" which detect when the return address
128 # has been overwritten, preventing many types of exploit attacks.
129 AC_MSG_CHECKING(whether compiler supports -fstack-protector)
131 CFLAGS="$CFLAGS -fstack-protector"
133 if test "x$LSB_BUILD" = xy; then
134 # Can't use stack-protector with LSB binaries...
135 OPTIM="$OPTIM -fno-stack-protector"
137 OPTIM="$OPTIM -fstack-protector"
143 if test "x$LSB_BUILD" != xy; then
144 # The -fPIE option is available with some versions of GCC and
145 # adds randomization of addresses, which avoids another class of
146 # exploits that depend on a fixed address for common functions.
148 # Not available to LSB binaries...
149 AC_MSG_CHECKING(whether compiler supports -fPIE)
151 case "$host_os_name" in
153 CFLAGS="$CFLAGS -fPIE -Wl,-pie"
155 PIEFLAGS="-fPIE -Wl,-pie"
161 CFLAGS="$CFLAGS -fPIE -pie"
163 PIEFLAGS="-fPIE -pie"
171 # Add useful warning options for tracking down problems...
172 WARNING_OPTIONS="-Wall -Wno-format-y2k -Wunused -Wno-unused-result -Wsign-conversion"
174 # Test GCC version for certain warning flags since -Werror
176 gccversion=`$CC --version | head -1 | awk '{print $NF}'`
177 case "$gccversion" in
179 WARNING_OPTIONS="$WARNING_OPTIONS -Wno-format-truncation -Wno-tautological-compare"
183 # Additional warning options for development testing...
184 if test -d .git; then
185 WARNING_OPTIONS="-Werror -Wno-error=deprecated-declarations $WARNING_OPTIONS"
188 # Add vendor-specific compiler options...
189 case $host_os_name in
192 if test -z "$OPTIM"; then
196 if test $PICFLAG = 1; then
201 # Running some other operating system; inform the user
202 # they should contribute the necessary options via
204 echo "Building CUPS with default compiler optimizations; contact the CUPS developers on Github"
205 echo "(https://github.com/apple/cups/issues) with the uname and compiler options needed for"
206 echo "your platform, or set the CFLAGS and LDFLAGS environment variables before running"
212 # Add general compiler options per platform...
213 case $host_os_name in
215 # glibc 2.8 and higher breaks peer credentials unless you
216 # define _GNU_SOURCE...
217 OPTIM="$OPTIM -D_GNU_SOURCE"
219 # The -z relro option is provided by the Linux linker command to
220 # make relocatable data read-only.
221 if test x$enable_relro = xyes; then
222 RELROFLAGS="-Wl,-z,relro,-z,now"