]> git.ipfire.org Git - thirdparty/cups.git/blob - config-scripts/cups-compiler.m4
Merge changes from CUPS 1.6svn-r9968.
[thirdparty/cups.git] / config-scripts / cups-compiler.m4
1 dnl
2 dnl "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $"
3 dnl
4 dnl Compiler stuff for CUPS.
5 dnl
6 dnl Copyright 2007-2011 by Apple Inc.
7 dnl Copyright 1997-2007 by Easy Software Products, all rights reserved.
8 dnl
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/".
14 dnl
15
16 dnl Clear the debugging and non-shared library options unless the user asks
17 dnl for them...
18 INSTALL_STRIP=""
19 OPTIM=""
20 AC_SUBST(INSTALL_STRIP)
21 AC_SUBST(OPTIM)
22
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])
28
29 dnl For debugging, keep symbols, otherwise strip them...
30 if test x$enable_debug = xyes; then
31 OPTIM="-g"
32 else
33 INSTALL_STRIP="-s"
34 fi
35
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"
40 fi
41
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"
47 fi
48
49 dnl Unit tests take up time during a compile...
50 if test x$enable_unit_tests = xyes; then
51 UNITTESTS="unittests"
52 else
53 UNITTESTS=""
54 fi
55 AC_SUBST(UNITTESTS)
56
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 ])
60
61 if test -z "$with_archflags"; then
62 ARCHFLAGS=""
63 else
64 ARCHFLAGS="$with_archflags"
65 fi
66
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//'`"
71 else
72 LDARCHFLAGS="$ARCHFLAGS"
73 fi
74 else
75 LDARCHFLAGS="$with_ldarchflags"
76 fi
77
78 AC_SUBST(ARCHFLAGS)
79 AC_SUBST(LDARCHFLAGS)
80
81 dnl Setup support for separate 32/64-bit library generation...
82 AC_ARG_WITH(arch32flags, [ --with-arch32flags set 32-bit architecture flags])
83 ARCH32FLAGS=""
84 AC_SUBST(ARCH32FLAGS)
85
86 AC_ARG_WITH(arch64flags, [ --with-arch64flags set 64-bit architecture flags])
87 ARCH64FLAGS=""
88 AC_SUBST(ARCH64FLAGS)
89
90 dnl Read-only data/program support on Linux...
91 AC_ARG_ENABLE(relro, [ --enable-relro build with the GCC relro option])
92
93 dnl Update compiler options...
94 CXXLIBS="${CXXLIBS:=}"
95 AC_SUBST(CXXLIBS)
96
97 PIEFLAGS=""
98 AC_SUBST(PIEFLAGS)
99
100 RELROFLAGS=""
101 AC_SUBST(RELROFLAGS)
102
103 if test -n "$GCC"; then
104 # Add GCC-specific compiler options...
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
114 # Generate position-independent code as needed...
115 if test $PICFLAG = 1 -a $uname != AIX; then
116 OPTIM="-fPIC $OPTIM"
117 fi
118
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"
125 AC_TRY_LINK(,,
126 OPTIM="$OPTIM -fstack-protector"
127 AC_MSG_RESULT(yes),
128 AC_MSG_RESULT(no))
129 CFLAGS="$OLDCFLAGS"
130
131 # The -fPIE option is available with some versions of GCC and adds
132 # randomization of addresses, which avoids another class of exploits
133 # that depend on a fixed address for common functions.
134 AC_MSG_CHECKING(if GCC supports -fPIE)
135 OLDCFLAGS="$CFLAGS"
136 CFLAGS="$CFLAGS -fPIE"
137 AC_TRY_COMPILE(,,
138 [case "$CC" in
139 *clang)
140 PIEFLAGS="-fPIE -Wl,-pie"
141 ;;
142 *)
143 PIEFLAGS="-fPIE -pie"
144 ;;
145 esac
146 AC_MSG_RESULT(yes)],
147 AC_MSG_RESULT(no))
148 CFLAGS="$OLDCFLAGS"
149
150 if test "x$with_optim" = x; then
151 # Add useful warning options for tracking down problems...
152 OPTIM="-Wall -Wno-format-y2k -Wunused $OPTIM"
153
154 # Additional warning options for development testing...
155 if test -d .svn; then
156 OPTIM="-Wshadow -Werror $OPTIM"
157 else
158 AC_MSG_CHECKING(if GCC supports -Wno-tautological-compare)
159 OLDCFLAGS="$CFLAGS"
160 CFLAGS="$CFLAGS -Werror -Wno-tautological-compare"
161 AC_TRY_COMPILE(,,
162 [OPTIM="$OPTIM -Wno-tautological-compare"
163 AC_MSG_RESULT(yes)],
164 AC_MSG_RESULT(no))
165 CFLAGS="$OLDCFLAGS"
166 fi
167 fi
168
169 case "$uname" in
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
175 # this will catch any additions that are broken.
176 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
177 ;;
178
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
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
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
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
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
247 fi
248 fi
249 ;;
250
251 Linux*)
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
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
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
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
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
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
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
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
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
325 fi
326 fi
327 ;;
328 esac
329 else
330 # Add vendor-specific compiler options...
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
352 if test $PICFLAG = 1; then
353 OPTIM="+z $OPTIM"
354 fi
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
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
399 if test "x$with_optim" = x; then
400 OPTIM="-fullwarn -woff 1183,1209,1349,1506,3201 $OPTIM"
401 fi
402
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
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
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
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
434 fi
435 fi
436 ;;
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 ;;
447 SunOS*)
448 # Solaris
449 if test -z "$OPTIM"; then
450 if test "x$with_optim" = x; then
451 OPTIM="-xO2"
452 else
453 OPTIM="$with_optim $OPTIM"
454 fi
455 fi
456
457 if test $PICFLAG = 1; then
458 OPTIM="-KPIC $OPTIM"
459 fi
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"
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"
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
479 fi
480 else
481 if test "x$enable_64bit" = xyes; then
482 # Build 64-bit libraries...
483 ARCH64FLAGS="-xarch=generic64"
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
492
493 if test -z "$with_archflags"; then
494 if test -z "$with_arch32flags"; then
495 ARCHFLAGS="-xarch=generic"
496 else
497 ARCHFLAGS="$with_arch32flags"
498 fi
499 fi
500 fi
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"
522 echo "for your platform, or set the CFLAGS and LDFLAGS environment"
523 echo "variables before running configure."
524 ;;
525 esac
526 fi
527
528 # Add general compiler options per platform...
529 case $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"
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"
542 ;;
543
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
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 ;;
555 esac
556
557 dnl
558 dnl End of "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $".
559 dnl