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