2 dnl Compiler stuff for CUPS.
4 dnl Copyright 2007-2014 by Apple Inc.
5 dnl Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 dnl These coded instructions, statements, and computer programs are the
8 dnl property of Apple Inc. and are protected by Federal copyright
9 dnl law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 dnl which should have been included with this file. If this file is
11 dnl file is missing or damaged, see the license at "http://www.cups.org/".
14 dnl Clear the debugging and non-shared library options unless the user asks
18 AC_SUBST(INSTALL_STRIP)
21 AC_ARG_WITH(optim, [ --with-optim set optimization flags ])
22 AC_ARG_ENABLE(debug, [ --enable-debug build with debugging symbols])
23 AC_ARG_ENABLE(debug_guards, [ --enable-debug-guards build with memory allocation guards])
24 AC_ARG_ENABLE(debug_printfs, [ --enable-debug-printfs build with CUPS_DEBUG_LOG support])
25 AC_ARG_ENABLE(unit_tests, [ --enable-unit-tests build and run unit tests])
27 dnl For debugging, keep symbols, otherwise strip them...
28 if test x$enable_debug = xyes; then
34 dnl Debug printfs can slow things down, so provide a separate option for that
35 if test x$enable_debug_printfs = xyes; then
36 CFLAGS="$CFLAGS -DDEBUG"
37 CXXFLAGS="$CXXFLAGS -DDEBUG"
40 dnl Debug guards use an extra 4 bytes for some structures like strings in the
41 dnl string pool, so provide a separate option for that
42 if test x$enable_debug_guards = xyes; then
43 CFLAGS="$CFLAGS -DDEBUG_GUARDS"
44 CXXFLAGS="$CXXFLAGS -DDEBUG_GUARDS"
47 dnl Unit tests take up time during a compile...
48 if test x$enable_unit_tests = xyes; then
55 dnl Setup general architecture flags...
56 AC_ARG_WITH(archflags, [ --with-archflags set default architecture flags ])
57 AC_ARG_WITH(ldarchflags, [ --with-ldarchflags set program architecture flags ])
59 if test -z "$with_archflags"; then
62 ARCHFLAGS="$with_archflags"
65 if test -z "$with_ldarchflags"; then
66 if test "$uname" = Darwin; then
67 # Only create Intel programs by default
68 LDARCHFLAGS="`echo $ARCHFLAGS | sed -e '1,$s/-arch ppc64//'`"
70 LDARCHFLAGS="$ARCHFLAGS"
73 LDARCHFLAGS="$with_ldarchflags"
79 dnl Read-only data/program support on Linux...
80 AC_ARG_ENABLE(relro, [ --enable-relro build with the GCC relro option])
82 dnl Update compiler options...
83 CXXLIBS="${CXXLIBS:=}"
92 if test -n "$GCC"; then
93 # Add GCC-specific compiler options...
94 if test -z "$OPTIM"; then
95 if test "x$with_optim" = x; then
96 # Default to optimize-for-size and debug
99 OPTIM="$with_optim $OPTIM"
103 # Generate position-independent code as needed...
104 if test $PICFLAG = 1; then
108 # The -fstack-protector option is available with some versions of
109 # GCC and adds "stack canaries" which detect when the return address
110 # has been overwritten, preventing many types of exploit attacks.
111 AC_MSG_CHECKING(whether compiler supports -fstack-protector)
113 CFLAGS="$CFLAGS -fstack-protector"
115 if test "x$LSB_BUILD" = xy; then
116 # Can't use stack-protector with LSB binaries...
117 OPTIM="$OPTIM -fno-stack-protector"
119 OPTIM="$OPTIM -fstack-protector"
125 if test "x$LSB_BUILD" != xy; then
126 # The -fPIE option is available with some versions of GCC and
127 # adds randomization of addresses, which avoids another class of
128 # exploits that depend on a fixed address for common functions.
130 # Not available to LSB binaries...
131 AC_MSG_CHECKING(whether compiler supports -fPIE)
135 CFLAGS="$CFLAGS -fPIE -Wl,-pie"
137 PIEFLAGS="-fPIE -Wl,-pie"
143 CFLAGS="$CFLAGS -fPIE -pie"
145 PIEFLAGS="-fPIE -pie"
153 if test "x$with_optim" = x; then
154 # Add useful warning options for tracking down problems...
155 OPTIM="-Wall -Wno-format-y2k -Wunused $OPTIM"
157 AC_MSG_CHECKING(whether compiler supports -Wno-unused-result)
159 CFLAGS="$CFLAGS -Werror -Wno-unused-result"
161 [OPTIM="$OPTIM -Wno-unused-result"
166 AC_MSG_CHECKING(whether compiler supports -Wsign-conversion)
168 CFLAGS="$CFLAGS -Werror -Wsign-conversion"
170 [OPTIM="$OPTIM -Wsign-conversion"
175 AC_MSG_CHECKING(whether compiler supports -Wno-tautological-compare)
177 CFLAGS="$CFLAGS -Werror -Wno-tautological-compare"
179 [OPTIM="$OPTIM -Wno-tautological-compare"
184 # Additional warning options for development testing...
185 if test -d .svn; then
186 OPTIM="-Werror $OPTIM"
192 # -D_FORTIFY_SOURCE=2 adds additional object size
193 # checking, basically wrapping all string functions
194 # with buffer-limited ones. Not strictly needed for
195 # CUPS since we already use buffer-limited calls, but
196 # this will catch any additions that are broken.
197 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
201 # The -z relro option is provided by the Linux linker command to
202 # make relocatable data read-only.
203 if test x$enable_relro = xyes; then
204 RELROFLAGS="-Wl,-z,relro,-z,now"
209 # Add vendor-specific compiler options...
213 if test -z "$OPTIM"; then
214 if test "x$with_optim" = x; then
217 OPTIM="$with_optim $OPTIM"
221 if test $PICFLAG = 1; then
226 # Running some other operating system; inform the user they
227 # should contribute the necessary options to
228 # cups-support@cups.org...
229 echo "Building CUPS with default compiler optimizations; contact"
230 echo "cups-devel@cups.org with uname and compiler options needed"
231 echo "for your platform, or set the CFLAGS and LDFLAGS environment"
232 echo "variables before running configure."
237 # Add general compiler options per platform...
240 # glibc 2.8 and higher breaks peer credentials unless you
241 # define _GNU_SOURCE...
242 OPTIM="$OPTIM -D_GNU_SOURCE"