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:=}"
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 $OPTIM"
160 CFLAGS="-Werror-implicit-function-declaration $CFLAGS"
161 PHPOPTIONS="-Wno-shadow"
163 AC_MSG_CHECKING(if GCC supports -Wno-tautological-compare)
165 CFLAGS="$CFLAGS -Wno-tautological-compare"
167 [OPTIM="$OPTIM -Wno-tautological-compare"
176 # -D_FORTIFY_SOURCE=2 adds additional object size
177 # checking, basically wrapping all string functions
178 # with buffer-limited ones. Not strictly needed for
179 # CUPS since we already use buffer-limited calls, but
180 # this will catch any additions that are broken.
181 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
185 if test "x$enable_32bit" = xyes; then
186 # Build 32-bit libraries, 64-bit base...
187 if test -z "$with_arch32flags"; then
188 ARCH32FLAGS="-milp32"
190 ARCH32FLAGS="$with_arch32flags"
193 if test -z "$with_archflags"; then
194 if test -z "$with_arch64flags"; then
197 ARCHFLAGS="$with_arch64flags"
202 if test "x$enable_64bit" = xyes; then
203 # Build 64-bit libraries, 32-bit base...
204 if test -z "$with_arch64flags"; then
207 ARCH64FLAGS="$with_arch64flags"
210 if test -z "$with_archflags"; then
211 if test -z "$with_arch32flags"; then
214 ARCHFLAGS="$with_arch32flags"
221 if test "x$enable_32bit" = xyes; then
222 # Build 32-bit libraries, 64-bit base...
223 if test -z "$with_arch32flags"; then
224 ARCH32FLAGS="-n32 -mips3"
226 ARCH32FLAGS="$with_arch32flags"
229 if test -z "$with_archflags"; then
230 if test -z "$with_arch64flags"; then
231 ARCHFLAGS="-64 -mips4"
233 ARCHFLAGS="$with_arch64flags"
238 if test "x$enable_64bit" = xyes; then
239 # Build 64-bit libraries, 32-bit base...
240 if test -z "$with_arch64flags"; then
241 ARCH64FLAGS="-64 -mips4"
243 ARCH64FLAGS="$with_arch64flags"
246 if test -z "$with_archflags"; then
247 if test -z "$with_arch32flags"; then
248 ARCHFLAGS="-n32 -mips3"
250 ARCHFLAGS="$with_arch32flags"
257 # The -z relro option is provided by the Linux linker command to
258 # make relocatable data read-only.
259 if test x$enable_relro = xyes; then
260 RELROFLAGS="-Wl,-z,relro"
263 if test "x$enable_32bit" = xyes; then
264 # Build 32-bit libraries, 64-bit base...
265 if test -z "$with_arch32flags"; then
268 ARCH32FLAGS="$with_arch32flags"
271 if test -z "$with_archflags"; then
272 if test -z "$with_arch64flags"; then
275 ARCHFLAGS="$with_arch64flags"
280 if test "x$enable_64bit" = xyes; then
281 # Build 64-bit libraries, 32-bit base...
282 if test -z "$with_arch64flags"; then
285 ARCH64FLAGS="$with_arch64flags"
288 if test -z "$with_archflags"; then
289 if test -z "$with_arch32flags"; then
292 ARCHFLAGS="$with_arch32flags"
299 if test "x$enable_32bit" = xyes; then
300 # Build 32-bit libraries, 64-bit base...
301 if test -z "$with_arch32flags"; then
304 ARCH32FLAGS="$with_arch32flags"
307 if test -z "$with_archflags"; then
308 if test -z "$with_arch64flags"; then
311 ARCHFLAGS="$with_arch64flags"
316 if test "x$enable_64bit" = xyes; then
317 # Build 64-bit libraries, 32-bit base...
318 if test -z "$with_arch64flags"; then
321 ARCH64FLAGS="$with_arch64flags"
324 if test -z "$with_archflags"; then
325 if test -z "$with_arch32flags"; then
328 ARCHFLAGS="$with_arch32flags"
335 # Add vendor-specific compiler options...
338 if test -z "$OPTIM"; then
339 if test "x$with_optim" = x; then
340 OPTIM="-O2 -qmaxmem=6000"
342 OPTIM="$with_optim $OPTIM"
347 if test -z "$OPTIM"; then
348 if test "x$with_optim" = x; then
351 OPTIM="$with_optim $OPTIM"
357 if test $PICFLAG = 1; then
361 if test "x$enable_32bit" = xyes; then
362 # Build 32-bit libraries, 64-bit base...
363 if test -z "$with_arch32flags"; then
366 ARCH32FLAGS="$with_arch32flags"
369 if test -z "$with_archflags"; then
370 if test -z "$with_arch64flags"; then
373 ARCHFLAGS="$with_arch64flags"
378 if test "x$enable_64bit" = xyes; then
379 # Build 64-bit libraries, 32-bit base...
380 if test -z "$with_arch64flags"; then
383 ARCH64FLAGS="$with_arch64flags"
386 if test -z "$with_archflags"; then
387 if test -z "$with_arch32flags"; then
390 ARCHFLAGS="$with_arch32flags"
396 if test -z "$OPTIM"; then
397 if test "x$with_optim" = x; then
400 OPTIM="$with_optim $OPTIM"
404 if test "x$with_optim" = x; then
405 OPTIM="-fullwarn -woff 1183,1209,1349,1506,3201 $OPTIM"
408 if test "x$enable_32bit" = xyes; then
409 # Build 32-bit libraries, 64-bit base...
410 if test -z "$with_arch32flags"; then
411 ARCH32FLAGS="-n32 -mips3"
413 ARCH32FLAGS="$with_arch32flags"
416 if test -z "$with_archflags"; then
417 if test -z "$with_arch64flags"; then
418 ARCHFLAGS="-64 -mips4"
420 ARCHFLAGS="$with_arch64flags"
425 if test "x$enable_64bit" = xyes; then
426 # Build 64-bit libraries, 32-bit base...
427 if test -z "$with_arch64flags"; then
428 ARCH64FLAGS="-64 -mips4"
430 ARCH64FLAGS="$with_arch64flags"
433 if test -z "$with_archflags"; then
434 if test -z "$with_arch32flags"; then
435 ARCHFLAGS="-n32 -mips3"
437 ARCHFLAGS="$with_arch32flags"
443 # Tru64 UNIX aka Digital UNIX aka OSF/1
444 if test -z "$OPTIM"; then
445 if test "x$with_optim" = x; then
454 if test -z "$OPTIM"; then
455 if test "x$with_optim" = x; then
458 OPTIM="$with_optim $OPTIM"
462 if test $PICFLAG = 1; then
466 if test "x$enable_32bit" = xyes; then
467 # Compiling on a Solaris system, build 64-bit
468 # binaries with separate 32-bit libraries...
469 ARCH32FLAGS="-xarch=generic"
471 if test "x$with_optim" = x; then
472 # Suppress all of Sun's questionable
473 # warning messages, and default to
474 # 64-bit compiles of everything else...
478 if test -z "$with_archflags"; then
479 if test -z "$with_arch64flags"; then
480 ARCHFLAGS="-xarch=generic64"
482 ARCHFLAGS="$with_arch64flags"
486 if test "x$enable_64bit" = xyes; then
487 # Build 64-bit libraries...
488 ARCH64FLAGS="-xarch=generic64"
491 if test "x$with_optim" = x; then
492 # Suppress all of Sun's questionable
493 # warning messages, and default to
494 # 32-bit compiles of everything else...
498 if test -z "$with_archflags"; then
499 if test -z "$with_arch32flags"; then
500 ARCHFLAGS="-xarch=generic"
502 ARCHFLAGS="$with_arch32flags"
509 if test -z "$OPTIM"; then
510 if test "x$with_optim" = x; then
513 OPTIM="$with_optim $OPTIM"
517 if test $PICFLAG = 1; then
522 # Running some other operating system; inform the user they
523 # should contribute the necessary options to
524 # cups-support@cups.org...
525 echo "Building CUPS with default compiler optimizations; contact"
526 echo "cups-bugs@cups.org with uname and compiler options needed"
527 echo "for your platform, or set the CFLAGS and LDFLAGS environment"
528 echo "variables before running configure."
533 # Add general compiler options per platform...
536 # HP-UX 10.20 (at least) needs this definition to get the
538 OPTIM="$OPTIM -D_XOPEN_SOURCE_EXTENDED"
540 # HP-UX 11.00 (at least) needs this definition to get the
541 # u_short type used by the IP headers...
542 OPTIM="$OPTIM -D_INCLUDE_HPUX_SOURCE"
544 # HP-UX 11.23 (at least) needs this definition to get the
545 # IPv6 header to work...
546 OPTIM="$OPTIM -D_HPUX_SOURCE"
550 # glibc 2.8 and higher breaks peer credentials unless you
551 # define _GNU_SOURCE...
552 OPTIM="$OPTIM -D_GNU_SOURCE"
556 # Tru64 UNIX aka Digital UNIX aka OSF/1 need to be told
557 # to be POSIX-compliant...
558 OPTIM="$OPTIM -D_XOPEN_SOURCE=500 -D_XOPEN_SOURCE_EXTENDED -D_OSF_SOURCE"
563 dnl End of "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $".