2 dnl "$Id: cups-compiler.m4 6975 2007-09-18 20:37:09Z mike $"
4 dnl Compiler stuff for the Common UNIX Printing System (CUPS).
6 dnl Copyright 2007-2008 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
21 AC_ARG_WITH(optim, [ --with-optim="flags" set optimization flags ])
22 AC_ARG_ENABLE(debug, [ --enable-debug turn on debugging, default=no],
23 [if test x$enable_debug = xyes; then
27 dnl Setup general architecture flags...
28 AC_ARG_WITH(archflags, [ --with-archflags="flags"
29 set default architecture flags ])
30 AC_ARG_WITH(ldarchflags, [ --with-ldarchflags="flags"
31 set default program architecture flags ])
33 if test -z "$with_archflags"; then
36 ARCHFLAGS="$with_archflags"
39 if test -z "$with_ldarchflags"; then
40 if test "$uname" = Darwin; then
41 # Only create 32-bit programs by default
42 LDARCHFLAGS="`echo $ARCHFLAGS | sed -e '1,$s/-arch x86_64//' -e '1,$s/-arch ppc64//'`"
44 LDARCHFLAGS="$ARCHFLAGS"
47 LDARCHFLAGS="$with_archflags"
53 dnl Setup support for separate 32/64-bit library generation...
54 AC_ARG_WITH(arch32flags, [ --with-arch32flags="flags"
55 specifies 32-bit architecture flags])
59 AC_ARG_WITH(arch64flags, [ --with-arch64flags="flags"
60 specifies 64-bit architecture flags])
64 dnl Read-only data/program support on Linux...
65 AC_ARG_ENABLE(relro, [ --enable-relro use GCC relro option, default=no])
67 dnl Update compiler options...
68 CXXLIBS="${CXXLIBS:=}"
77 LIBCUPSORDER="libcups.order"
78 AC_ARG_WITH(libcupsorder, [ --with-libcupsorder libcups secorder file, default=libcups.order],
79 if test -f "$withval"; then
80 LIBCUPSORDER="$withval"
82 AC_SUBST(LIBCUPSORDER)
84 LIBCUPSIMAGEORDER="libcupsimage.order"
85 AC_ARG_WITH(libcupsimageorder, [ --with-libcupsimagesorder
86 libcupsimage secorder file, default=libcupsimage.order],
87 if test -f "$withval"; then
88 LIBCUPSIMAGEORDER="$withval"
90 AC_SUBST(LIBCUPSIMAGEORDER)
92 if test -n "$GCC"; then
93 # Add GCC-specific compiler options...
94 if test -z "$OPTIM"; then
95 if test "x$with_optim" = x; then
96 # Default to optimize-for-size and debug
99 OPTIM="$with_optim $OPTIM"
103 # Generate position-independent code as needed...
104 if test $PICFLAG = 1 -a $uname != AIX; then
108 # The -fstack-protector option is available with some versions of
109 # GCC and adds "stack canaries" which detect when the return address
110 # has been overwritten, preventing many types of exploit attacks.
111 AC_MSG_CHECKING(if GCC supports -fstack-protector)
113 CFLAGS="$CFLAGS -fstack-protector"
115 OPTIM="$OPTIM -fstack-protector"
120 # The -pie option is available with some versions of GCC and adds
121 # randomization of addresses, which avoids another class of exploits
122 # that depend on a fixed address for common functions.
123 AC_MSG_CHECKING(if GCC supports -pie)
125 CFLAGS="$CFLAGS -pie -fPIE"
127 PIEFLAGS="-pie -fPIE"
132 if test "x$with_optim" = x; then
133 # Add useful warning options for tracking down problems...
134 OPTIM="-Wall -Wno-format-y2k $OPTIM"
135 # Additional warning options for development testing...
136 if test -d .svn; then
137 OPTIM="-Wshadow -Wunused $OPTIM"
143 # -D_FORTIFY_SOURCE=2 adds additional object size
144 # checking, basically wrapping all string functions
145 # with buffer-limited ones. Not strictly needed for
146 # CUPS since we already use buffer-limited calls, but
147 # this will catch any additions that are broken.
148 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
150 if test x$enable_pie = xyes; then
151 # GCC 4 on Mac OS X needs -Wl,-pie as well
152 LDFLAGS="$LDFLAGS -Wl,-pie"
157 if test "x$enable_32bit" = xyes; then
158 # Build 32-bit libraries, 64-bit base...
159 if test -z "$with_arch32flags"; then
160 ARCH32FLAGS="-milp32"
162 ARCH32FLAGS="$with_arch32flags"
165 if test -z "$with_archflags"; then
166 if test -z "$with_arch64flags"; then
169 ARCHFLAGS="$with_arch64flags"
174 if test "x$enable_64bit" = xyes; then
175 # Build 64-bit libraries, 32-bit base...
176 if test -z "$with_arch64flags"; then
179 ARCH64FLAGS="$with_arch64flags"
182 if test -z "$with_archflags"; then
183 if test -z "$with_arch32flags"; then
186 ARCHFLAGS="$with_arch32flags"
193 if test "x$enable_32bit" = xyes; then
194 # Build 32-bit libraries, 64-bit base...
195 if test -z "$with_arch32flags"; then
196 ARCH32FLAGS="-n32 -mips3"
198 ARCH32FLAGS="$with_arch32flags"
201 if test -z "$with_archflags"; then
202 if test -z "$with_arch64flags"; then
203 ARCHFLAGS="-64 -mips4"
205 ARCHFLAGS="$with_arch64flags"
210 if test "x$enable_64bit" = xyes; then
211 # Build 64-bit libraries, 32-bit base...
212 if test -z "$with_arch64flags"; then
213 ARCH64FLAGS="-64 -mips4"
215 ARCH64FLAGS="$with_arch64flags"
218 if test -z "$with_archflags"; then
219 if test -z "$with_arch32flags"; then
220 ARCHFLAGS="-n32 -mips3"
222 ARCHFLAGS="$with_arch32flags"
229 # The -z relro option is provided by the Linux linker command to
230 # make relocatable data read-only.
231 if test x$enable_relro = xyes; then
232 RELROFLAGS="-Wl,-z,relro"
235 if test "x$enable_32bit" = xyes; then
236 # Build 32-bit libraries, 64-bit base...
237 if test -z "$with_arch32flags"; then
240 ARCH32FLAGS="$with_arch32flags"
243 if test -z "$with_archflags"; then
244 if test -z "$with_arch64flags"; then
247 ARCHFLAGS="$with_arch64flags"
252 if test "x$enable_64bit" = xyes; then
253 # Build 64-bit libraries, 32-bit base...
254 if test -z "$with_arch64flags"; then
257 ARCH64FLAGS="$with_arch64flags"
260 if test -z "$with_archflags"; then
261 if test -z "$with_arch32flags"; then
264 ARCHFLAGS="$with_arch32flags"
271 if test "x$enable_32bit" = xyes; then
272 # Build 32-bit libraries, 64-bit base...
273 if test -z "$with_arch32flags"; then
276 ARCH32FLAGS="$with_arch32flags"
279 if test -z "$with_archflags"; then
280 if test -z "$with_arch64flags"; then
283 ARCHFLAGS="$with_arch64flags"
288 if test "x$enable_64bit" = xyes; then
289 # Build 64-bit libraries, 32-bit base...
290 if test -z "$with_arch64flags"; then
293 ARCH64FLAGS="$with_arch64flags"
296 if test -z "$with_archflags"; then
297 if test -z "$with_arch32flags"; then
300 ARCHFLAGS="$with_arch32flags"
307 # Add vendor-specific compiler options...
310 if test -z "$OPTIM"; then
311 if test "x$with_optim" = x; then
312 OPTIM="-O2 -qmaxmem=6000"
314 OPTIM="$with_optim $OPTIM"
319 if test -z "$OPTIM"; then
320 if test "x$with_optim" = x; then
323 OPTIM="$with_optim $OPTIM"
329 if test $PICFLAG = 1; then
333 if test "x$enable_32bit" = xyes; then
334 # Build 32-bit libraries, 64-bit base...
335 if test -z "$with_arch32flags"; then
338 ARCH32FLAGS="$with_arch32flags"
341 if test -z "$with_archflags"; then
342 if test -z "$with_arch64flags"; then
345 ARCHFLAGS="$with_arch64flags"
350 if test "x$enable_64bit" = xyes; then
351 # Build 64-bit libraries, 32-bit base...
352 if test -z "$with_arch64flags"; then
355 ARCH64FLAGS="$with_arch64flags"
358 if test -z "$with_archflags"; then
359 if test -z "$with_arch32flags"; then
362 ARCHFLAGS="$with_arch32flags"
368 if test -z "$OPTIM"; then
369 if test "x$with_optim" = x; then
372 OPTIM="$with_optim $OPTIM"
376 if test "x$with_optim" = x; then
377 OPTIM="-fullwarn -woff 1183,1209,1349,1506,3201 $OPTIM"
380 if test "x$enable_32bit" = xyes; then
381 # Build 32-bit libraries, 64-bit base...
382 if test -z "$with_arch32flags"; then
383 ARCH32FLAGS="-n32 -mips3"
385 ARCH32FLAGS="$with_arch32flags"
388 if test -z "$with_archflags"; then
389 if test -z "$with_arch64flags"; then
390 ARCHFLAGS="-64 -mips4"
392 ARCHFLAGS="$with_arch64flags"
397 if test "x$enable_64bit" = xyes; then
398 # Build 64-bit libraries, 32-bit base...
399 if test -z "$with_arch64flags"; then
400 ARCH64FLAGS="-64 -mips4"
402 ARCH64FLAGS="$with_arch64flags"
405 if test -z "$with_archflags"; then
406 if test -z "$with_arch32flags"; then
407 ARCHFLAGS="-n32 -mips3"
409 ARCHFLAGS="$with_arch32flags"
415 # Tru64 UNIX aka Digital UNIX aka OSF/1
416 if test -z "$OPTIM"; then
417 if test "x$with_optim" = x; then
426 if test -z "$OPTIM"; then
427 if test "x$with_optim" = x; then
430 OPTIM="$with_optim $OPTIM"
434 if test $PICFLAG = 1; then
438 if test "x$enable_32bit" = xyes; then
439 # Compiling on a Solaris system, build 64-bit
440 # binaries with separate 32-bit libraries...
441 ARCH32FLAGS="-xarch=generic"
443 if test "x$with_optim" = x; then
444 # Suppress all of Sun's questionable
445 # warning messages, and default to
446 # 64-bit compiles of everything else...
450 if test -z "$with_archflags"; then
451 if test -z "$with_arch64flags"; then
452 ARCHFLAGS="-xarch=generic64"
454 ARCHFLAGS="$with_arch64flags"
458 if test "x$enable_64bit" = xyes; then
459 # Build 64-bit libraries...
460 ARCH64FLAGS="-xarch=generic64"
463 if test "x$with_optim" = x; then
464 # Suppress all of Sun's questionable
465 # warning messages, and default to
466 # 32-bit compiles of everything else...
470 if test -z "$with_archflags"; then
471 if test -z "$with_arch32flags"; then
472 ARCHFLAGS="-xarch=generic"
474 ARCHFLAGS="$with_arch32flags"
481 if test -z "$OPTIM"; then
482 if test "x$with_optim" = x; then
485 OPTIM="$with_optim $OPTIM"
489 if test $PICFLAG = 1; then
494 # Running some other operating system; inform the user they
495 # should contribute the necessary options to
496 # cups-support@cups.org...
497 echo "Building CUPS with default compiler optimizations; contact"
498 echo "cups-bugs@cups.org with uname and compiler options needed"
499 echo "for your platform, or set the CFLAGS and LDFLAGS environment"
500 echo "variables before running configure."
505 # Add general compiler options per platform...
508 # HP-UX 10.20 (at least) needs this definition to get the
510 OPTIM="$OPTIM -D_XOPEN_SOURCE_EXTENDED"
512 # HP-UX 11.00 (at least) needs this definition to get the
513 # u_short type used by the IP headers...
514 OPTIM="$OPTIM -D_INCLUDE_HPUX_SOURCE"
516 # HP-UX 11.23 (at least) needs this definition to get the
517 # IPv6 header to work...
518 OPTIM="$OPTIM -D_HPUX_SOURCE"
522 # Tru64 UNIX aka Digital UNIX aka OSF/1 need to be told
523 # to be POSIX-compliant...
524 OPTIM="$OPTIM -D_XOPEN_SOURCE=500 -D_XOPEN_SOURCE_EXTENDED -D_OSF_SOURCE"
529 dnl End of "$Id: cups-compiler.m4 6975 2007-09-18 20:37:09Z mike $".