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