2 dnl Compiler stuff for CUPS.
4 dnl Copyright 2007-2017 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 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
49 if test "$build" != "$host"; then
50 AC_MSG_ERROR([Sorry, cannot build unit tests when cross-compiling.])
59 dnl Setup general architecture flags...
60 AC_ARG_WITH(archflags, [ --with-archflags set default architecture flags ])
61 AC_ARG_WITH(ldarchflags, [ --with-ldarchflags set program architecture flags ])
63 if test -z "$with_archflags"; then
66 ARCHFLAGS="$with_archflags"
69 if test -z "$with_ldarchflags"; then
70 if test "$host_os_name" = darwin; then
71 # Only create Intel programs by default
72 LDARCHFLAGS="`echo $ARCHFLAGS | sed -e '1,$s/-arch ppc64//'`"
74 LDARCHFLAGS="$ARCHFLAGS"
77 LDARCHFLAGS="$with_ldarchflags"
83 dnl Read-only data/program support on Linux...
84 AC_ARG_ENABLE(relro, [ --enable-relro build with the GCC relro option])
86 dnl Update compiler options...
87 CXXLIBS="${CXXLIBS:=}"
96 if test -n "$GCC"; then
97 # Add GCC-specific compiler options...
98 if test -z "$OPTIM"; then
99 if test "x$with_optim" = x; then
100 # Default to optimize-for-size and debug
103 OPTIM="$with_optim $OPTIM"
107 # Generate position-independent code as needed...
108 if test $PICFLAG = 1; then
112 # The -fstack-protector option is available with some versions of
113 # GCC and adds "stack canaries" which detect when the return address
114 # has been overwritten, preventing many types of exploit attacks.
115 AC_MSG_CHECKING(whether compiler supports -fstack-protector)
117 CFLAGS="$CFLAGS -fstack-protector"
119 if test "x$LSB_BUILD" = xy; then
120 # Can't use stack-protector with LSB binaries...
121 OPTIM="$OPTIM -fno-stack-protector"
123 OPTIM="$OPTIM -fstack-protector"
129 if test "x$LSB_BUILD" != xy; then
130 # The -fPIE option is available with some versions of GCC and
131 # adds randomization of addresses, which avoids another class of
132 # exploits that depend on a fixed address for common functions.
134 # Not available to LSB binaries...
135 AC_MSG_CHECKING(whether compiler supports -fPIE)
137 case "$host_os_name" in
139 CFLAGS="$CFLAGS -fPIE -Wl,-pie"
141 PIEFLAGS="-fPIE -Wl,-pie"
147 CFLAGS="$CFLAGS -fPIE -pie"
149 PIEFLAGS="-fPIE -pie"
157 if test "x$with_optim" = x; then
158 # Add useful warning options for tracking down problems...
159 OPTIM="-Wall -Wno-format-y2k -Wunused $OPTIM"
161 AC_MSG_CHECKING(whether compiler supports -Wno-unused-result)
163 CFLAGS="$CFLAGS -Werror -Wno-unused-result"
165 [OPTIM="$OPTIM -Wno-unused-result"
170 AC_MSG_CHECKING(whether compiler supports -Wsign-conversion)
172 CFLAGS="$CFLAGS -Werror -Wsign-conversion"
174 [OPTIM="$OPTIM -Wsign-conversion"
179 AC_MSG_CHECKING(whether compiler supports -Wno-tautological-compare)
181 CFLAGS="$CFLAGS -Werror -Wno-tautological-compare"
183 [OPTIM="$OPTIM -Wno-tautological-compare"
188 AC_MSG_CHECKING(whether compiler supports -Wno-format-truncation)
190 CFLAGS="$CFLAGS -Werror -Wno-format-truncation"
192 [OPTIM="$OPTIM -Wno-format-truncation"
197 # Additional warning options for development testing...
198 if test -d .svn; then
199 OPTIM="-Werror $OPTIM"
203 case "$host_os_name" in
205 # -D_FORTIFY_SOURCE=2 adds additional object size
206 # checking, basically wrapping all string functions
207 # with buffer-limited ones. Not strictly needed for
208 # CUPS since we already use buffer-limited calls, but
209 # this will catch any additions that are broken.
210 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
214 # The -z relro option is provided by the Linux linker command to
215 # make relocatable data read-only.
216 if test x$enable_relro = xyes; then
217 RELROFLAGS="-Wl,-z,relro,-z,now"
222 # Add vendor-specific compiler options...
223 case $host_os_name in
226 if test -z "$OPTIM"; then
227 if test "x$with_optim" = x; then
230 OPTIM="$with_optim $OPTIM"
234 if test $PICFLAG = 1; then
239 # Running some other operating system; inform the user they
240 # should contribute the necessary options to
241 # cups-support@cups.org...
242 echo "Building CUPS with default compiler optimizations; contact"
243 echo "cups-devel@cups.org with uname and compiler options needed"
244 echo "for your platform, or set the CFLAGS and LDFLAGS environment"
245 echo "variables before running configure."
250 # Add general compiler options per platform...
251 case $host_os_name in
253 # glibc 2.8 and higher breaks peer credentials unless you
254 # define _GNU_SOURCE...
255 OPTIM="$OPTIM -D_GNU_SOURCE"