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