]> git.ipfire.org Git - thirdparty/cups.git/blame - config-scripts/cups-compiler.m4
Merge changes from CUPS 1.4svn-r8454.
[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
MS
38 CFLAGS="$CFLAGS -DDEBUG"
39fi
40
745129be
MS
41dnl Debug guards use an extra 4 bytes for some structures like strings in the
42dnl string pool, so provide a separate option for that
43if test x$enable_debug_guards = xyes; then
44 CFLAGS="$CFLAGS -DDEBUG_GUARDS"
45fi
46
5f64df29
MS
47dnl Unit tests take up time during a compile...
48if test x$enable_unit_tests = xyes; then
49 UNITTESTS="unittests"
50else
51 UNITTESTS=""
52fi
53AC_SUBST(UNITTESTS)
54
ed486911 55dnl Setup general architecture flags...
bf3816c7
MS
56AC_ARG_WITH(archflags, [ --with-archflags set default architecture flags ])
57AC_ARG_WITH(ldarchflags, [ --with-ldarchflags set program architecture flags ])
ed486911 58
59if test -z "$with_archflags"; then
60 ARCHFLAGS=""
61else
62 ARCHFLAGS="$with_archflags"
a603edef
MS
63fi
64
65if test -z "$with_ldarchflags"; then
09a101d6 66 if test "$uname" = Darwin; then
a603edef 67 # Only create 32-bit programs by default
09a101d6 68 LDARCHFLAGS="`echo $ARCHFLAGS | sed -e '1,$s/-arch x86_64//' -e '1,$s/-arch ppc64//'`"
69 else
70 LDARCHFLAGS="$ARCHFLAGS"
71 fi
a603edef 72else
839a51c8 73 LDARCHFLAGS="$with_ldarchflags"
ed486911 74fi
75
76AC_SUBST(ARCHFLAGS)
09a101d6 77AC_SUBST(LDARCHFLAGS)
ed486911 78
e1d6a774 79dnl Setup support for separate 32/64-bit library generation...
bf3816c7 80AC_ARG_WITH(arch32flags, [ --with-arch32flags set 32-bit architecture flags])
e1d6a774 81ARCH32FLAGS=""
e1d6a774 82AC_SUBST(ARCH32FLAGS)
e1d6a774 83
bf3816c7 84AC_ARG_WITH(arch64flags, [ --with-arch64flags set 64-bit architecture flags])
e1d6a774 85ARCH64FLAGS=""
e1d6a774 86AC_SUBST(ARCH64FLAGS)
e1d6a774 87
f7deaa1a 88dnl Read-only data/program support on Linux...
bf3816c7 89AC_ARG_ENABLE(relro, [ --enable-relro build with the GCC relro option])
f7deaa1a 90
ef416fc2 91dnl Update compiler options...
ac884b6a
MS
92CXXLIBS="${CXXLIBS:=}"
93AC_SUBST(CXXLIBS)
94
a74454a7 95PIEFLAGS=""
96AC_SUBST(PIEFLAGS)
97
f7deaa1a 98RELROFLAGS=""
99AC_SUBST(RELROFLAGS)
100
355e94dc 101LIBCUPSORDER="libcups.order"
bf3816c7 102AC_ARG_WITH(libcupsorder, [ --with-libcupsorder set libcups secorder file, default=libcups.order],
355e94dc
MS
103 if test -f "$withval"; then
104 LIBCUPSORDER="$withval"
105 fi)
cc0d019f
MS
106AC_SUBST(LIBCUPSORDER)
107
355e94dc
MS
108LIBCUPSIMAGEORDER="libcupsimage.order"
109AC_ARG_WITH(libcupsimageorder, [ --with-libcupsimagesorder
bf3816c7 110 set libcupsimage secorder file, default=libcupsimage.order],
355e94dc
MS
111 if test -f "$withval"; then
112 LIBCUPSIMAGEORDER="$withval"
113 fi)
cc0d019f
MS
114AC_SUBST(LIBCUPSIMAGEORDER)
115
7a14d768
MS
116PHPOPTIONS=""
117AC_SUBST(PHPOPTIONS)
118
ef416fc2 119if test -n "$GCC"; then
2abf387c 120 # Add GCC-specific compiler options...
ef416fc2 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
a4924f6c 130 # Generate position-independent code as needed...
ef416fc2 131 if test $PICFLAG = 1 -a $uname != AIX; then
132 OPTIM="-fPIC $OPTIM"
133 fi
134
a4924f6c
MS
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"
ef416fc2 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"
a4924f6c 162 # Additional warning options for development testing...
d9bca400
MS
163 if test -d .svn; then
164 OPTIM="-Wshadow -Wunused $OPTIM"
749b1e90 165 CFLAGS="-Werror-implicit-function-declaration $CFLAGS"
7a14d768 166 PHPOPTIONS="-Wno-shadow"
d9bca400 167 fi
ef416fc2 168 fi
e1d6a774 169
170 case "$uname" in
a4924f6c
MS
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"
568fa3fa
MS
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
a4924f6c
MS
183 ;;
184
b86bc4cf 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
e1d6a774 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
e1d6a774 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
e1d6a774 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
e1d6a774 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
e1d6a774 253 fi
254 fi
255 ;;
256
257 Linux*)
a4924f6c
MS
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
e1d6a774 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
e1d6a774 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
e1d6a774 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
e1d6a774 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
e1d6a774 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
e1d6a774 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
e1d6a774 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
e1d6a774 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
e1d6a774 331 fi
332 fi
333 ;;
334 esac
ef416fc2 335else
2abf387c 336 # Add vendor-specific compiler options...
ef416fc2 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
ef416fc2 358 if test $PICFLAG = 1; then
359 OPTIM="+z $OPTIM"
360 fi
c277e2f8
MS
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
ef416fc2 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
e1d6a774 405 if test "x$with_optim" = x; then
406 OPTIM="-fullwarn -woff 1183,1209,1349,1506,3201 $OPTIM"
ef416fc2 407 fi
408
e1d6a774 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
e1d6a774 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
e1d6a774 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
e1d6a774 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
ef416fc2 440 fi
441 fi
442 ;;
2abf387c 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 ;;
ef416fc2 453 SunOS*)
454 # Solaris
455 if test -z "$OPTIM"; then
456 if test "x$with_optim" = x; then
ed486911 457 OPTIM="-xO2"
ef416fc2 458 else
459 OPTIM="$with_optim $OPTIM"
460 fi
461 fi
462
ef416fc2 463 if test $PICFLAG = 1; then
464 OPTIM="-KPIC $OPTIM"
465 fi
e1d6a774 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"
e1d6a774 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"
f301802f 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
e1d6a774 485 fi
486 else
487 if test "x$enable_64bit" = xyes; then
488 # Build 64-bit libraries...
489 ARCH64FLAGS="-xarch=generic64"
f301802f 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
e1d6a774 498
f301802f 499 if test -z "$with_archflags"; then
500 if test -z "$with_arch32flags"; then
501 ARCHFLAGS="-xarch=generic"
502 else
503 ARCHFLAGS="$with_arch32flags"
e1d6a774 504 fi
e1d6a774 505 fi
506 fi
ef416fc2 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"
5bd77a73
MS
528 echo "for your platform, or set the CFLAGS and LDFLAGS environment"
529 echo "variables before running configure."
ef416fc2 530 ;;
531 esac
532fi
533
2abf387c 534# Add general compiler options per platform...
535case $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"
b94498cf 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"
2abf387c 548 ;;
549
dd1abb6b
MS
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
2abf387c 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 ;;
561esac
ef416fc2 562
563dnl
b19ccc9e 564dnl End of "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $".
ef416fc2 565dnl