]> git.ipfire.org Git - thirdparty/cups.git/blob - config-scripts/cups-compiler.m4
Merge changes from CUPS 1.5b2-r9811.
[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 PHPOPTIONS=""
104 AC_SUBST(PHPOPTIONS)
105
106 if test -n "$GCC"; then
107 # Add GCC-specific compiler options...
108 if test -z "$OPTIM"; then
109 if test "x$with_optim" = x; then
110 # Default to optimize-for-size and debug
111 OPTIM="-Os -g"
112 else
113 OPTIM="$with_optim $OPTIM"
114 fi
115 fi
116
117 # Generate position-independent code as needed...
118 if test $PICFLAG = 1 -a $uname != AIX; then
119 OPTIM="-fPIC $OPTIM"
120 fi
121
122 # The -fstack-protector option is available with some versions of
123 # GCC and adds "stack canaries" which detect when the return address
124 # has been overwritten, preventing many types of exploit attacks.
125 AC_MSG_CHECKING(if GCC supports -fstack-protector)
126 OLDCFLAGS="$CFLAGS"
127 CFLAGS="$CFLAGS -fstack-protector"
128 AC_TRY_LINK(,,
129 OPTIM="$OPTIM -fstack-protector"
130 AC_MSG_RESULT(yes),
131 AC_MSG_RESULT(no))
132 CFLAGS="$OLDCFLAGS"
133
134 # The -fPIE option is available with some versions of GCC and adds
135 # randomization of addresses, which avoids another class of exploits
136 # that depend on a fixed address for common functions.
137 AC_MSG_CHECKING(if GCC supports -fPIE)
138 OLDCFLAGS="$CFLAGS"
139 CFLAGS="$CFLAGS -fPIE"
140 AC_TRY_COMPILE(,,
141 [case "$CC" in
142 *clang)
143 PIEFLAGS="-fPIE -Wl,-pie"
144 ;;
145 *)
146 PIEFLAGS="-fPIE -pie"
147 ;;
148 esac
149 AC_MSG_RESULT(yes)],
150 AC_MSG_RESULT(no))
151 CFLAGS="$OLDCFLAGS"
152
153 if test "x$with_optim" = x; then
154 # Add useful warning options for tracking down problems...
155 OPTIM="-Wall -Wno-format-y2k -Wunused $OPTIM"
156
157 # Additional warning options for development testing...
158 if test -d .svn; then
159 OPTIM="-Wshadow $OPTIM"
160 CFLAGS="-Werror-implicit-function-declaration $CFLAGS"
161 PHPOPTIONS="-Wno-shadow"
162 else
163 AC_MSG_CHECKING(if GCC supports -Wno-tautological-compare)
164 OLDCFLAGS="$CFLAGS"
165 CFLAGS="$CFLAGS -Wno-tautological-compare"
166 AC_TRY_COMPILE(,,
167 [OPTIM="$OPTIM -Wno-tautological-compare"
168 AC_MSG_RESULT(yes)],
169 AC_MSG_RESULT(no))
170 CFLAGS="$OLDCFLAGS"
171 fi
172 fi
173
174 case "$uname" in
175 Darwin*)
176 # -D_FORTIFY_SOURCE=2 adds additional object size
177 # checking, basically wrapping all string functions
178 # with buffer-limited ones. Not strictly needed for
179 # CUPS since we already use buffer-limited calls, but
180 # this will catch any additions that are broken.
181 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
182 ;;
183
184 HP-UX*)
185 if test "x$enable_32bit" = xyes; then
186 # Build 32-bit libraries, 64-bit base...
187 if test -z "$with_arch32flags"; then
188 ARCH32FLAGS="-milp32"
189 else
190 ARCH32FLAGS="$with_arch32flags"
191 fi
192
193 if test -z "$with_archflags"; then
194 if test -z "$with_arch64flags"; then
195 ARCHFLAGS="-mlp64"
196 else
197 ARCHFLAGS="$with_arch64flags"
198 fi
199 fi
200 fi
201
202 if test "x$enable_64bit" = xyes; then
203 # Build 64-bit libraries, 32-bit base...
204 if test -z "$with_arch64flags"; then
205 ARCH64FLAGS="-mlp64"
206 else
207 ARCH64FLAGS="$with_arch64flags"
208 fi
209
210 if test -z "$with_archflags"; then
211 if test -z "$with_arch32flags"; then
212 ARCHFLAGS="-milp32"
213 else
214 ARCHFLAGS="$with_arch32flags"
215 fi
216 fi
217 fi
218 ;;
219
220 IRIX)
221 if test "x$enable_32bit" = xyes; then
222 # Build 32-bit libraries, 64-bit base...
223 if test -z "$with_arch32flags"; then
224 ARCH32FLAGS="-n32 -mips3"
225 else
226 ARCH32FLAGS="$with_arch32flags"
227 fi
228
229 if test -z "$with_archflags"; then
230 if test -z "$with_arch64flags"; then
231 ARCHFLAGS="-64 -mips4"
232 else
233 ARCHFLAGS="$with_arch64flags"
234 fi
235 fi
236 fi
237
238 if test "x$enable_64bit" = xyes; then
239 # Build 64-bit libraries, 32-bit base...
240 if test -z "$with_arch64flags"; then
241 ARCH64FLAGS="-64 -mips4"
242 else
243 ARCH64FLAGS="$with_arch64flags"
244 fi
245
246 if test -z "$with_archflags"; then
247 if test -z "$with_arch32flags"; then
248 ARCHFLAGS="-n32 -mips3"
249 else
250 ARCHFLAGS="$with_arch32flags"
251 fi
252 fi
253 fi
254 ;;
255
256 Linux*)
257 # The -z relro option is provided by the Linux linker command to
258 # make relocatable data read-only.
259 if test x$enable_relro = xyes; then
260 RELROFLAGS="-Wl,-z,relro"
261 fi
262
263 if test "x$enable_32bit" = xyes; then
264 # Build 32-bit libraries, 64-bit base...
265 if test -z "$with_arch32flags"; then
266 ARCH32FLAGS="-m32"
267 else
268 ARCH32FLAGS="$with_arch32flags"
269 fi
270
271 if test -z "$with_archflags"; then
272 if test -z "$with_arch64flags"; then
273 ARCHFLAGS="-m64"
274 else
275 ARCHFLAGS="$with_arch64flags"
276 fi
277 fi
278 fi
279
280 if test "x$enable_64bit" = xyes; then
281 # Build 64-bit libraries, 32-bit base...
282 if test -z "$with_arch64flags"; then
283 ARCH64FLAGS="-m64"
284 else
285 ARCH64FLAGS="$with_arch64flags"
286 fi
287
288 if test -z "$with_archflags"; then
289 if test -z "$with_arch32flags"; then
290 ARCHFLAGS="-m32"
291 else
292 ARCHFLAGS="$with_arch32flags"
293 fi
294 fi
295 fi
296 ;;
297
298 SunOS*)
299 if test "x$enable_32bit" = xyes; then
300 # Build 32-bit libraries, 64-bit base...
301 if test -z "$with_arch32flags"; then
302 ARCH32FLAGS="-m32"
303 else
304 ARCH32FLAGS="$with_arch32flags"
305 fi
306
307 if test -z "$with_archflags"; then
308 if test -z "$with_arch64flags"; then
309 ARCHFLAGS="-m64"
310 else
311 ARCHFLAGS="$with_arch64flags"
312 fi
313 fi
314 fi
315
316 if test "x$enable_64bit" = xyes; then
317 # Build 64-bit libraries, 32-bit base...
318 if test -z "$with_arch64flags"; then
319 ARCH64FLAGS="-m64"
320 else
321 ARCH64FLAGS="$with_arch64flags"
322 fi
323
324 if test -z "$with_archflags"; then
325 if test -z "$with_arch32flags"; then
326 ARCHFLAGS="-m32"
327 else
328 ARCHFLAGS="$with_arch32flags"
329 fi
330 fi
331 fi
332 ;;
333 esac
334 else
335 # Add vendor-specific compiler options...
336 case $uname in
337 AIX*)
338 if test -z "$OPTIM"; then
339 if test "x$with_optim" = x; then
340 OPTIM="-O2 -qmaxmem=6000"
341 else
342 OPTIM="$with_optim $OPTIM"
343 fi
344 fi
345 ;;
346 HP-UX*)
347 if test -z "$OPTIM"; then
348 if test "x$with_optim" = x; then
349 OPTIM="+O2"
350 else
351 OPTIM="$with_optim $OPTIM"
352 fi
353 fi
354
355 CFLAGS="-Ae $CFLAGS"
356
357 if test $PICFLAG = 1; then
358 OPTIM="+z $OPTIM"
359 fi
360
361 if test "x$enable_32bit" = xyes; then
362 # Build 32-bit libraries, 64-bit base...
363 if test -z "$with_arch32flags"; then
364 ARCH32FLAGS="+DD32"
365 else
366 ARCH32FLAGS="$with_arch32flags"
367 fi
368
369 if test -z "$with_archflags"; then
370 if test -z "$with_arch64flags"; then
371 ARCHFLAGS="+DD64"
372 else
373 ARCHFLAGS="$with_arch64flags"
374 fi
375 fi
376 fi
377
378 if test "x$enable_64bit" = xyes; then
379 # Build 64-bit libraries, 32-bit base...
380 if test -z "$with_arch64flags"; then
381 ARCH64FLAGS="+DD64"
382 else
383 ARCH64FLAGS="$with_arch64flags"
384 fi
385
386 if test -z "$with_archflags"; then
387 if test -z "$with_arch32flags"; then
388 ARCHFLAGS="+DD32"
389 else
390 ARCHFLAGS="$with_arch32flags"
391 fi
392 fi
393 fi
394 ;;
395 IRIX)
396 if test -z "$OPTIM"; then
397 if test "x$with_optim" = x; then
398 OPTIM="-O2"
399 else
400 OPTIM="$with_optim $OPTIM"
401 fi
402 fi
403
404 if test "x$with_optim" = x; then
405 OPTIM="-fullwarn -woff 1183,1209,1349,1506,3201 $OPTIM"
406 fi
407
408 if test "x$enable_32bit" = xyes; then
409 # Build 32-bit libraries, 64-bit base...
410 if test -z "$with_arch32flags"; then
411 ARCH32FLAGS="-n32 -mips3"
412 else
413 ARCH32FLAGS="$with_arch32flags"
414 fi
415
416 if test -z "$with_archflags"; then
417 if test -z "$with_arch64flags"; then
418 ARCHFLAGS="-64 -mips4"
419 else
420 ARCHFLAGS="$with_arch64flags"
421 fi
422 fi
423 fi
424
425 if test "x$enable_64bit" = xyes; then
426 # Build 64-bit libraries, 32-bit base...
427 if test -z "$with_arch64flags"; then
428 ARCH64FLAGS="-64 -mips4"
429 else
430 ARCH64FLAGS="$with_arch64flags"
431 fi
432
433 if test -z "$with_archflags"; then
434 if test -z "$with_arch32flags"; then
435 ARCHFLAGS="-n32 -mips3"
436 else
437 ARCHFLAGS="$with_arch32flags"
438 fi
439 fi
440 fi
441 ;;
442 OSF*)
443 # Tru64 UNIX aka Digital UNIX aka OSF/1
444 if test -z "$OPTIM"; then
445 if test "x$with_optim" = x; then
446 OPTIM="-O"
447 else
448 OPTIM="$with_optim"
449 fi
450 fi
451 ;;
452 SunOS*)
453 # Solaris
454 if test -z "$OPTIM"; then
455 if test "x$with_optim" = x; then
456 OPTIM="-xO2"
457 else
458 OPTIM="$with_optim $OPTIM"
459 fi
460 fi
461
462 if test $PICFLAG = 1; then
463 OPTIM="-KPIC $OPTIM"
464 fi
465
466 if test "x$enable_32bit" = xyes; then
467 # Compiling on a Solaris system, build 64-bit
468 # binaries with separate 32-bit libraries...
469 ARCH32FLAGS="-xarch=generic"
470
471 if test "x$with_optim" = x; then
472 # Suppress all of Sun's questionable
473 # warning messages, and default to
474 # 64-bit compiles of everything else...
475 OPTIM="-w $OPTIM"
476 fi
477
478 if test -z "$with_archflags"; then
479 if test -z "$with_arch64flags"; then
480 ARCHFLAGS="-xarch=generic64"
481 else
482 ARCHFLAGS="$with_arch64flags"
483 fi
484 fi
485 else
486 if test "x$enable_64bit" = xyes; then
487 # Build 64-bit libraries...
488 ARCH64FLAGS="-xarch=generic64"
489 fi
490
491 if test "x$with_optim" = x; then
492 # Suppress all of Sun's questionable
493 # warning messages, and default to
494 # 32-bit compiles of everything else...
495 OPTIM="-w $OPTIM"
496 fi
497
498 if test -z "$with_archflags"; then
499 if test -z "$with_arch32flags"; then
500 ARCHFLAGS="-xarch=generic"
501 else
502 ARCHFLAGS="$with_arch32flags"
503 fi
504 fi
505 fi
506 ;;
507 UNIX_SVR*)
508 # UnixWare
509 if test -z "$OPTIM"; then
510 if test "x$with_optim" = x; then
511 OPTIM="-O"
512 else
513 OPTIM="$with_optim $OPTIM"
514 fi
515 fi
516
517 if test $PICFLAG = 1; then
518 OPTIM="-KPIC $OPTIM"
519 fi
520 ;;
521 *)
522 # Running some other operating system; inform the user they
523 # should contribute the necessary options to
524 # cups-support@cups.org...
525 echo "Building CUPS with default compiler optimizations; contact"
526 echo "cups-bugs@cups.org with uname and compiler options needed"
527 echo "for your platform, or set the CFLAGS and LDFLAGS environment"
528 echo "variables before running configure."
529 ;;
530 esac
531 fi
532
533 # Add general compiler options per platform...
534 case $uname in
535 HP-UX*)
536 # HP-UX 10.20 (at least) needs this definition to get the
537 # h_errno global...
538 OPTIM="$OPTIM -D_XOPEN_SOURCE_EXTENDED"
539
540 # HP-UX 11.00 (at least) needs this definition to get the
541 # u_short type used by the IP headers...
542 OPTIM="$OPTIM -D_INCLUDE_HPUX_SOURCE"
543
544 # HP-UX 11.23 (at least) needs this definition to get the
545 # IPv6 header to work...
546 OPTIM="$OPTIM -D_HPUX_SOURCE"
547 ;;
548
549 Linux*)
550 # glibc 2.8 and higher breaks peer credentials unless you
551 # define _GNU_SOURCE...
552 OPTIM="$OPTIM -D_GNU_SOURCE"
553 ;;
554
555 OSF*)
556 # Tru64 UNIX aka Digital UNIX aka OSF/1 need to be told
557 # to be POSIX-compliant...
558 OPTIM="$OPTIM -D_XOPEN_SOURCE=500 -D_XOPEN_SOURCE_EXTENDED -D_OSF_SOURCE"
559 ;;
560 esac
561
562 dnl
563 dnl End of "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $".
564 dnl