]> git.ipfire.org Git - thirdparty/cups.git/blame - config-scripts/cups-compiler.m4
Merge changes from CUPS 1.6svn-r9968.
[thirdparty/cups.git] / config-scripts / cups-compiler.m4
CommitLineData
ef416fc2 1dnl
b19ccc9e 2dnl "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $"
ef416fc2 3dnl
22c9029b 4dnl Compiler stuff for CUPS.
ef416fc2 5dnl
22c9029b 6dnl Copyright 2007-2011 by Apple Inc.
f7deaa1a 7dnl Copyright 1997-2007 by Easy Software Products, all rights reserved.
ef416fc2 8dnl
9dnl These coded instructions, statements, and computer programs are the
bc44d920 10dnl property of Apple Inc. and are protected by Federal copyright
11dnl law. Distribution and use rights are outlined in the file "LICENSE.txt"
12dnl which should have been included with this file. If this file is
13dnl file is missing or damaged, see the license at "http://www.cups.org/".
ef416fc2 14dnl
15
16dnl Clear the debugging and non-shared library options unless the user asks
17dnl for them...
50fe7201 18INSTALL_STRIP=""
ef416fc2 19OPTIM=""
50fe7201 20AC_SUBST(INSTALL_STRIP)
ef416fc2 21AC_SUBST(OPTIM)
22
bf3816c7
MS
23AC_ARG_WITH(optim, [ --with-optim set optimization flags ])
24AC_ARG_ENABLE(debug, [ --enable-debug build with debugging symbols])
25AC_ARG_ENABLE(debug_guards, [ --enable-debug-guards build with memory allocation guards])
26AC_ARG_ENABLE(debug_printfs, [ --enable-debug-printfs build with CUPS_DEBUG_LOG support])
27AC_ARG_ENABLE(unit_tests, [ --enable-unit-tests build and run unit tests])
839a51c8
MS
28
29dnl For debugging, keep symbols, otherwise strip them...
30if test x$enable_debug = xyes; then
31 OPTIM="-g"
32else
33 INSTALL_STRIP="-s"
34fi
ef416fc2 35
5f64df29 36dnl Debug printfs can slow things down, so provide a separate option for that
52f6f666 37if test x$enable_debug_printfs = xyes; then
5f64df29 38 CFLAGS="$CFLAGS -DDEBUG"
94da7e34 39 CXXFLAGS="$CXXFLAGS -DDEBUG"
5f64df29
MS
40fi
41
745129be
MS
42dnl Debug guards use an extra 4 bytes for some structures like strings in the
43dnl string pool, so provide a separate option for that
44if test x$enable_debug_guards = xyes; then
45 CFLAGS="$CFLAGS -DDEBUG_GUARDS"
94da7e34 46 CXXFLAGS="$CXXFLAGS -DDEBUG_GUARDS"
745129be
MS
47fi
48
5f64df29
MS
49dnl Unit tests take up time during a compile...
50if test x$enable_unit_tests = xyes; then
51 UNITTESTS="unittests"
52else
53 UNITTESTS=""
54fi
55AC_SUBST(UNITTESTS)
56
ed486911 57dnl Setup general architecture flags...
bf3816c7
MS
58AC_ARG_WITH(archflags, [ --with-archflags set default architecture flags ])
59AC_ARG_WITH(ldarchflags, [ --with-ldarchflags set program architecture flags ])
ed486911 60
61if test -z "$with_archflags"; then
62 ARCHFLAGS=""
63else
64 ARCHFLAGS="$with_archflags"
a603edef
MS
65fi
66
67if test -z "$with_ldarchflags"; then
09a101d6 68 if test "$uname" = Darwin; then
a603edef 69 # Only create 32-bit programs by default
09a101d6 70 LDARCHFLAGS="`echo $ARCHFLAGS | sed -e '1,$s/-arch x86_64//' -e '1,$s/-arch ppc64//'`"
71 else
72 LDARCHFLAGS="$ARCHFLAGS"
73 fi
a603edef 74else
839a51c8 75 LDARCHFLAGS="$with_ldarchflags"
ed486911 76fi
77
78AC_SUBST(ARCHFLAGS)
09a101d6 79AC_SUBST(LDARCHFLAGS)
ed486911 80
e1d6a774 81dnl Setup support for separate 32/64-bit library generation...
bf3816c7 82AC_ARG_WITH(arch32flags, [ --with-arch32flags set 32-bit architecture flags])
e1d6a774 83ARCH32FLAGS=""
e1d6a774 84AC_SUBST(ARCH32FLAGS)
e1d6a774 85
bf3816c7 86AC_ARG_WITH(arch64flags, [ --with-arch64flags set 64-bit architecture flags])
e1d6a774 87ARCH64FLAGS=""
e1d6a774 88AC_SUBST(ARCH64FLAGS)
e1d6a774 89
f7deaa1a 90dnl Read-only data/program support on Linux...
bf3816c7 91AC_ARG_ENABLE(relro, [ --enable-relro build with the GCC relro option])
f7deaa1a 92
ef416fc2 93dnl Update compiler options...
ac884b6a
MS
94CXXLIBS="${CXXLIBS:=}"
95AC_SUBST(CXXLIBS)
96
a74454a7 97PIEFLAGS=""
98AC_SUBST(PIEFLAGS)
99
f7deaa1a 100RELROFLAGS=""
101AC_SUBST(RELROFLAGS)
102
ef416fc2 103if test -n "$GCC"; then
2abf387c 104 # Add GCC-specific compiler options...
ef416fc2 105 if test -z "$OPTIM"; then
106 if test "x$with_optim" = x; then
107 # Default to optimize-for-size and debug
108 OPTIM="-Os -g"
109 else
110 OPTIM="$with_optim $OPTIM"
111 fi
112 fi
113
a4924f6c 114 # Generate position-independent code as needed...
ef416fc2 115 if test $PICFLAG = 1 -a $uname != AIX; then
116 OPTIM="-fPIC $OPTIM"
117 fi
118
a4924f6c
MS
119 # The -fstack-protector option is available with some versions of
120 # GCC and adds "stack canaries" which detect when the return address
121 # has been overwritten, preventing many types of exploit attacks.
122 AC_MSG_CHECKING(if GCC supports -fstack-protector)
123 OLDCFLAGS="$CFLAGS"
124 CFLAGS="$CFLAGS -fstack-protector"
68b10830 125 AC_TRY_LINK(,,
a4924f6c
MS
126 OPTIM="$OPTIM -fstack-protector"
127 AC_MSG_RESULT(yes),
128 AC_MSG_RESULT(no))
129 CFLAGS="$OLDCFLAGS"
130
22c9029b 131 # The -fPIE option is available with some versions of GCC and adds
a4924f6c
MS
132 # randomization of addresses, which avoids another class of exploits
133 # that depend on a fixed address for common functions.
22c9029b 134 AC_MSG_CHECKING(if GCC supports -fPIE)
a4924f6c 135 OLDCFLAGS="$CFLAGS"
22c9029b 136 CFLAGS="$CFLAGS -fPIE"
a4924f6c 137 AC_TRY_COMPILE(,,
f228370c
MS
138 [case "$CC" in
139 *clang)
140 PIEFLAGS="-fPIE -Wl,-pie"
141 ;;
142 *)
143 PIEFLAGS="-fPIE -pie"
144 ;;
145 esac
22c9029b 146 AC_MSG_RESULT(yes)],
a4924f6c
MS
147 AC_MSG_RESULT(no))
148 CFLAGS="$OLDCFLAGS"
ef416fc2 149
150 if test "x$with_optim" = x; then
151 # Add useful warning options for tracking down problems...
321d8d57 152 OPTIM="-Wall -Wno-format-y2k -Wunused $OPTIM"
f228370c 153
a4924f6c 154 # Additional warning options for development testing...
d9bca400 155 if test -d .svn; then
85dda01c 156 OPTIM="-Wshadow -Werror $OPTIM"
f228370c
MS
157 else
158 AC_MSG_CHECKING(if GCC supports -Wno-tautological-compare)
159 OLDCFLAGS="$CFLAGS"
f99f3698 160 CFLAGS="$CFLAGS -Werror -Wno-tautological-compare"
f228370c
MS
161 AC_TRY_COMPILE(,,
162 [OPTIM="$OPTIM -Wno-tautological-compare"
163 AC_MSG_RESULT(yes)],
164 AC_MSG_RESULT(no))
165 CFLAGS="$OLDCFLAGS"
d9bca400 166 fi
ef416fc2 167 fi
e1d6a774 168
169 case "$uname" in
a4924f6c
MS
170 Darwin*)
171 # -D_FORTIFY_SOURCE=2 adds additional object size
172 # checking, basically wrapping all string functions
173 # with buffer-limited ones. Not strictly needed for
174 # CUPS since we already use buffer-limited calls, but
22c9029b 175 # this will catch any additions that are broken.
a4924f6c
MS
176 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
177 ;;
178
b86bc4cf 179 HP-UX*)
180 if test "x$enable_32bit" = xyes; then
181 # Build 32-bit libraries, 64-bit base...
182 if test -z "$with_arch32flags"; then
183 ARCH32FLAGS="-milp32"
184 else
185 ARCH32FLAGS="$with_arch32flags"
186 fi
187
188 if test -z "$with_archflags"; then
189 if test -z "$with_arch64flags"; then
190 ARCHFLAGS="-mlp64"
191 else
192 ARCHFLAGS="$with_arch64flags"
193 fi
194 fi
195 fi
196
197 if test "x$enable_64bit" = xyes; then
198 # Build 64-bit libraries, 32-bit base...
199 if test -z "$with_arch64flags"; then
200 ARCH64FLAGS="-mlp64"
201 else
202 ARCH64FLAGS="$with_arch64flags"
203 fi
204
205 if test -z "$with_archflags"; then
206 if test -z "$with_arch32flags"; then
207 ARCHFLAGS="-milp32"
208 else
209 ARCHFLAGS="$with_arch32flags"
210 fi
211 fi
212 fi
213 ;;
214
e1d6a774 215 IRIX)
216 if test "x$enable_32bit" = xyes; then
217 # Build 32-bit libraries, 64-bit base...
218 if test -z "$with_arch32flags"; then
219 ARCH32FLAGS="-n32 -mips3"
220 else
221 ARCH32FLAGS="$with_arch32flags"
222 fi
e1d6a774 223
224 if test -z "$with_archflags"; then
225 if test -z "$with_arch64flags"; then
226 ARCHFLAGS="-64 -mips4"
227 else
228 ARCHFLAGS="$with_arch64flags"
229 fi
e1d6a774 230 fi
231 fi
232
233 if test "x$enable_64bit" = xyes; then
234 # Build 64-bit libraries, 32-bit base...
235 if test -z "$with_arch64flags"; then
236 ARCH64FLAGS="-64 -mips4"
237 else
238 ARCH64FLAGS="$with_arch64flags"
239 fi
e1d6a774 240
241 if test -z "$with_archflags"; then
242 if test -z "$with_arch32flags"; then
243 ARCHFLAGS="-n32 -mips3"
244 else
245 ARCHFLAGS="$with_arch32flags"
246 fi
e1d6a774 247 fi
248 fi
249 ;;
250
251 Linux*)
a4924f6c
MS
252 # The -z relro option is provided by the Linux linker command to
253 # make relocatable data read-only.
254 if test x$enable_relro = xyes; then
255 RELROFLAGS="-Wl,-z,relro"
256 fi
257
e1d6a774 258 if test "x$enable_32bit" = xyes; then
259 # Build 32-bit libraries, 64-bit base...
260 if test -z "$with_arch32flags"; then
261 ARCH32FLAGS="-m32"
262 else
263 ARCH32FLAGS="$with_arch32flags"
264 fi
e1d6a774 265
266 if test -z "$with_archflags"; then
267 if test -z "$with_arch64flags"; then
268 ARCHFLAGS="-m64"
269 else
270 ARCHFLAGS="$with_arch64flags"
271 fi
e1d6a774 272 fi
273 fi
274
275 if test "x$enable_64bit" = xyes; then
276 # Build 64-bit libraries, 32-bit base...
277 if test -z "$with_arch64flags"; then
278 ARCH64FLAGS="-m64"
279 else
280 ARCH64FLAGS="$with_arch64flags"
281 fi
e1d6a774 282
283 if test -z "$with_archflags"; then
284 if test -z "$with_arch32flags"; then
285 ARCHFLAGS="-m32"
286 else
287 ARCHFLAGS="$with_arch32flags"
288 fi
e1d6a774 289 fi
290 fi
291 ;;
292
293 SunOS*)
294 if test "x$enable_32bit" = xyes; then
295 # Build 32-bit libraries, 64-bit base...
296 if test -z "$with_arch32flags"; then
297 ARCH32FLAGS="-m32"
298 else
299 ARCH32FLAGS="$with_arch32flags"
300 fi
e1d6a774 301
302 if test -z "$with_archflags"; then
303 if test -z "$with_arch64flags"; then
304 ARCHFLAGS="-m64"
305 else
306 ARCHFLAGS="$with_arch64flags"
307 fi
e1d6a774 308 fi
309 fi
310
311 if test "x$enable_64bit" = xyes; then
312 # Build 64-bit libraries, 32-bit base...
313 if test -z "$with_arch64flags"; then
314 ARCH64FLAGS="-m64"
315 else
316 ARCH64FLAGS="$with_arch64flags"
317 fi
e1d6a774 318
319 if test -z "$with_archflags"; then
320 if test -z "$with_arch32flags"; then
321 ARCHFLAGS="-m32"
322 else
323 ARCHFLAGS="$with_arch32flags"
324 fi
e1d6a774 325 fi
326 fi
327 ;;
328 esac
ef416fc2 329else
2abf387c 330 # Add vendor-specific compiler options...
ef416fc2 331 case $uname in
332 AIX*)
333 if test -z "$OPTIM"; then
334 if test "x$with_optim" = x; then
335 OPTIM="-O2 -qmaxmem=6000"
336 else
337 OPTIM="$with_optim $OPTIM"
338 fi
339 fi
340 ;;
341 HP-UX*)
342 if test -z "$OPTIM"; then
343 if test "x$with_optim" = x; then
344 OPTIM="+O2"
345 else
346 OPTIM="$with_optim $OPTIM"
347 fi
348 fi
349
350 CFLAGS="-Ae $CFLAGS"
351
ef416fc2 352 if test $PICFLAG = 1; then
353 OPTIM="+z $OPTIM"
354 fi
c277e2f8
MS
355
356 if test "x$enable_32bit" = xyes; then
357 # Build 32-bit libraries, 64-bit base...
358 if test -z "$with_arch32flags"; then
359 ARCH32FLAGS="+DD32"
360 else
361 ARCH32FLAGS="$with_arch32flags"
362 fi
363
364 if test -z "$with_archflags"; then
365 if test -z "$with_arch64flags"; then
366 ARCHFLAGS="+DD64"
367 else
368 ARCHFLAGS="$with_arch64flags"
369 fi
370 fi
371 fi
372
373 if test "x$enable_64bit" = xyes; then
374 # Build 64-bit libraries, 32-bit base...
375 if test -z "$with_arch64flags"; then
376 ARCH64FLAGS="+DD64"
377 else
378 ARCH64FLAGS="$with_arch64flags"
379 fi
380
381 if test -z "$with_archflags"; then
382 if test -z "$with_arch32flags"; then
383 ARCHFLAGS="+DD32"
384 else
385 ARCHFLAGS="$with_arch32flags"
386 fi
387 fi
388 fi
ef416fc2 389 ;;
390 IRIX)
391 if test -z "$OPTIM"; then
392 if test "x$with_optim" = x; then
393 OPTIM="-O2"
394 else
395 OPTIM="$with_optim $OPTIM"
396 fi
397 fi
398
e1d6a774 399 if test "x$with_optim" = x; then
400 OPTIM="-fullwarn -woff 1183,1209,1349,1506,3201 $OPTIM"
ef416fc2 401 fi
402
e1d6a774 403 if test "x$enable_32bit" = xyes; then
404 # Build 32-bit libraries, 64-bit base...
405 if test -z "$with_arch32flags"; then
406 ARCH32FLAGS="-n32 -mips3"
407 else
408 ARCH32FLAGS="$with_arch32flags"
409 fi
e1d6a774 410
411 if test -z "$with_archflags"; then
412 if test -z "$with_arch64flags"; then
413 ARCHFLAGS="-64 -mips4"
414 else
415 ARCHFLAGS="$with_arch64flags"
416 fi
e1d6a774 417 fi
418 fi
419
420 if test "x$enable_64bit" = xyes; then
421 # Build 64-bit libraries, 32-bit base...
422 if test -z "$with_arch64flags"; then
423 ARCH64FLAGS="-64 -mips4"
424 else
425 ARCH64FLAGS="$with_arch64flags"
426 fi
e1d6a774 427
428 if test -z "$with_archflags"; then
429 if test -z "$with_arch32flags"; then
430 ARCHFLAGS="-n32 -mips3"
431 else
432 ARCHFLAGS="$with_arch32flags"
433 fi
ef416fc2 434 fi
435 fi
436 ;;
2abf387c 437 OSF*)
438 # Tru64 UNIX aka Digital UNIX aka OSF/1
439 if test -z "$OPTIM"; then
440 if test "x$with_optim" = x; then
441 OPTIM="-O"
442 else
443 OPTIM="$with_optim"
444 fi
445 fi
446 ;;
ef416fc2 447 SunOS*)
448 # Solaris
449 if test -z "$OPTIM"; then
450 if test "x$with_optim" = x; then
ed486911 451 OPTIM="-xO2"
ef416fc2 452 else
453 OPTIM="$with_optim $OPTIM"
454 fi
455 fi
456
ef416fc2 457 if test $PICFLAG = 1; then
458 OPTIM="-KPIC $OPTIM"
459 fi
e1d6a774 460
461 if test "x$enable_32bit" = xyes; then
462 # Compiling on a Solaris system, build 64-bit
463 # binaries with separate 32-bit libraries...
464 ARCH32FLAGS="-xarch=generic"
e1d6a774 465
466 if test "x$with_optim" = x; then
467 # Suppress all of Sun's questionable
468 # warning messages, and default to
469 # 64-bit compiles of everything else...
470 OPTIM="-w $OPTIM"
f301802f 471 fi
472
473 if test -z "$with_archflags"; then
474 if test -z "$with_arch64flags"; then
475 ARCHFLAGS="-xarch=generic64"
476 else
477 ARCHFLAGS="$with_arch64flags"
478 fi
e1d6a774 479 fi
480 else
481 if test "x$enable_64bit" = xyes; then
482 # Build 64-bit libraries...
483 ARCH64FLAGS="-xarch=generic64"
f301802f 484 fi
485
486 if test "x$with_optim" = x; then
487 # Suppress all of Sun's questionable
488 # warning messages, and default to
489 # 32-bit compiles of everything else...
490 OPTIM="-w $OPTIM"
491 fi
e1d6a774 492
f301802f 493 if test -z "$with_archflags"; then
494 if test -z "$with_arch32flags"; then
495 ARCHFLAGS="-xarch=generic"
496 else
497 ARCHFLAGS="$with_arch32flags"
e1d6a774 498 fi
e1d6a774 499 fi
500 fi
ef416fc2 501 ;;
502 UNIX_SVR*)
503 # UnixWare
504 if test -z "$OPTIM"; then
505 if test "x$with_optim" = x; then
506 OPTIM="-O"
507 else
508 OPTIM="$with_optim $OPTIM"
509 fi
510 fi
511
512 if test $PICFLAG = 1; then
513 OPTIM="-KPIC $OPTIM"
514 fi
515 ;;
516 *)
517 # Running some other operating system; inform the user they
518 # should contribute the necessary options to
519 # cups-support@cups.org...
520 echo "Building CUPS with default compiler optimizations; contact"
521 echo "cups-bugs@cups.org with uname and compiler options needed"
5bd77a73
MS
522 echo "for your platform, or set the CFLAGS and LDFLAGS environment"
523 echo "variables before running configure."
ef416fc2 524 ;;
525 esac
526fi
527
2abf387c 528# Add general compiler options per platform...
529case $uname in
530 HP-UX*)
531 # HP-UX 10.20 (at least) needs this definition to get the
532 # h_errno global...
533 OPTIM="$OPTIM -D_XOPEN_SOURCE_EXTENDED"
534
535 # HP-UX 11.00 (at least) needs this definition to get the
536 # u_short type used by the IP headers...
537 OPTIM="$OPTIM -D_INCLUDE_HPUX_SOURCE"
b94498cf 538
539 # HP-UX 11.23 (at least) needs this definition to get the
540 # IPv6 header to work...
541 OPTIM="$OPTIM -D_HPUX_SOURCE"
2abf387c 542 ;;
543
dd1abb6b
MS
544 Linux*)
545 # glibc 2.8 and higher breaks peer credentials unless you
546 # define _GNU_SOURCE...
547 OPTIM="$OPTIM -D_GNU_SOURCE"
548 ;;
549
2abf387c 550 OSF*)
551 # Tru64 UNIX aka Digital UNIX aka OSF/1 need to be told
552 # to be POSIX-compliant...
553 OPTIM="$OPTIM -D_XOPEN_SOURCE=500 -D_XOPEN_SOURCE_EXTENDED -D_OSF_SOURCE"
554 ;;
555esac
ef416fc2 556
557dnl
b19ccc9e 558dnl End of "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $".
ef416fc2 559dnl