]> git.ipfire.org Git - thirdparty/cups.git/blame - config-scripts/cups-compiler.m4
Merge changes from CUPS 1.5svn-r9675.
[thirdparty/cups.git] / config-scripts / cups-compiler.m4
CommitLineData
ef416fc2 1dnl
b19ccc9e 2dnl "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $"
ef416fc2 3dnl
4dnl Compiler stuff for the Common UNIX Printing System (CUPS).
5dnl
745129be 6dnl Copyright 2007-2009 by Apple Inc.
f7deaa1a 7dnl Copyright 1997-2007 by Easy Software Products, all rights reserved.
ef416fc2 8dnl
9dnl These coded instructions, statements, and computer programs are the
bc44d920 10dnl property of Apple Inc. and are protected by Federal copyright
11dnl law. Distribution and use rights are outlined in the file "LICENSE.txt"
12dnl which should have been included with this file. If this file is
13dnl file is missing or damaged, see the license at "http://www.cups.org/".
ef416fc2 14dnl
15
16dnl Clear the debugging and non-shared library options unless the user asks
17dnl for them...
50fe7201 18INSTALL_STRIP=""
ef416fc2 19OPTIM=""
50fe7201 20AC_SUBST(INSTALL_STRIP)
ef416fc2 21AC_SUBST(OPTIM)
22
bf3816c7
MS
23AC_ARG_WITH(optim, [ --with-optim set optimization flags ])
24AC_ARG_ENABLE(debug, [ --enable-debug build with debugging symbols])
25AC_ARG_ENABLE(debug_guards, [ --enable-debug-guards build with memory allocation guards])
26AC_ARG_ENABLE(debug_printfs, [ --enable-debug-printfs build with CUPS_DEBUG_LOG support])
27AC_ARG_ENABLE(unit_tests, [ --enable-unit-tests build and run unit tests])
839a51c8
MS
28
29dnl For debugging, keep symbols, otherwise strip them...
30if test x$enable_debug = xyes; then
31 OPTIM="-g"
32else
33 INSTALL_STRIP="-s"
34fi
ef416fc2 35
5f64df29 36dnl Debug printfs can slow things down, so provide a separate option for that
52f6f666 37if test x$enable_debug_printfs = xyes; then
5f64df29 38 CFLAGS="$CFLAGS -DDEBUG"
94da7e34 39 CXXFLAGS="$CXXFLAGS -DDEBUG"
5f64df29
MS
40fi
41
745129be
MS
42dnl Debug guards use an extra 4 bytes for some structures like strings in the
43dnl string pool, so provide a separate option for that
44if test x$enable_debug_guards = xyes; then
45 CFLAGS="$CFLAGS -DDEBUG_GUARDS"
94da7e34 46 CXXFLAGS="$CXXFLAGS -DDEBUG_GUARDS"
745129be
MS
47fi
48
5f64df29
MS
49dnl Unit tests take up time during a compile...
50if test x$enable_unit_tests = xyes; then
51 UNITTESTS="unittests"
52else
53 UNITTESTS=""
54fi
55AC_SUBST(UNITTESTS)
56
ed486911 57dnl Setup general architecture flags...
bf3816c7
MS
58AC_ARG_WITH(archflags, [ --with-archflags set default architecture flags ])
59AC_ARG_WITH(ldarchflags, [ --with-ldarchflags set program architecture flags ])
ed486911 60
61if test -z "$with_archflags"; then
62 ARCHFLAGS=""
63else
64 ARCHFLAGS="$with_archflags"
a603edef
MS
65fi
66
67if test -z "$with_ldarchflags"; then
09a101d6 68 if test "$uname" = Darwin; then
a603edef 69 # Only create 32-bit programs by default
09a101d6 70 LDARCHFLAGS="`echo $ARCHFLAGS | sed -e '1,$s/-arch x86_64//' -e '1,$s/-arch ppc64//'`"
71 else
72 LDARCHFLAGS="$ARCHFLAGS"
73 fi
a603edef 74else
839a51c8 75 LDARCHFLAGS="$with_ldarchflags"
ed486911 76fi
77
78AC_SUBST(ARCHFLAGS)
09a101d6 79AC_SUBST(LDARCHFLAGS)
ed486911 80
e1d6a774 81dnl Setup support for separate 32/64-bit library generation...
bf3816c7 82AC_ARG_WITH(arch32flags, [ --with-arch32flags set 32-bit architecture flags])
e1d6a774 83ARCH32FLAGS=""
e1d6a774 84AC_SUBST(ARCH32FLAGS)
e1d6a774 85
bf3816c7 86AC_ARG_WITH(arch64flags, [ --with-arch64flags set 64-bit architecture flags])
e1d6a774 87ARCH64FLAGS=""
e1d6a774 88AC_SUBST(ARCH64FLAGS)
e1d6a774 89
f7deaa1a 90dnl Read-only data/program support on Linux...
bf3816c7 91AC_ARG_ENABLE(relro, [ --enable-relro build with the GCC relro option])
f7deaa1a 92
ef416fc2 93dnl Update compiler options...
ac884b6a
MS
94CXXLIBS="${CXXLIBS:=}"
95AC_SUBST(CXXLIBS)
96
a74454a7 97PIEFLAGS=""
98AC_SUBST(PIEFLAGS)
99
f7deaa1a 100RELROFLAGS=""
101AC_SUBST(RELROFLAGS)
102
7a14d768
MS
103PHPOPTIONS=""
104AC_SUBST(PHPOPTIONS)
105
ef416fc2 106if test -n "$GCC"; then
2abf387c 107 # Add GCC-specific compiler options...
ef416fc2 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
a4924f6c 117 # Generate position-independent code as needed...
ef416fc2 118 if test $PICFLAG = 1 -a $uname != AIX; then
119 OPTIM="-fPIC $OPTIM"
120 fi
121
a4924f6c
MS
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"
68b10830 128 AC_TRY_LINK(,,
a4924f6c
MS
129 OPTIM="$OPTIM -fstack-protector"
130 AC_MSG_RESULT(yes),
131 AC_MSG_RESULT(no))
132 CFLAGS="$OLDCFLAGS"
133
134 # The -pie 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 -pie)
138 OLDCFLAGS="$CFLAGS"
139 CFLAGS="$CFLAGS -pie -fPIE"
140 AC_TRY_COMPILE(,,
141 PIEFLAGS="-pie -fPIE"
142 AC_MSG_RESULT(yes),
143 AC_MSG_RESULT(no))
144 CFLAGS="$OLDCFLAGS"
ef416fc2 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"
a4924f6c 149 # Additional warning options for development testing...
d9bca400
MS
150 if test -d .svn; then
151 OPTIM="-Wshadow -Wunused $OPTIM"
749b1e90 152 CFLAGS="-Werror-implicit-function-declaration $CFLAGS"
7a14d768 153 PHPOPTIONS="-Wno-shadow"
d9bca400 154 fi
ef416fc2 155 fi
e1d6a774 156
157 case "$uname" in
a4924f6c
MS
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"
568fa3fa
MS
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
a4924f6c
MS
170 ;;
171
b86bc4cf 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
e1d6a774 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
e1d6a774 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
e1d6a774 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
e1d6a774 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
e1d6a774 240 fi
241 fi
242 ;;
243
244 Linux*)
a4924f6c
MS
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
e1d6a774 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
e1d6a774 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
e1d6a774 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
e1d6a774 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
e1d6a774 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
e1d6a774 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
e1d6a774 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
e1d6a774 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
e1d6a774 318 fi
319 fi
320 ;;
321 esac
ef416fc2 322else
2abf387c 323 # Add vendor-specific compiler options...
ef416fc2 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
ef416fc2 345 if test $PICFLAG = 1; then
346 OPTIM="+z $OPTIM"
347 fi
c277e2f8
MS
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
ef416fc2 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
e1d6a774 392 if test "x$with_optim" = x; then
393 OPTIM="-fullwarn -woff 1183,1209,1349,1506,3201 $OPTIM"
ef416fc2 394 fi
395
e1d6a774 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
e1d6a774 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
e1d6a774 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
e1d6a774 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
ef416fc2 427 fi
428 fi
429 ;;
2abf387c 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 ;;
ef416fc2 440 SunOS*)
441 # Solaris
442 if test -z "$OPTIM"; then
443 if test "x$with_optim" = x; then
ed486911 444 OPTIM="-xO2"
ef416fc2 445 else
446 OPTIM="$with_optim $OPTIM"
447 fi
448 fi
449
ef416fc2 450 if test $PICFLAG = 1; then
451 OPTIM="-KPIC $OPTIM"
452 fi
e1d6a774 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"
e1d6a774 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"
f301802f 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
e1d6a774 472 fi
473 else
474 if test "x$enable_64bit" = xyes; then
475 # Build 64-bit libraries...
476 ARCH64FLAGS="-xarch=generic64"
f301802f 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
e1d6a774 485
f301802f 486 if test -z "$with_archflags"; then
487 if test -z "$with_arch32flags"; then
488 ARCHFLAGS="-xarch=generic"
489 else
490 ARCHFLAGS="$with_arch32flags"
e1d6a774 491 fi
e1d6a774 492 fi
493 fi
ef416fc2 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"
5bd77a73
MS
515 echo "for your platform, or set the CFLAGS and LDFLAGS environment"
516 echo "variables before running configure."
ef416fc2 517 ;;
518 esac
519fi
520
2abf387c 521# Add general compiler options per platform...
522case $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"
b94498cf 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"
2abf387c 535 ;;
536
dd1abb6b
MS
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
2abf387c 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 ;;
548esac
ef416fc2 549
550dnl
b19ccc9e 551dnl End of "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $".
ef416fc2 552dnl