2 dnl "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $"
4 dnl Compiler stuff for CUPS.
6 dnl Copyright 2007-2011 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 32-bit programs by default
70 LDARCHFLAGS="`echo $ARCHFLAGS | sed -e '1,$s/-arch x86_64//' -e '1,$s/-arch ppc64//'`"
72 LDARCHFLAGS="$ARCHFLAGS"
75 LDARCHFLAGS="$with_ldarchflags"
81 dnl Setup support for separate 32/64-bit library generation...
82 AC_ARG_WITH(arch32flags, [ --with-arch32flags set 32-bit architecture flags])
86 AC_ARG_WITH(arch64flags, [ --with-arch64flags set 64-bit architecture flags])
90 dnl Read-only data/program support on Linux...
91 AC_ARG_ENABLE(relro, [ --enable-relro build with the GCC relro option])
93 dnl Update compiler options...
94 CXXLIBS="${CXXLIBS:=}"
103 if test -n "$GCC"; then
104 # Add GCC-specific compiler options...
105 if test -z "$OPTIM"; then
106 if test "x$with_optim" = x; then
107 # Default to optimize-for-size and debug
110 OPTIM="$with_optim $OPTIM"
114 # Generate position-independent code as needed...
115 if test $PICFLAG = 1 -a $uname != AIX; then
119 # The -fstack-protector option is available with some versions of
120 # GCC and adds "stack canaries" which detect when the return address
121 # has been overwritten, preventing many types of exploit attacks.
122 AC_MSG_CHECKING(if GCC supports -fstack-protector)
124 CFLAGS="$CFLAGS -fstack-protector"
126 OPTIM="$OPTIM -fstack-protector"
131 # The -fPIE option is available with some versions of GCC and adds
132 # randomization of addresses, which avoids another class of exploits
133 # that depend on a fixed address for common functions.
134 AC_MSG_CHECKING(if GCC supports -fPIE)
136 CFLAGS="$CFLAGS -fPIE"
140 PIEFLAGS="-fPIE -Wl,-pie"
143 PIEFLAGS="-fPIE -pie"
150 if test "x$with_optim" = x; then
151 # Add useful warning options for tracking down problems...
152 OPTIM="-Wall -Wno-format-y2k -Wunused $OPTIM"
154 # Additional warning options for development testing...
155 if test -d .svn; then
156 OPTIM="-Wshadow -Werror $OPTIM"
158 AC_MSG_CHECKING(if GCC supports -Wno-tautological-compare)
160 CFLAGS="$CFLAGS -Werror -Wno-tautological-compare"
162 [OPTIM="$OPTIM -Wno-tautological-compare"
171 # -D_FORTIFY_SOURCE=2 adds additional object size
172 # checking, basically wrapping all string functions
173 # with buffer-limited ones. Not strictly needed for
174 # CUPS since we already use buffer-limited calls, but
175 # this will catch any additions that are broken.
176 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
180 if test "x$enable_32bit" = xyes; then
181 # Build 32-bit libraries, 64-bit base...
182 if test -z "$with_arch32flags"; then
183 ARCH32FLAGS="-milp32"
185 ARCH32FLAGS="$with_arch32flags"
188 if test -z "$with_archflags"; then
189 if test -z "$with_arch64flags"; then
192 ARCHFLAGS="$with_arch64flags"
197 if test "x$enable_64bit" = xyes; then
198 # Build 64-bit libraries, 32-bit base...
199 if test -z "$with_arch64flags"; then
202 ARCH64FLAGS="$with_arch64flags"
205 if test -z "$with_archflags"; then
206 if test -z "$with_arch32flags"; then
209 ARCHFLAGS="$with_arch32flags"
216 if test "x$enable_32bit" = xyes; then
217 # Build 32-bit libraries, 64-bit base...
218 if test -z "$with_arch32flags"; then
219 ARCH32FLAGS="-n32 -mips3"
221 ARCH32FLAGS="$with_arch32flags"
224 if test -z "$with_archflags"; then
225 if test -z "$with_arch64flags"; then
226 ARCHFLAGS="-64 -mips4"
228 ARCHFLAGS="$with_arch64flags"
233 if test "x$enable_64bit" = xyes; then
234 # Build 64-bit libraries, 32-bit base...
235 if test -z "$with_arch64flags"; then
236 ARCH64FLAGS="-64 -mips4"
238 ARCH64FLAGS="$with_arch64flags"
241 if test -z "$with_archflags"; then
242 if test -z "$with_arch32flags"; then
243 ARCHFLAGS="-n32 -mips3"
245 ARCHFLAGS="$with_arch32flags"
252 # The -z relro option is provided by the Linux linker command to
253 # make relocatable data read-only.
254 if test x$enable_relro = xyes; then
255 RELROFLAGS="-Wl,-z,relro"
258 if test "x$enable_32bit" = xyes; then
259 # Build 32-bit libraries, 64-bit base...
260 if test -z "$with_arch32flags"; then
263 ARCH32FLAGS="$with_arch32flags"
266 if test -z "$with_archflags"; then
267 if test -z "$with_arch64flags"; then
270 ARCHFLAGS="$with_arch64flags"
275 if test "x$enable_64bit" = xyes; then
276 # Build 64-bit libraries, 32-bit base...
277 if test -z "$with_arch64flags"; then
280 ARCH64FLAGS="$with_arch64flags"
283 if test -z "$with_archflags"; then
284 if test -z "$with_arch32flags"; then
287 ARCHFLAGS="$with_arch32flags"
294 if test "x$enable_32bit" = xyes; then
295 # Build 32-bit libraries, 64-bit base...
296 if test -z "$with_arch32flags"; then
299 ARCH32FLAGS="$with_arch32flags"
302 if test -z "$with_archflags"; then
303 if test -z "$with_arch64flags"; then
306 ARCHFLAGS="$with_arch64flags"
311 if test "x$enable_64bit" = xyes; then
312 # Build 64-bit libraries, 32-bit base...
313 if test -z "$with_arch64flags"; then
316 ARCH64FLAGS="$with_arch64flags"
319 if test -z "$with_archflags"; then
320 if test -z "$with_arch32flags"; then
323 ARCHFLAGS="$with_arch32flags"
330 # Add vendor-specific compiler options...
333 if test -z "$OPTIM"; then
334 if test "x$with_optim" = x; then
335 OPTIM="-O2 -qmaxmem=6000"
337 OPTIM="$with_optim $OPTIM"
342 if test -z "$OPTIM"; then
343 if test "x$with_optim" = x; then
346 OPTIM="$with_optim $OPTIM"
352 if test $PICFLAG = 1; then
356 if test "x$enable_32bit" = xyes; then
357 # Build 32-bit libraries, 64-bit base...
358 if test -z "$with_arch32flags"; then
361 ARCH32FLAGS="$with_arch32flags"
364 if test -z "$with_archflags"; then
365 if test -z "$with_arch64flags"; then
368 ARCHFLAGS="$with_arch64flags"
373 if test "x$enable_64bit" = xyes; then
374 # Build 64-bit libraries, 32-bit base...
375 if test -z "$with_arch64flags"; then
378 ARCH64FLAGS="$with_arch64flags"
381 if test -z "$with_archflags"; then
382 if test -z "$with_arch32flags"; then
385 ARCHFLAGS="$with_arch32flags"
391 if test -z "$OPTIM"; then
392 if test "x$with_optim" = x; then
395 OPTIM="$with_optim $OPTIM"
399 if test "x$with_optim" = x; then
400 OPTIM="-fullwarn -woff 1183,1209,1349,1506,3201 $OPTIM"
403 if test "x$enable_32bit" = xyes; then
404 # Build 32-bit libraries, 64-bit base...
405 if test -z "$with_arch32flags"; then
406 ARCH32FLAGS="-n32 -mips3"
408 ARCH32FLAGS="$with_arch32flags"
411 if test -z "$with_archflags"; then
412 if test -z "$with_arch64flags"; then
413 ARCHFLAGS="-64 -mips4"
415 ARCHFLAGS="$with_arch64flags"
420 if test "x$enable_64bit" = xyes; then
421 # Build 64-bit libraries, 32-bit base...
422 if test -z "$with_arch64flags"; then
423 ARCH64FLAGS="-64 -mips4"
425 ARCH64FLAGS="$with_arch64flags"
428 if test -z "$with_archflags"; then
429 if test -z "$with_arch32flags"; then
430 ARCHFLAGS="-n32 -mips3"
432 ARCHFLAGS="$with_arch32flags"
438 # Tru64 UNIX aka Digital UNIX aka OSF/1
439 if test -z "$OPTIM"; then
440 if test "x$with_optim" = x; then
449 if test -z "$OPTIM"; then
450 if test "x$with_optim" = x; then
453 OPTIM="$with_optim $OPTIM"
457 if test $PICFLAG = 1; then
461 if test "x$enable_32bit" = xyes; then
462 # Compiling on a Solaris system, build 64-bit
463 # binaries with separate 32-bit libraries...
464 ARCH32FLAGS="-xarch=generic"
466 if test "x$with_optim" = x; then
467 # Suppress all of Sun's questionable
468 # warning messages, and default to
469 # 64-bit compiles of everything else...
473 if test -z "$with_archflags"; then
474 if test -z "$with_arch64flags"; then
475 ARCHFLAGS="-xarch=generic64"
477 ARCHFLAGS="$with_arch64flags"
481 if test "x$enable_64bit" = xyes; then
482 # Build 64-bit libraries...
483 ARCH64FLAGS="-xarch=generic64"
486 if test "x$with_optim" = x; then
487 # Suppress all of Sun's questionable
488 # warning messages, and default to
489 # 32-bit compiles of everything else...
493 if test -z "$with_archflags"; then
494 if test -z "$with_arch32flags"; then
495 ARCHFLAGS="-xarch=generic"
497 ARCHFLAGS="$with_arch32flags"
504 if test -z "$OPTIM"; then
505 if test "x$with_optim" = x; then
508 OPTIM="$with_optim $OPTIM"
512 if test $PICFLAG = 1; then
517 # Running some other operating system; inform the user they
518 # should contribute the necessary options to
519 # cups-support@cups.org...
520 echo "Building CUPS with default compiler optimizations; contact"
521 echo "cups-bugs@cups.org with uname and compiler options needed"
522 echo "for your platform, or set the CFLAGS and LDFLAGS environment"
523 echo "variables before running configure."
528 # Add general compiler options per platform...
531 # HP-UX 10.20 (at least) needs this definition to get the
533 OPTIM="$OPTIM -D_XOPEN_SOURCE_EXTENDED"
535 # HP-UX 11.00 (at least) needs this definition to get the
536 # u_short type used by the IP headers...
537 OPTIM="$OPTIM -D_INCLUDE_HPUX_SOURCE"
539 # HP-UX 11.23 (at least) needs this definition to get the
540 # IPv6 header to work...
541 OPTIM="$OPTIM -D_HPUX_SOURCE"
545 # glibc 2.8 and higher breaks peer credentials unless you
546 # define _GNU_SOURCE...
547 OPTIM="$OPTIM -D_GNU_SOURCE"
551 # Tru64 UNIX aka Digital UNIX aka OSF/1 need to be told
552 # to be POSIX-compliant...
553 OPTIM="$OPTIM -D_XOPEN_SOURCE=500 -D_XOPEN_SOURCE_EXTENDED -D_OSF_SOURCE"
558 dnl End of "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $".