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