2 dnl "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $"
4 dnl Compiler stuff for CUPS.
6 dnl Copyright 2007-2013 by Apple Inc.
7 dnl Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 dnl These coded instructions, statements, and computer programs are the
10 dnl property of Apple Inc. and are protected by Federal copyright
11 dnl law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 dnl which should have been included with this file. If this file is
13 dnl file is missing or damaged, see the license at "http://www.cups.org/".
16 dnl Clear the debugging and non-shared library options unless the user asks
20 AC_SUBST(INSTALL_STRIP)
23 AC_ARG_WITH(optim, [ --with-optim set optimization flags ])
24 AC_ARG_ENABLE(debug, [ --enable-debug build with debugging symbols])
25 AC_ARG_ENABLE(debug_guards, [ --enable-debug-guards build with memory allocation guards])
26 AC_ARG_ENABLE(debug_printfs, [ --enable-debug-printfs build with CUPS_DEBUG_LOG support])
27 AC_ARG_ENABLE(unit_tests, [ --enable-unit-tests build and run unit tests])
29 dnl For debugging, keep symbols, otherwise strip them...
30 if test x$enable_debug = xyes; then
36 dnl Debug printfs can slow things down, so provide a separate option for that
37 if test x$enable_debug_printfs = xyes; then
38 CFLAGS="$CFLAGS -DDEBUG"
39 CXXFLAGS="$CXXFLAGS -DDEBUG"
42 dnl Debug guards use an extra 4 bytes for some structures like strings in the
43 dnl string pool, so provide a separate option for that
44 if test x$enable_debug_guards = xyes; then
45 CFLAGS="$CFLAGS -DDEBUG_GUARDS"
46 CXXFLAGS="$CXXFLAGS -DDEBUG_GUARDS"
49 dnl Unit tests take up time during a compile...
50 if test x$enable_unit_tests = xyes; then
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 "$uname" = 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 Update compiler options...
85 CXXLIBS="${CXXLIBS:=}"
94 if test -n "$GCC"; then
95 # Add GCC-specific compiler options...
96 if test -z "$OPTIM"; then
97 if test "x$with_optim" = x; then
98 # Default to optimize-for-size and debug
101 OPTIM="$with_optim $OPTIM"
105 # Generate position-independent code as needed...
106 if test $PICFLAG = 1 -a $uname != AIX; then
110 # The -fstack-protector option is available with some versions of
111 # GCC and adds "stack canaries" which detect when the return address
112 # has been overwritten, preventing many types of exploit attacks.
113 AC_MSG_CHECKING(if GCC supports -fstack-protector)
115 CFLAGS="$CFLAGS -fstack-protector"
117 if test "x$LSB_BUILD" = xy; then
118 # Can't use stack-protector with LSB binaries...
119 OPTIM="$OPTIM -fno-stack-protector"
121 OPTIM="$OPTIM -fstack-protector"
127 if test "x$LSB_BUILD" != xy; then
128 # The -fPIE option is available with some versions of GCC and
129 # adds randomization of addresses, which avoids another class of
130 # exploits that depend on a fixed address for common functions.
132 # Not available to LSB binaries...
133 AC_MSG_CHECKING(if GCC supports -fPIE)
135 CFLAGS="$CFLAGS -fPIE -pie"
137 PIEFLAGS="-fPIE -pie"
143 if test "x$with_optim" = x; then
144 # Add useful warning options for tracking down problems...
145 OPTIM="-Wall -Wno-format-y2k -Wunused $OPTIM"
147 # Additional warning options for development testing...
148 if test -d .svn; then
149 OPTIM="-Wshadow -Werror $OPTIM"
151 AC_MSG_CHECKING(if GCC supports -Wno-tautological-compare)
153 CFLAGS="$CFLAGS -Werror -Wno-tautological-compare"
155 [OPTIM="$OPTIM -Wno-tautological-compare"
164 # -D_FORTIFY_SOURCE=2 adds additional object size
165 # checking, basically wrapping all string functions
166 # with buffer-limited ones. Not strictly needed for
167 # CUPS since we already use buffer-limited calls, but
168 # this will catch any additions that are broken.
169 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
173 # The -z relro option is provided by the Linux linker command to
174 # make relocatable data read-only.
175 if test x$enable_relro = xyes; then
176 RELROFLAGS="-Wl,-z,relro"
181 # Add vendor-specific compiler options...
184 if test -z "$OPTIM"; then
185 if test "x$with_optim" = x; then
186 OPTIM="-O2 -qmaxmem=6000"
188 OPTIM="$with_optim $OPTIM"
193 if test -z "$OPTIM"; then
194 if test "x$with_optim" = x; then
197 OPTIM="$with_optim $OPTIM"
203 if test $PICFLAG = 1; then
208 # Tru64 UNIX aka Digital UNIX aka OSF/1
209 if test -z "$OPTIM"; then
210 if test "x$with_optim" = x; then
219 if test -z "$OPTIM"; then
220 if test "x$with_optim" = x; then
223 OPTIM="$with_optim $OPTIM"
227 if test $PICFLAG = 1; then
233 if test -z "$OPTIM"; then
234 if test "x$with_optim" = x; then
237 OPTIM="$with_optim $OPTIM"
241 if test $PICFLAG = 1; then
246 # Running some other operating system; inform the user they
247 # should contribute the necessary options to
248 # cups-support@cups.org...
249 echo "Building CUPS with default compiler optimizations; contact"
250 echo "cups-bugs@cups.org with uname and compiler options needed"
251 echo "for your platform, or set the CFLAGS and LDFLAGS environment"
252 echo "variables before running configure."
257 # Add general compiler options per platform...
260 # HP-UX 10.20 (at least) needs this definition to get the
262 OPTIM="$OPTIM -D_XOPEN_SOURCE_EXTENDED"
264 # HP-UX 11.00 (at least) needs this definition to get the
265 # u_short type used by the IP headers...
266 OPTIM="$OPTIM -D_INCLUDE_HPUX_SOURCE"
268 # HP-UX 11.23 (at least) needs this definition to get the
269 # IPv6 header to work...
270 OPTIM="$OPTIM -D_HPUX_SOURCE"
274 # glibc 2.8 and higher breaks peer credentials unless you
275 # define _GNU_SOURCE...
276 OPTIM="$OPTIM -D_GNU_SOURCE"
280 # Tru64 UNIX aka Digital UNIX aka OSF/1 need to be told
281 # to be POSIX-compliant...
282 OPTIM="$OPTIM -D_XOPEN_SOURCE=500 -D_XOPEN_SOURCE_EXTENDED -D_OSF_SOURCE"
287 dnl End of "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $".