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