2 dnl "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $"
4 dnl Compiler stuff for the Common UNIX Printing System (CUPS).
6 dnl Copyright 2007-2009 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 -pie 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 -pie)
139 CFLAGS="$CFLAGS -pie -fPIE"
141 PIEFLAGS="-pie -fPIE"
146 if test "x$with_optim" = x; then
147 # Add useful warning options for tracking down problems...
148 OPTIM="-Wall -Wno-format-y2k $OPTIM"
149 # Additional warning options for development testing...
150 if test -d .svn; then
151 OPTIM="-Wshadow -Wunused $OPTIM"
152 CFLAGS="-Werror-implicit-function-declaration $CFLAGS"
153 PHPOPTIONS="-Wno-shadow"
159 # -D_FORTIFY_SOURCE=2 adds additional object size
160 # checking, basically wrapping all string functions
161 # with buffer-limited ones. Not strictly needed for
162 # CUPS since we already use buffer-limited calls, but
163 # this will catch any additions that are broken.
164 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
166 if test x$enable_pie = xyes; then
167 # GCC 4 on Mac OS X needs -Wl,-pie as well
168 LDFLAGS="$LDFLAGS -Wl,-pie"
173 if test "x$enable_32bit" = xyes; then
174 # Build 32-bit libraries, 64-bit base...
175 if test -z "$with_arch32flags"; then
176 ARCH32FLAGS="-milp32"
178 ARCH32FLAGS="$with_arch32flags"
181 if test -z "$with_archflags"; then
182 if test -z "$with_arch64flags"; then
185 ARCHFLAGS="$with_arch64flags"
190 if test "x$enable_64bit" = xyes; then
191 # Build 64-bit libraries, 32-bit base...
192 if test -z "$with_arch64flags"; then
195 ARCH64FLAGS="$with_arch64flags"
198 if test -z "$with_archflags"; then
199 if test -z "$with_arch32flags"; then
202 ARCHFLAGS="$with_arch32flags"
209 if test "x$enable_32bit" = xyes; then
210 # Build 32-bit libraries, 64-bit base...
211 if test -z "$with_arch32flags"; then
212 ARCH32FLAGS="-n32 -mips3"
214 ARCH32FLAGS="$with_arch32flags"
217 if test -z "$with_archflags"; then
218 if test -z "$with_arch64flags"; then
219 ARCHFLAGS="-64 -mips4"
221 ARCHFLAGS="$with_arch64flags"
226 if test "x$enable_64bit" = xyes; then
227 # Build 64-bit libraries, 32-bit base...
228 if test -z "$with_arch64flags"; then
229 ARCH64FLAGS="-64 -mips4"
231 ARCH64FLAGS="$with_arch64flags"
234 if test -z "$with_archflags"; then
235 if test -z "$with_arch32flags"; then
236 ARCHFLAGS="-n32 -mips3"
238 ARCHFLAGS="$with_arch32flags"
245 # The -z relro option is provided by the Linux linker command to
246 # make relocatable data read-only.
247 if test x$enable_relro = xyes; then
248 RELROFLAGS="-Wl,-z,relro"
251 if test "x$enable_32bit" = xyes; then
252 # Build 32-bit libraries, 64-bit base...
253 if test -z "$with_arch32flags"; then
256 ARCH32FLAGS="$with_arch32flags"
259 if test -z "$with_archflags"; then
260 if test -z "$with_arch64flags"; then
263 ARCHFLAGS="$with_arch64flags"
268 if test "x$enable_64bit" = xyes; then
269 # Build 64-bit libraries, 32-bit base...
270 if test -z "$with_arch64flags"; then
273 ARCH64FLAGS="$with_arch64flags"
276 if test -z "$with_archflags"; then
277 if test -z "$with_arch32flags"; then
280 ARCHFLAGS="$with_arch32flags"
287 if test "x$enable_32bit" = xyes; then
288 # Build 32-bit libraries, 64-bit base...
289 if test -z "$with_arch32flags"; then
292 ARCH32FLAGS="$with_arch32flags"
295 if test -z "$with_archflags"; then
296 if test -z "$with_arch64flags"; then
299 ARCHFLAGS="$with_arch64flags"
304 if test "x$enable_64bit" = xyes; then
305 # Build 64-bit libraries, 32-bit base...
306 if test -z "$with_arch64flags"; then
309 ARCH64FLAGS="$with_arch64flags"
312 if test -z "$with_archflags"; then
313 if test -z "$with_arch32flags"; then
316 ARCHFLAGS="$with_arch32flags"
323 # Add vendor-specific compiler options...
326 if test -z "$OPTIM"; then
327 if test "x$with_optim" = x; then
328 OPTIM="-O2 -qmaxmem=6000"
330 OPTIM="$with_optim $OPTIM"
335 if test -z "$OPTIM"; then
336 if test "x$with_optim" = x; then
339 OPTIM="$with_optim $OPTIM"
345 if test $PICFLAG = 1; then
349 if test "x$enable_32bit" = xyes; then
350 # Build 32-bit libraries, 64-bit base...
351 if test -z "$with_arch32flags"; then
354 ARCH32FLAGS="$with_arch32flags"
357 if test -z "$with_archflags"; then
358 if test -z "$with_arch64flags"; then
361 ARCHFLAGS="$with_arch64flags"
366 if test "x$enable_64bit" = xyes; then
367 # Build 64-bit libraries, 32-bit base...
368 if test -z "$with_arch64flags"; then
371 ARCH64FLAGS="$with_arch64flags"
374 if test -z "$with_archflags"; then
375 if test -z "$with_arch32flags"; then
378 ARCHFLAGS="$with_arch32flags"
384 if test -z "$OPTIM"; then
385 if test "x$with_optim" = x; then
388 OPTIM="$with_optim $OPTIM"
392 if test "x$with_optim" = x; then
393 OPTIM="-fullwarn -woff 1183,1209,1349,1506,3201 $OPTIM"
396 if test "x$enable_32bit" = xyes; then
397 # Build 32-bit libraries, 64-bit base...
398 if test -z "$with_arch32flags"; then
399 ARCH32FLAGS="-n32 -mips3"
401 ARCH32FLAGS="$with_arch32flags"
404 if test -z "$with_archflags"; then
405 if test -z "$with_arch64flags"; then
406 ARCHFLAGS="-64 -mips4"
408 ARCHFLAGS="$with_arch64flags"
413 if test "x$enable_64bit" = xyes; then
414 # Build 64-bit libraries, 32-bit base...
415 if test -z "$with_arch64flags"; then
416 ARCH64FLAGS="-64 -mips4"
418 ARCH64FLAGS="$with_arch64flags"
421 if test -z "$with_archflags"; then
422 if test -z "$with_arch32flags"; then
423 ARCHFLAGS="-n32 -mips3"
425 ARCHFLAGS="$with_arch32flags"
431 # Tru64 UNIX aka Digital UNIX aka OSF/1
432 if test -z "$OPTIM"; then
433 if test "x$with_optim" = x; then
442 if test -z "$OPTIM"; then
443 if test "x$with_optim" = x; then
446 OPTIM="$with_optim $OPTIM"
450 if test $PICFLAG = 1; then
454 if test "x$enable_32bit" = xyes; then
455 # Compiling on a Solaris system, build 64-bit
456 # binaries with separate 32-bit libraries...
457 ARCH32FLAGS="-xarch=generic"
459 if test "x$with_optim" = x; then
460 # Suppress all of Sun's questionable
461 # warning messages, and default to
462 # 64-bit compiles of everything else...
466 if test -z "$with_archflags"; then
467 if test -z "$with_arch64flags"; then
468 ARCHFLAGS="-xarch=generic64"
470 ARCHFLAGS="$with_arch64flags"
474 if test "x$enable_64bit" = xyes; then
475 # Build 64-bit libraries...
476 ARCH64FLAGS="-xarch=generic64"
479 if test "x$with_optim" = x; then
480 # Suppress all of Sun's questionable
481 # warning messages, and default to
482 # 32-bit compiles of everything else...
486 if test -z "$with_archflags"; then
487 if test -z "$with_arch32flags"; then
488 ARCHFLAGS="-xarch=generic"
490 ARCHFLAGS="$with_arch32flags"
497 if test -z "$OPTIM"; then
498 if test "x$with_optim" = x; then
501 OPTIM="$with_optim $OPTIM"
505 if test $PICFLAG = 1; then
510 # Running some other operating system; inform the user they
511 # should contribute the necessary options to
512 # cups-support@cups.org...
513 echo "Building CUPS with default compiler optimizations; contact"
514 echo "cups-bugs@cups.org with uname and compiler options needed"
515 echo "for your platform, or set the CFLAGS and LDFLAGS environment"
516 echo "variables before running configure."
521 # Add general compiler options per platform...
524 # HP-UX 10.20 (at least) needs this definition to get the
526 OPTIM="$OPTIM -D_XOPEN_SOURCE_EXTENDED"
528 # HP-UX 11.00 (at least) needs this definition to get the
529 # u_short type used by the IP headers...
530 OPTIM="$OPTIM -D_INCLUDE_HPUX_SOURCE"
532 # HP-UX 11.23 (at least) needs this definition to get the
533 # IPv6 header to work...
534 OPTIM="$OPTIM -D_HPUX_SOURCE"
538 # glibc 2.8 and higher breaks peer credentials unless you
539 # define _GNU_SOURCE...
540 OPTIM="$OPTIM -D_GNU_SOURCE"
544 # Tru64 UNIX aka Digital UNIX aka OSF/1 need to be told
545 # to be POSIX-compliant...
546 OPTIM="$OPTIM -D_XOPEN_SOURCE=500 -D_XOPEN_SOURCE_EXTENDED -D_OSF_SOURCE"
551 dnl End of "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $".