2 dnl "$Id: cups-compiler.m4 9981 2011-09-09 17:28:58Z 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:=}"
106 if test -n "$GCC"; then
107 # Add GCC-specific compiler options...
108 if test -z "$OPTIM"; then
109 if test "x$with_optim" = x; then
110 # Default to optimize-for-size and debug
113 OPTIM="$with_optim $OPTIM"
117 # Generate position-independent code as needed...
118 if test $PICFLAG = 1 -a $uname != AIX; then
122 # The -fstack-protector option is available with some versions of
123 # GCC and adds "stack canaries" which detect when the return address
124 # has been overwritten, preventing many types of exploit attacks.
125 AC_MSG_CHECKING(if GCC supports -fstack-protector)
127 CFLAGS="$CFLAGS -fstack-protector"
129 OPTIM="$OPTIM -fstack-protector"
134 # The -fPIE option is available with some versions of GCC and adds
135 # randomization of addresses, which avoids another class of exploits
136 # that depend on a fixed address for common functions.
137 AC_MSG_CHECKING(if GCC supports -fPIE)
139 CFLAGS="$CFLAGS -fPIE"
143 PIEFLAGS="-fPIE -Wl,-pie"
146 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 # Additional warning options for development testing...
158 if test -d .svn; then
159 OPTIM="-Wshadow -Werror $OPTIM"
160 PHPOPTIONS="-Wno-shadow"
162 AC_MSG_CHECKING(if GCC supports -Wno-tautological-compare)
164 CFLAGS="$CFLAGS -Werror -Wno-tautological-compare"
166 [OPTIM="$OPTIM -Wno-tautological-compare"
175 # -D_FORTIFY_SOURCE=2 adds additional object size
176 # checking, basically wrapping all string functions
177 # with buffer-limited ones. Not strictly needed for
178 # CUPS since we already use buffer-limited calls, but
179 # this will catch any additions that are broken.
180 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
184 if test "x$enable_32bit" = xyes; then
185 # Build 32-bit libraries, 64-bit base...
186 if test -z "$with_arch32flags"; then
187 ARCH32FLAGS="-milp32"
189 ARCH32FLAGS="$with_arch32flags"
192 if test -z "$with_archflags"; then
193 if test -z "$with_arch64flags"; then
196 ARCHFLAGS="$with_arch64flags"
201 if test "x$enable_64bit" = xyes; then
202 # Build 64-bit libraries, 32-bit base...
203 if test -z "$with_arch64flags"; then
206 ARCH64FLAGS="$with_arch64flags"
209 if test -z "$with_archflags"; then
210 if test -z "$with_arch32flags"; then
213 ARCHFLAGS="$with_arch32flags"
220 if test "x$enable_32bit" = xyes; then
221 # Build 32-bit libraries, 64-bit base...
222 if test -z "$with_arch32flags"; then
223 ARCH32FLAGS="-n32 -mips3"
225 ARCH32FLAGS="$with_arch32flags"
228 if test -z "$with_archflags"; then
229 if test -z "$with_arch64flags"; then
230 ARCHFLAGS="-64 -mips4"
232 ARCHFLAGS="$with_arch64flags"
237 if test "x$enable_64bit" = xyes; then
238 # Build 64-bit libraries, 32-bit base...
239 if test -z "$with_arch64flags"; then
240 ARCH64FLAGS="-64 -mips4"
242 ARCH64FLAGS="$with_arch64flags"
245 if test -z "$with_archflags"; then
246 if test -z "$with_arch32flags"; then
247 ARCHFLAGS="-n32 -mips3"
249 ARCHFLAGS="$with_arch32flags"
256 # The -z relro option is provided by the Linux linker command to
257 # make relocatable data read-only.
258 if test x$enable_relro = xyes; then
259 RELROFLAGS="-Wl,-z,relro"
262 if test "x$enable_32bit" = xyes; then
263 # Build 32-bit libraries, 64-bit base...
264 if test -z "$with_arch32flags"; then
267 ARCH32FLAGS="$with_arch32flags"
270 if test -z "$with_archflags"; then
271 if test -z "$with_arch64flags"; then
274 ARCHFLAGS="$with_arch64flags"
279 if test "x$enable_64bit" = xyes; then
280 # Build 64-bit libraries, 32-bit base...
281 if test -z "$with_arch64flags"; then
284 ARCH64FLAGS="$with_arch64flags"
287 if test -z "$with_archflags"; then
288 if test -z "$with_arch32flags"; then
291 ARCHFLAGS="$with_arch32flags"
298 if test "x$enable_32bit" = xyes; then
299 # Build 32-bit libraries, 64-bit base...
300 if test -z "$with_arch32flags"; then
303 ARCH32FLAGS="$with_arch32flags"
306 if test -z "$with_archflags"; then
307 if test -z "$with_arch64flags"; then
310 ARCHFLAGS="$with_arch64flags"
315 if test "x$enable_64bit" = xyes; then
316 # Build 64-bit libraries, 32-bit base...
317 if test -z "$with_arch64flags"; then
320 ARCH64FLAGS="$with_arch64flags"
323 if test -z "$with_archflags"; then
324 if test -z "$with_arch32flags"; then
327 ARCHFLAGS="$with_arch32flags"
334 # Add vendor-specific compiler options...
337 if test -z "$OPTIM"; then
338 if test "x$with_optim" = x; then
339 OPTIM="-O2 -qmaxmem=6000"
341 OPTIM="$with_optim $OPTIM"
346 if test -z "$OPTIM"; then
347 if test "x$with_optim" = x; then
350 OPTIM="$with_optim $OPTIM"
356 if test $PICFLAG = 1; then
360 if test "x$enable_32bit" = xyes; then
361 # Build 32-bit libraries, 64-bit base...
362 if test -z "$with_arch32flags"; then
365 ARCH32FLAGS="$with_arch32flags"
368 if test -z "$with_archflags"; then
369 if test -z "$with_arch64flags"; then
372 ARCHFLAGS="$with_arch64flags"
377 if test "x$enable_64bit" = xyes; then
378 # Build 64-bit libraries, 32-bit base...
379 if test -z "$with_arch64flags"; then
382 ARCH64FLAGS="$with_arch64flags"
385 if test -z "$with_archflags"; then
386 if test -z "$with_arch32flags"; then
389 ARCHFLAGS="$with_arch32flags"
395 if test -z "$OPTIM"; then
396 if test "x$with_optim" = x; then
399 OPTIM="$with_optim $OPTIM"
403 if test "x$with_optim" = x; then
404 OPTIM="-fullwarn -woff 1183,1209,1349,1506,3201 $OPTIM"
407 if test "x$enable_32bit" = xyes; then
408 # Build 32-bit libraries, 64-bit base...
409 if test -z "$with_arch32flags"; then
410 ARCH32FLAGS="-n32 -mips3"
412 ARCH32FLAGS="$with_arch32flags"
415 if test -z "$with_archflags"; then
416 if test -z "$with_arch64flags"; then
417 ARCHFLAGS="-64 -mips4"
419 ARCHFLAGS="$with_arch64flags"
424 if test "x$enable_64bit" = xyes; then
425 # Build 64-bit libraries, 32-bit base...
426 if test -z "$with_arch64flags"; then
427 ARCH64FLAGS="-64 -mips4"
429 ARCH64FLAGS="$with_arch64flags"
432 if test -z "$with_archflags"; then
433 if test -z "$with_arch32flags"; then
434 ARCHFLAGS="-n32 -mips3"
436 ARCHFLAGS="$with_arch32flags"
442 # Tru64 UNIX aka Digital UNIX aka OSF/1
443 if test -z "$OPTIM"; then
444 if test "x$with_optim" = x; then
453 if test -z "$OPTIM"; then
454 if test "x$with_optim" = x; then
457 OPTIM="$with_optim $OPTIM"
461 if test $PICFLAG = 1; then
465 if test "x$enable_32bit" = xyes; then
466 # Compiling on a Solaris system, build 64-bit
467 # binaries with separate 32-bit libraries...
468 ARCH32FLAGS="-xarch=generic"
470 if test "x$with_optim" = x; then
471 # Suppress all of Sun's questionable
472 # warning messages, and default to
473 # 64-bit compiles of everything else...
477 if test -z "$with_archflags"; then
478 if test -z "$with_arch64flags"; then
479 ARCHFLAGS="-xarch=generic64"
481 ARCHFLAGS="$with_arch64flags"
485 if test "x$enable_64bit" = xyes; then
486 # Build 64-bit libraries...
487 ARCH64FLAGS="-xarch=generic64"
490 if test "x$with_optim" = x; then
491 # Suppress all of Sun's questionable
492 # warning messages, and default to
493 # 32-bit compiles of everything else...
497 if test -z "$with_archflags"; then
498 if test -z "$with_arch32flags"; then
499 ARCHFLAGS="-xarch=generic"
501 ARCHFLAGS="$with_arch32flags"
508 if test -z "$OPTIM"; then
509 if test "x$with_optim" = x; then
512 OPTIM="$with_optim $OPTIM"
516 if test $PICFLAG = 1; then
521 # Running some other operating system; inform the user they
522 # should contribute the necessary options to
523 # cups-support@cups.org...
524 echo "Building CUPS with default compiler optimizations; contact"
525 echo "cups-bugs@cups.org with uname and compiler options needed"
526 echo "for your platform, or set the CFLAGS and LDFLAGS environment"
527 echo "variables before running configure."
532 # Add general compiler options per platform...
535 # HP-UX 10.20 (at least) needs this definition to get the
537 OPTIM="$OPTIM -D_XOPEN_SOURCE_EXTENDED"
539 # HP-UX 11.00 (at least) needs this definition to get the
540 # u_short type used by the IP headers...
541 OPTIM="$OPTIM -D_INCLUDE_HPUX_SOURCE"
543 # HP-UX 11.23 (at least) needs this definition to get the
544 # IPv6 header to work...
545 OPTIM="$OPTIM -D_HPUX_SOURCE"
549 # glibc 2.8 and higher breaks peer credentials unless you
550 # define _GNU_SOURCE...
551 OPTIM="$OPTIM -D_GNU_SOURCE"
555 # Tru64 UNIX aka Digital UNIX aka OSF/1 need to be told
556 # to be POSIX-compliant...
557 OPTIM="$OPTIM -D_XOPEN_SOURCE=500 -D_XOPEN_SOURCE_EXTENDED -D_OSF_SOURCE"
562 dnl End of "$Id: cups-compiler.m4 9981 2011-09-09 17:28:58Z mike $".