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