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