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"
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 set default architecture flags ])
57 AC_ARG_WITH(ldarchflags, [ --with-ldarchflags set program architecture flags ])
59 if test -z "$with_archflags"; then
62 ARCHFLAGS="$with_archflags"
65 if test -z "$with_ldarchflags"; then
66 if test "$uname" = Darwin; then
67 # Only create 32-bit programs by default
68 LDARCHFLAGS="`echo $ARCHFLAGS | sed -e '1,$s/-arch x86_64//' -e '1,$s/-arch ppc64//'`"
70 LDARCHFLAGS="$ARCHFLAGS"
73 LDARCHFLAGS="$with_ldarchflags"
79 dnl Setup support for separate 32/64-bit library generation...
80 AC_ARG_WITH(arch32flags, [ --with-arch32flags set 32-bit architecture flags])
84 AC_ARG_WITH(arch64flags, [ --with-arch64flags set 64-bit architecture flags])
88 dnl Read-only data/program support on Linux...
89 AC_ARG_ENABLE(relro, [ --enable-relro build with the GCC relro option])
91 dnl Update compiler options...
92 CXXLIBS="${CXXLIBS:=}"
101 LIBCUPSORDER="libcups.order"
102 AC_ARG_WITH(libcupsorder, [ --with-libcupsorder set libcups secorder file, default=libcups.order],
103 if test -f "$withval"; then
104 LIBCUPSORDER="$withval"
106 AC_SUBST(LIBCUPSORDER)
108 LIBCUPSIMAGEORDER="libcupsimage.order"
109 AC_ARG_WITH(libcupsimageorder, [ --with-libcupsimagesorder
110 set libcupsimage secorder file, default=libcupsimage.order],
111 if test -f "$withval"; then
112 LIBCUPSIMAGEORDER="$withval"
114 AC_SUBST(LIBCUPSIMAGEORDER)
119 if test -n "$GCC"; then
120 # Add GCC-specific compiler options...
121 if test -z "$OPTIM"; then
122 if test "x$with_optim" = x; then
123 # Default to optimize-for-size and debug
126 OPTIM="$with_optim $OPTIM"
130 # Generate position-independent code as needed...
131 if test $PICFLAG = 1 -a $uname != AIX; then
135 # The -fstack-protector option is available with some versions of
136 # GCC and adds "stack canaries" which detect when the return address
137 # has been overwritten, preventing many types of exploit attacks.
138 AC_MSG_CHECKING(if GCC supports -fstack-protector)
140 CFLAGS="$CFLAGS -fstack-protector"
142 OPTIM="$OPTIM -fstack-protector"
147 # The -pie option is available with some versions of GCC and adds
148 # randomization of addresses, which avoids another class of exploits
149 # that depend on a fixed address for common functions.
150 AC_MSG_CHECKING(if GCC supports -pie)
152 CFLAGS="$CFLAGS -pie -fPIE"
154 PIEFLAGS="-pie -fPIE"
159 if test "x$with_optim" = x; then
160 # Add useful warning options for tracking down problems...
161 OPTIM="-Wall -Wno-format-y2k $OPTIM"
162 # Additional warning options for development testing...
163 if test -d .svn; then
164 OPTIM="-Wshadow -Wunused $OPTIM"
165 CFLAGS="-Werror-implicit-function-declaration $CFLAGS"
166 PHPOPTIONS="-Wno-shadow"
172 # -D_FORTIFY_SOURCE=2 adds additional object size
173 # checking, basically wrapping all string functions
174 # with buffer-limited ones. Not strictly needed for
175 # CUPS since we already use buffer-limited calls, but
176 # this will catch any additions that are broken.
177 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
179 if test x$enable_pie = xyes; then
180 # GCC 4 on Mac OS X needs -Wl,-pie as well
181 LDFLAGS="$LDFLAGS -Wl,-pie"
186 if test "x$enable_32bit" = xyes; then
187 # Build 32-bit libraries, 64-bit base...
188 if test -z "$with_arch32flags"; then
189 ARCH32FLAGS="-milp32"
191 ARCH32FLAGS="$with_arch32flags"
194 if test -z "$with_archflags"; then
195 if test -z "$with_arch64flags"; then
198 ARCHFLAGS="$with_arch64flags"
203 if test "x$enable_64bit" = xyes; then
204 # Build 64-bit libraries, 32-bit base...
205 if test -z "$with_arch64flags"; then
208 ARCH64FLAGS="$with_arch64flags"
211 if test -z "$with_archflags"; then
212 if test -z "$with_arch32flags"; then
215 ARCHFLAGS="$with_arch32flags"
222 if test "x$enable_32bit" = xyes; then
223 # Build 32-bit libraries, 64-bit base...
224 if test -z "$with_arch32flags"; then
225 ARCH32FLAGS="-n32 -mips3"
227 ARCH32FLAGS="$with_arch32flags"
230 if test -z "$with_archflags"; then
231 if test -z "$with_arch64flags"; then
232 ARCHFLAGS="-64 -mips4"
234 ARCHFLAGS="$with_arch64flags"
239 if test "x$enable_64bit" = xyes; then
240 # Build 64-bit libraries, 32-bit base...
241 if test -z "$with_arch64flags"; then
242 ARCH64FLAGS="-64 -mips4"
244 ARCH64FLAGS="$with_arch64flags"
247 if test -z "$with_archflags"; then
248 if test -z "$with_arch32flags"; then
249 ARCHFLAGS="-n32 -mips3"
251 ARCHFLAGS="$with_arch32flags"
258 # The -z relro option is provided by the Linux linker command to
259 # make relocatable data read-only.
260 if test x$enable_relro = xyes; then
261 RELROFLAGS="-Wl,-z,relro"
264 if test "x$enable_32bit" = xyes; then
265 # Build 32-bit libraries, 64-bit base...
266 if test -z "$with_arch32flags"; then
269 ARCH32FLAGS="$with_arch32flags"
272 if test -z "$with_archflags"; then
273 if test -z "$with_arch64flags"; then
276 ARCHFLAGS="$with_arch64flags"
281 if test "x$enable_64bit" = xyes; then
282 # Build 64-bit libraries, 32-bit base...
283 if test -z "$with_arch64flags"; then
286 ARCH64FLAGS="$with_arch64flags"
289 if test -z "$with_archflags"; then
290 if test -z "$with_arch32flags"; then
293 ARCHFLAGS="$with_arch32flags"
300 if test "x$enable_32bit" = xyes; then
301 # Build 32-bit libraries, 64-bit base...
302 if test -z "$with_arch32flags"; then
305 ARCH32FLAGS="$with_arch32flags"
308 if test -z "$with_archflags"; then
309 if test -z "$with_arch64flags"; then
312 ARCHFLAGS="$with_arch64flags"
317 if test "x$enable_64bit" = xyes; then
318 # Build 64-bit libraries, 32-bit base...
319 if test -z "$with_arch64flags"; then
322 ARCH64FLAGS="$with_arch64flags"
325 if test -z "$with_archflags"; then
326 if test -z "$with_arch32flags"; then
329 ARCHFLAGS="$with_arch32flags"
336 # Add vendor-specific compiler options...
339 if test -z "$OPTIM"; then
340 if test "x$with_optim" = x; then
341 OPTIM="-O2 -qmaxmem=6000"
343 OPTIM="$with_optim $OPTIM"
348 if test -z "$OPTIM"; then
349 if test "x$with_optim" = x; then
352 OPTIM="$with_optim $OPTIM"
358 if test $PICFLAG = 1; then
362 if test "x$enable_32bit" = xyes; then
363 # Build 32-bit libraries, 64-bit base...
364 if test -z "$with_arch32flags"; then
367 ARCH32FLAGS="$with_arch32flags"
370 if test -z "$with_archflags"; then
371 if test -z "$with_arch64flags"; then
374 ARCHFLAGS="$with_arch64flags"
379 if test "x$enable_64bit" = xyes; then
380 # Build 64-bit libraries, 32-bit base...
381 if test -z "$with_arch64flags"; then
384 ARCH64FLAGS="$with_arch64flags"
387 if test -z "$with_archflags"; then
388 if test -z "$with_arch32flags"; then
391 ARCHFLAGS="$with_arch32flags"
397 if test -z "$OPTIM"; then
398 if test "x$with_optim" = x; then
401 OPTIM="$with_optim $OPTIM"
405 if test "x$with_optim" = x; then
406 OPTIM="-fullwarn -woff 1183,1209,1349,1506,3201 $OPTIM"
409 if test "x$enable_32bit" = xyes; then
410 # Build 32-bit libraries, 64-bit base...
411 if test -z "$with_arch32flags"; then
412 ARCH32FLAGS="-n32 -mips3"
414 ARCH32FLAGS="$with_arch32flags"
417 if test -z "$with_archflags"; then
418 if test -z "$with_arch64flags"; then
419 ARCHFLAGS="-64 -mips4"
421 ARCHFLAGS="$with_arch64flags"
426 if test "x$enable_64bit" = xyes; then
427 # Build 64-bit libraries, 32-bit base...
428 if test -z "$with_arch64flags"; then
429 ARCH64FLAGS="-64 -mips4"
431 ARCH64FLAGS="$with_arch64flags"
434 if test -z "$with_archflags"; then
435 if test -z "$with_arch32flags"; then
436 ARCHFLAGS="-n32 -mips3"
438 ARCHFLAGS="$with_arch32flags"
444 # Tru64 UNIX aka Digital UNIX aka OSF/1
445 if test -z "$OPTIM"; then
446 if test "x$with_optim" = x; then
455 if test -z "$OPTIM"; then
456 if test "x$with_optim" = x; then
459 OPTIM="$with_optim $OPTIM"
463 if test $PICFLAG = 1; then
467 if test "x$enable_32bit" = xyes; then
468 # Compiling on a Solaris system, build 64-bit
469 # binaries with separate 32-bit libraries...
470 ARCH32FLAGS="-xarch=generic"
472 if test "x$with_optim" = x; then
473 # Suppress all of Sun's questionable
474 # warning messages, and default to
475 # 64-bit compiles of everything else...
479 if test -z "$with_archflags"; then
480 if test -z "$with_arch64flags"; then
481 ARCHFLAGS="-xarch=generic64"
483 ARCHFLAGS="$with_arch64flags"
487 if test "x$enable_64bit" = xyes; then
488 # Build 64-bit libraries...
489 ARCH64FLAGS="-xarch=generic64"
492 if test "x$with_optim" = x; then
493 # Suppress all of Sun's questionable
494 # warning messages, and default to
495 # 32-bit compiles of everything else...
499 if test -z "$with_archflags"; then
500 if test -z "$with_arch32flags"; then
501 ARCHFLAGS="-xarch=generic"
503 ARCHFLAGS="$with_arch32flags"
510 if test -z "$OPTIM"; then
511 if test "x$with_optim" = x; then
514 OPTIM="$with_optim $OPTIM"
518 if test $PICFLAG = 1; then
523 # Running some other operating system; inform the user they
524 # should contribute the necessary options to
525 # cups-support@cups.org...
526 echo "Building CUPS with default compiler optimizations; contact"
527 echo "cups-bugs@cups.org with uname and compiler options needed"
528 echo "for your platform, or set the CFLAGS and LDFLAGS environment"
529 echo "variables before running configure."
534 # Add general compiler options per platform...
537 # HP-UX 10.20 (at least) needs this definition to get the
539 OPTIM="$OPTIM -D_XOPEN_SOURCE_EXTENDED"
541 # HP-UX 11.00 (at least) needs this definition to get the
542 # u_short type used by the IP headers...
543 OPTIM="$OPTIM -D_INCLUDE_HPUX_SOURCE"
545 # HP-UX 11.23 (at least) needs this definition to get the
546 # IPv6 header to work...
547 OPTIM="$OPTIM -D_HPUX_SOURCE"
551 # glibc 2.8 and higher breaks peer credentials unless you
552 # define _GNU_SOURCE...
553 OPTIM="$OPTIM -D_GNU_SOURCE"
557 # Tru64 UNIX aka Digital UNIX aka OSF/1 need to be told
558 # to be POSIX-compliant...
559 OPTIM="$OPTIM -D_XOPEN_SOURCE=500 -D_XOPEN_SOURCE_EXTENDED -D_OSF_SOURCE"
564 dnl End of "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $".