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