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="flags" set optimization flags ])
24 AC_ARG_ENABLE(debug, [ --enable-debug turn on debugging, default=no])
25 AC_ARG_ENABLE(debug_guards, [ --enable-debug-guards turn on debug guards, default=no])
26 AC_ARG_ENABLE(debug_printfs, [ --enable-debug-printfs turn on debug printfs, default=no])
27 AC_ARG_ENABLE(unit_tests, [ --enable-unit-tests turn on unit tests, default=no])
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"
41 dnl Debug guards use an extra 4 bytes for some structures like strings in the
42 dnl string pool, so provide a separate option for that
43 if test x$enable_debug_guards = xyes; then
44 CFLAGS="$CFLAGS -DDEBUG_GUARDS"
47 dnl Unit tests take up time during a compile...
48 if test x$enable_unit_tests = xyes; then
55 dnl Setup general architecture flags...
56 AC_ARG_WITH(archflags, [ --with-archflags="flags"
57 set default architecture flags ])
58 AC_ARG_WITH(ldarchflags, [ --with-ldarchflags="flags"
59 set default 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="flags"
83 specifies 32-bit architecture flags])
87 AC_ARG_WITH(arch64flags, [ --with-arch64flags="flags"
88 specifies 64-bit architecture flags])
92 dnl Read-only data/program support on Linux...
93 AC_ARG_ENABLE(relro, [ --enable-relro use GCC relro option, default=no])
95 dnl Update compiler options...
96 CXXLIBS="${CXXLIBS:=}"
105 LIBCUPSORDER="libcups.order"
106 AC_ARG_WITH(libcupsorder, [ --with-libcupsorder libcups secorder file, default=libcups.order],
107 if test -f "$withval"; then
108 LIBCUPSORDER="$withval"
110 AC_SUBST(LIBCUPSORDER)
112 LIBCUPSIMAGEORDER="libcupsimage.order"
113 AC_ARG_WITH(libcupsimageorder, [ --with-libcupsimagesorder
114 libcupsimage secorder file, default=libcupsimage.order],
115 if test -f "$withval"; then
116 LIBCUPSIMAGEORDER="$withval"
118 AC_SUBST(LIBCUPSIMAGEORDER)
123 if test -n "$GCC"; then
124 # Add GCC-specific compiler options...
125 if test -z "$OPTIM"; then
126 if test "x$with_optim" = x; then
127 # Default to optimize-for-size and debug
130 OPTIM="$with_optim $OPTIM"
134 # Generate position-independent code as needed...
135 if test $PICFLAG = 1 -a $uname != AIX; then
139 # The -fstack-protector option is available with some versions of
140 # GCC and adds "stack canaries" which detect when the return address
141 # has been overwritten, preventing many types of exploit attacks.
142 AC_MSG_CHECKING(if GCC supports -fstack-protector)
144 CFLAGS="$CFLAGS -fstack-protector"
146 OPTIM="$OPTIM -fstack-protector"
151 # The -pie option is available with some versions of GCC and adds
152 # randomization of addresses, which avoids another class of exploits
153 # that depend on a fixed address for common functions.
154 AC_MSG_CHECKING(if GCC supports -pie)
156 CFLAGS="$CFLAGS -pie -fPIE"
158 PIEFLAGS="-pie -fPIE"
163 if test "x$with_optim" = x; then
164 # Add useful warning options for tracking down problems...
165 OPTIM="-Wall -Wno-format-y2k $OPTIM"
166 # Additional warning options for development testing...
167 if test -d .svn; then
168 OPTIM="-Wshadow -Wunused $OPTIM"
169 CFLAGS="-Werror-implicit-function-declaration $CFLAGS"
170 PHPOPTIONS="-Wno-shadow"
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"
183 if test x$enable_pie = xyes; then
184 # GCC 4 on Mac OS X needs -Wl,-pie as well
185 LDFLAGS="$LDFLAGS -Wl,-pie"
190 if test "x$enable_32bit" = xyes; then
191 # Build 32-bit libraries, 64-bit base...
192 if test -z "$with_arch32flags"; then
193 ARCH32FLAGS="-milp32"
195 ARCH32FLAGS="$with_arch32flags"
198 if test -z "$with_archflags"; then
199 if test -z "$with_arch64flags"; then
202 ARCHFLAGS="$with_arch64flags"
207 if test "x$enable_64bit" = xyes; then
208 # Build 64-bit libraries, 32-bit base...
209 if test -z "$with_arch64flags"; then
212 ARCH64FLAGS="$with_arch64flags"
215 if test -z "$with_archflags"; then
216 if test -z "$with_arch32flags"; then
219 ARCHFLAGS="$with_arch32flags"
226 if test "x$enable_32bit" = xyes; then
227 # Build 32-bit libraries, 64-bit base...
228 if test -z "$with_arch32flags"; then
229 ARCH32FLAGS="-n32 -mips3"
231 ARCH32FLAGS="$with_arch32flags"
234 if test -z "$with_archflags"; then
235 if test -z "$with_arch64flags"; then
236 ARCHFLAGS="-64 -mips4"
238 ARCHFLAGS="$with_arch64flags"
243 if test "x$enable_64bit" = xyes; then
244 # Build 64-bit libraries, 32-bit base...
245 if test -z "$with_arch64flags"; then
246 ARCH64FLAGS="-64 -mips4"
248 ARCH64FLAGS="$with_arch64flags"
251 if test -z "$with_archflags"; then
252 if test -z "$with_arch32flags"; then
253 ARCHFLAGS="-n32 -mips3"
255 ARCHFLAGS="$with_arch32flags"
262 # The -z relro option is provided by the Linux linker command to
263 # make relocatable data read-only.
264 if test x$enable_relro = xyes; then
265 RELROFLAGS="-Wl,-z,relro"
268 if test "x$enable_32bit" = xyes; then
269 # Build 32-bit libraries, 64-bit base...
270 if test -z "$with_arch32flags"; then
273 ARCH32FLAGS="$with_arch32flags"
276 if test -z "$with_archflags"; then
277 if test -z "$with_arch64flags"; then
280 ARCHFLAGS="$with_arch64flags"
285 if test "x$enable_64bit" = xyes; then
286 # Build 64-bit libraries, 32-bit base...
287 if test -z "$with_arch64flags"; then
290 ARCH64FLAGS="$with_arch64flags"
293 if test -z "$with_archflags"; then
294 if test -z "$with_arch32flags"; then
297 ARCHFLAGS="$with_arch32flags"
304 if test "x$enable_32bit" = xyes; then
305 # Build 32-bit libraries, 64-bit base...
306 if test -z "$with_arch32flags"; then
309 ARCH32FLAGS="$with_arch32flags"
312 if test -z "$with_archflags"; then
313 if test -z "$with_arch64flags"; then
316 ARCHFLAGS="$with_arch64flags"
321 if test "x$enable_64bit" = xyes; then
322 # Build 64-bit libraries, 32-bit base...
323 if test -z "$with_arch64flags"; then
326 ARCH64FLAGS="$with_arch64flags"
329 if test -z "$with_archflags"; then
330 if test -z "$with_arch32flags"; then
333 ARCHFLAGS="$with_arch32flags"
340 # Add vendor-specific compiler options...
343 if test -z "$OPTIM"; then
344 if test "x$with_optim" = x; then
345 OPTIM="-O2 -qmaxmem=6000"
347 OPTIM="$with_optim $OPTIM"
352 if test -z "$OPTIM"; then
353 if test "x$with_optim" = x; then
356 OPTIM="$with_optim $OPTIM"
362 if test $PICFLAG = 1; then
366 if test "x$enable_32bit" = xyes; then
367 # Build 32-bit libraries, 64-bit base...
368 if test -z "$with_arch32flags"; then
371 ARCH32FLAGS="$with_arch32flags"
374 if test -z "$with_archflags"; then
375 if test -z "$with_arch64flags"; then
378 ARCHFLAGS="$with_arch64flags"
383 if test "x$enable_64bit" = xyes; then
384 # Build 64-bit libraries, 32-bit base...
385 if test -z "$with_arch64flags"; then
388 ARCH64FLAGS="$with_arch64flags"
391 if test -z "$with_archflags"; then
392 if test -z "$with_arch32flags"; then
395 ARCHFLAGS="$with_arch32flags"
401 if test -z "$OPTIM"; then
402 if test "x$with_optim" = x; then
405 OPTIM="$with_optim $OPTIM"
409 if test "x$with_optim" = x; then
410 OPTIM="-fullwarn -woff 1183,1209,1349,1506,3201 $OPTIM"
413 if test "x$enable_32bit" = xyes; then
414 # Build 32-bit libraries, 64-bit base...
415 if test -z "$with_arch32flags"; then
416 ARCH32FLAGS="-n32 -mips3"
418 ARCH32FLAGS="$with_arch32flags"
421 if test -z "$with_archflags"; then
422 if test -z "$with_arch64flags"; then
423 ARCHFLAGS="-64 -mips4"
425 ARCHFLAGS="$with_arch64flags"
430 if test "x$enable_64bit" = xyes; then
431 # Build 64-bit libraries, 32-bit base...
432 if test -z "$with_arch64flags"; then
433 ARCH64FLAGS="-64 -mips4"
435 ARCH64FLAGS="$with_arch64flags"
438 if test -z "$with_archflags"; then
439 if test -z "$with_arch32flags"; then
440 ARCHFLAGS="-n32 -mips3"
442 ARCHFLAGS="$with_arch32flags"
448 # Tru64 UNIX aka Digital UNIX aka OSF/1
449 if test -z "$OPTIM"; then
450 if test "x$with_optim" = x; then
459 if test -z "$OPTIM"; then
460 if test "x$with_optim" = x; then
463 OPTIM="$with_optim $OPTIM"
467 if test $PICFLAG = 1; then
471 if test "x$enable_32bit" = xyes; then
472 # Compiling on a Solaris system, build 64-bit
473 # binaries with separate 32-bit libraries...
474 ARCH32FLAGS="-xarch=generic"
476 if test "x$with_optim" = x; then
477 # Suppress all of Sun's questionable
478 # warning messages, and default to
479 # 64-bit compiles of everything else...
483 if test -z "$with_archflags"; then
484 if test -z "$with_arch64flags"; then
485 ARCHFLAGS="-xarch=generic64"
487 ARCHFLAGS="$with_arch64flags"
491 if test "x$enable_64bit" = xyes; then
492 # Build 64-bit libraries...
493 ARCH64FLAGS="-xarch=generic64"
496 if test "x$with_optim" = x; then
497 # Suppress all of Sun's questionable
498 # warning messages, and default to
499 # 32-bit compiles of everything else...
503 if test -z "$with_archflags"; then
504 if test -z "$with_arch32flags"; then
505 ARCHFLAGS="-xarch=generic"
507 ARCHFLAGS="$with_arch32flags"
514 if test -z "$OPTIM"; then
515 if test "x$with_optim" = x; then
518 OPTIM="$with_optim $OPTIM"
522 if test $PICFLAG = 1; then
527 # Running some other operating system; inform the user they
528 # should contribute the necessary options to
529 # cups-support@cups.org...
530 echo "Building CUPS with default compiler optimizations; contact"
531 echo "cups-bugs@cups.org with uname and compiler options needed"
532 echo "for your platform, or set the CFLAGS and LDFLAGS environment"
533 echo "variables before running configure."
538 # Add general compiler options per platform...
541 # HP-UX 10.20 (at least) needs this definition to get the
543 OPTIM="$OPTIM -D_XOPEN_SOURCE_EXTENDED"
545 # HP-UX 11.00 (at least) needs this definition to get the
546 # u_short type used by the IP headers...
547 OPTIM="$OPTIM -D_INCLUDE_HPUX_SOURCE"
549 # HP-UX 11.23 (at least) needs this definition to get the
550 # IPv6 header to work...
551 OPTIM="$OPTIM -D_HPUX_SOURCE"
555 # glibc 2.8 and higher breaks peer credentials unless you
556 # define _GNU_SOURCE...
557 OPTIM="$OPTIM -D_GNU_SOURCE"
561 # Tru64 UNIX aka Digital UNIX aka OSF/1 need to be told
562 # to be POSIX-compliant...
563 OPTIM="$OPTIM -D_XOPEN_SOURCE=500 -D_XOPEN_SOURCE_EXTENDED -D_OSF_SOURCE"
568 dnl End of "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $".