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