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:=}"
103 LIBCUPSORDER="libcups.order"
104 AC_ARG_WITH(libcupsorder, [ --with-libcupsorder set libcups secorder file, default=libcups.order],
105 if test -f "$withval"; then
106 LIBCUPSORDER="$withval"
108 AC_SUBST(LIBCUPSORDER)
110 LIBCUPSIMAGEORDER="libcupsimage.order"
111 AC_ARG_WITH(libcupsimageorder, [ --with-libcupsimagesorder
112 set libcupsimage secorder file, default=libcupsimage.order],
113 if test -f "$withval"; then
114 LIBCUPSIMAGEORDER="$withval"
116 AC_SUBST(LIBCUPSIMAGEORDER)
121 if test -n "$GCC"; then
122 # Add GCC-specific compiler options...
123 if test -z "$OPTIM"; then
124 if test "x$with_optim" = x; then
125 # Default to optimize-for-size and debug
128 OPTIM="$with_optim $OPTIM"
132 # Generate position-independent code as needed...
133 if test $PICFLAG = 1 -a $uname != AIX; then
137 # The -fstack-protector option is available with some versions of
138 # GCC and adds "stack canaries" which detect when the return address
139 # has been overwritten, preventing many types of exploit attacks.
140 AC_MSG_CHECKING(if GCC supports -fstack-protector)
142 CFLAGS="$CFLAGS -fstack-protector"
144 OPTIM="$OPTIM -fstack-protector"
149 # The -pie option is available with some versions of GCC and adds
150 # randomization of addresses, which avoids another class of exploits
151 # that depend on a fixed address for common functions.
152 AC_MSG_CHECKING(if GCC supports -pie)
154 CFLAGS="$CFLAGS -pie -fPIE"
156 PIEFLAGS="-pie -fPIE"
161 if test "x$with_optim" = x; then
162 # Add useful warning options for tracking down problems...
163 OPTIM="-Wall -Wno-format-y2k $OPTIM"
164 # Additional warning options for development testing...
165 if test -d .svn; then
166 OPTIM="-Wshadow -Wunused $OPTIM"
167 CFLAGS="-Werror-implicit-function-declaration $CFLAGS"
168 PHPOPTIONS="-Wno-shadow"
174 # -D_FORTIFY_SOURCE=2 adds additional object size
175 # checking, basically wrapping all string functions
176 # with buffer-limited ones. Not strictly needed for
177 # CUPS since we already use buffer-limited calls, but
178 # this will catch any additions that are broken.
179 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
181 if test x$enable_pie = xyes; then
182 # GCC 4 on Mac OS X needs -Wl,-pie as well
183 LDFLAGS="$LDFLAGS -Wl,-pie"
188 if test "x$enable_32bit" = xyes; then
189 # Build 32-bit libraries, 64-bit base...
190 if test -z "$with_arch32flags"; then
191 ARCH32FLAGS="-milp32"
193 ARCH32FLAGS="$with_arch32flags"
196 if test -z "$with_archflags"; then
197 if test -z "$with_arch64flags"; then
200 ARCHFLAGS="$with_arch64flags"
205 if test "x$enable_64bit" = xyes; then
206 # Build 64-bit libraries, 32-bit base...
207 if test -z "$with_arch64flags"; then
210 ARCH64FLAGS="$with_arch64flags"
213 if test -z "$with_archflags"; then
214 if test -z "$with_arch32flags"; then
217 ARCHFLAGS="$with_arch32flags"
224 if test "x$enable_32bit" = xyes; then
225 # Build 32-bit libraries, 64-bit base...
226 if test -z "$with_arch32flags"; then
227 ARCH32FLAGS="-n32 -mips3"
229 ARCH32FLAGS="$with_arch32flags"
232 if test -z "$with_archflags"; then
233 if test -z "$with_arch64flags"; then
234 ARCHFLAGS="-64 -mips4"
236 ARCHFLAGS="$with_arch64flags"
241 if test "x$enable_64bit" = xyes; then
242 # Build 64-bit libraries, 32-bit base...
243 if test -z "$with_arch64flags"; then
244 ARCH64FLAGS="-64 -mips4"
246 ARCH64FLAGS="$with_arch64flags"
249 if test -z "$with_archflags"; then
250 if test -z "$with_arch32flags"; then
251 ARCHFLAGS="-n32 -mips3"
253 ARCHFLAGS="$with_arch32flags"
260 # The -z relro option is provided by the Linux linker command to
261 # make relocatable data read-only.
262 if test x$enable_relro = xyes; then
263 RELROFLAGS="-Wl,-z,relro"
266 if test "x$enable_32bit" = xyes; then
267 # Build 32-bit libraries, 64-bit base...
268 if test -z "$with_arch32flags"; then
271 ARCH32FLAGS="$with_arch32flags"
274 if test -z "$with_archflags"; then
275 if test -z "$with_arch64flags"; then
278 ARCHFLAGS="$with_arch64flags"
283 if test "x$enable_64bit" = xyes; then
284 # Build 64-bit libraries, 32-bit base...
285 if test -z "$with_arch64flags"; then
288 ARCH64FLAGS="$with_arch64flags"
291 if test -z "$with_archflags"; then
292 if test -z "$with_arch32flags"; then
295 ARCHFLAGS="$with_arch32flags"
302 if test "x$enable_32bit" = xyes; then
303 # Build 32-bit libraries, 64-bit base...
304 if test -z "$with_arch32flags"; then
307 ARCH32FLAGS="$with_arch32flags"
310 if test -z "$with_archflags"; then
311 if test -z "$with_arch64flags"; then
314 ARCHFLAGS="$with_arch64flags"
319 if test "x$enable_64bit" = xyes; then
320 # Build 64-bit libraries, 32-bit base...
321 if test -z "$with_arch64flags"; then
324 ARCH64FLAGS="$with_arch64flags"
327 if test -z "$with_archflags"; then
328 if test -z "$with_arch32flags"; then
331 ARCHFLAGS="$with_arch32flags"
338 # Add vendor-specific compiler options...
341 if test -z "$OPTIM"; then
342 if test "x$with_optim" = x; then
343 OPTIM="-O2 -qmaxmem=6000"
345 OPTIM="$with_optim $OPTIM"
350 if test -z "$OPTIM"; then
351 if test "x$with_optim" = x; then
354 OPTIM="$with_optim $OPTIM"
360 if test $PICFLAG = 1; then
364 if test "x$enable_32bit" = xyes; then
365 # Build 32-bit libraries, 64-bit base...
366 if test -z "$with_arch32flags"; then
369 ARCH32FLAGS="$with_arch32flags"
372 if test -z "$with_archflags"; then
373 if test -z "$with_arch64flags"; then
376 ARCHFLAGS="$with_arch64flags"
381 if test "x$enable_64bit" = xyes; then
382 # Build 64-bit libraries, 32-bit base...
383 if test -z "$with_arch64flags"; then
386 ARCH64FLAGS="$with_arch64flags"
389 if test -z "$with_archflags"; then
390 if test -z "$with_arch32flags"; then
393 ARCHFLAGS="$with_arch32flags"
399 if test -z "$OPTIM"; then
400 if test "x$with_optim" = x; then
403 OPTIM="$with_optim $OPTIM"
407 if test "x$with_optim" = x; then
408 OPTIM="-fullwarn -woff 1183,1209,1349,1506,3201 $OPTIM"
411 if test "x$enable_32bit" = xyes; then
412 # Build 32-bit libraries, 64-bit base...
413 if test -z "$with_arch32flags"; then
414 ARCH32FLAGS="-n32 -mips3"
416 ARCH32FLAGS="$with_arch32flags"
419 if test -z "$with_archflags"; then
420 if test -z "$with_arch64flags"; then
421 ARCHFLAGS="-64 -mips4"
423 ARCHFLAGS="$with_arch64flags"
428 if test "x$enable_64bit" = xyes; then
429 # Build 64-bit libraries, 32-bit base...
430 if test -z "$with_arch64flags"; then
431 ARCH64FLAGS="-64 -mips4"
433 ARCH64FLAGS="$with_arch64flags"
436 if test -z "$with_archflags"; then
437 if test -z "$with_arch32flags"; then
438 ARCHFLAGS="-n32 -mips3"
440 ARCHFLAGS="$with_arch32flags"
446 # Tru64 UNIX aka Digital UNIX aka OSF/1
447 if test -z "$OPTIM"; then
448 if test "x$with_optim" = x; then
457 if test -z "$OPTIM"; then
458 if test "x$with_optim" = x; then
461 OPTIM="$with_optim $OPTIM"
465 if test $PICFLAG = 1; then
469 if test "x$enable_32bit" = xyes; then
470 # Compiling on a Solaris system, build 64-bit
471 # binaries with separate 32-bit libraries...
472 ARCH32FLAGS="-xarch=generic"
474 if test "x$with_optim" = x; then
475 # Suppress all of Sun's questionable
476 # warning messages, and default to
477 # 64-bit compiles of everything else...
481 if test -z "$with_archflags"; then
482 if test -z "$with_arch64flags"; then
483 ARCHFLAGS="-xarch=generic64"
485 ARCHFLAGS="$with_arch64flags"
489 if test "x$enable_64bit" = xyes; then
490 # Build 64-bit libraries...
491 ARCH64FLAGS="-xarch=generic64"
494 if test "x$with_optim" = x; then
495 # Suppress all of Sun's questionable
496 # warning messages, and default to
497 # 32-bit compiles of everything else...
501 if test -z "$with_archflags"; then
502 if test -z "$with_arch32flags"; then
503 ARCHFLAGS="-xarch=generic"
505 ARCHFLAGS="$with_arch32flags"
512 if test -z "$OPTIM"; then
513 if test "x$with_optim" = x; then
516 OPTIM="$with_optim $OPTIM"
520 if test $PICFLAG = 1; then
525 # Running some other operating system; inform the user they
526 # should contribute the necessary options to
527 # cups-support@cups.org...
528 echo "Building CUPS with default compiler optimizations; contact"
529 echo "cups-bugs@cups.org with uname and compiler options needed"
530 echo "for your platform, or set the CFLAGS and LDFLAGS environment"
531 echo "variables before running configure."
536 # Add general compiler options per platform...
539 # HP-UX 10.20 (at least) needs this definition to get the
541 OPTIM="$OPTIM -D_XOPEN_SOURCE_EXTENDED"
543 # HP-UX 11.00 (at least) needs this definition to get the
544 # u_short type used by the IP headers...
545 OPTIM="$OPTIM -D_INCLUDE_HPUX_SOURCE"
547 # HP-UX 11.23 (at least) needs this definition to get the
548 # IPv6 header to work...
549 OPTIM="$OPTIM -D_HPUX_SOURCE"
553 # glibc 2.8 and higher breaks peer credentials unless you
554 # define _GNU_SOURCE...
555 OPTIM="$OPTIM -D_GNU_SOURCE"
559 # Tru64 UNIX aka Digital UNIX aka OSF/1 need to be told
560 # to be POSIX-compliant...
561 OPTIM="$OPTIM -D_XOPEN_SOURCE=500 -D_XOPEN_SOURCE_EXTENDED -D_OSF_SOURCE"
566 dnl End of "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $".