Build Fix -- compatibility issue with newer autoconf
[sxemacs] / m4 / sxe-compiler.m4
1 dnl compiler.m4 --- compiler magic
2 dnl
3 dnl Copyright (C) 2005, 2006, 2007, 2008 Sebastian Freundt
4 dnl Copyright (c) 2005 Steven G. Johnson
5 dnl Copyright (c) 2005 Matteo Frigo
6 dnl
7 dnl Author: Sebastian Freundt <hroptatyr@sxemacs.org>
8 dnl
9 dnl Redistribution and use in source and binary forms, with or without
10 dnl modification, are permitted provided that the following conditions
11 dnl are met:
12 dnl
13 dnl 1. Redistributions of source code must retain the above copyright
14 dnl    notice, this list of conditions and the following disclaimer.
15 dnl
16 dnl 2. Redistributions in binary form must reproduce the above copyright
17 dnl    notice, this list of conditions and the following disclaimer in the
18 dnl    documentation and/or other materials provided with the distribution.
19 dnl
20 dnl 3. Neither the name of the author nor the names of any contributors
21 dnl    may be used to endorse or promote products derived from this
22 dnl    software without specific prior written permission.
23 dnl
24 dnl THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
25 dnl IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 dnl WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 dnl DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 dnl FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 dnl CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 dnl SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31 dnl BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 dnl WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33 dnl OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
34 dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 dnl
36 dnl This file is part of SXEmacs.
37
38
39 ## C compiler
40 AC_DEFUN([SXE_CHECK_CC_VERSION], [dnl
41         ## ---------------------------------------------------------------
42         ## Get version information for:
43         ## C compiler, libc
44         ## #### should do CC compiler, too, if different from SXEMACS_CC
45         ## ---------------------------------------------------------------
46
47         compiler_version=""
48         gcc_compiler_specs=""
49         AC_MSG_CHECKING([for compiler version information])
50
51         dnl First try portable compilers, then crack system secrets
52         dnl run through the AC_PROG_CC mill.
53         case "$(basename $CC)" in
54         dnl GNU cc compiler
55         gcc*)
56                 compiler_version=$($CC --version | head -1)
57                 gcc_compiler_specs=$($CC -v 2>&1 | sed 's/.* \([[^ ]]\)/\1/' | head -1)
58                 ;;
59         dnl The Intel cc compiler
60         ic*)
61                 compiler_version=$($CC -V 2>&1 | head -1)
62                 ;;
63         dnl a generic thing called `cc', we just hope that it accepts --version
64         cc*)
65                 compiler_version=$($CC --version 2>&1 | head -1)
66                 ;;
67         dnl non-gcc machine-specific magic - contributions welcome
68         *)
69                 case "$ac_cv_build" in
70                 *-*-aix*   )
71                         dnl Yes, it's this ugly for AIX...
72                         realcc=`which $SXEMACS_CC`
73                         dnl Might be a symlink created by replaceCset command
74                         if test -L $realcc ; then
75                                 ccdir=`dirname $realcc`
76                                 ccprog=`/bin/ls -l $realcc | sed 's/.* \([[^ ]]\)/\1/'`
77                                 dnl This doesn't handle ../../xlc type
78                                 dnl stuff, but I've not seen one...
79                                 case $ccprog in
80                                 */*)
81                                         realcc=$ccprog
82                                         ;;
83                                 *)
84                                         realcc=$ccdir/$ccprog
85                                         ;;
86                                 esac
87                         fi
88                         lpp=`lslpp -wqc $realcc | cut -f2 -d:`
89                         if test ! -z "$lpp" ; then
90                                 lppstr=`lslpp -Lqc $lpp`
91                                 lpplev=`echo "$lppstr" | cut -f3 -d:`
92                                 lppdesc=`echo "$lppstr" | cut -f8 -d:`
93                         fi
94                         if test ! -z "$lpplev" ; then
95                                 compiler_version="$lpp $lpplev - $lppdesc"
96                         fi
97                         ;;
98
99                 *-*-solaris*)
100                         compiler_version=`$SXEMACS_CC -V 2>&1 | head -1`
101                         ;;
102
103                 alpha*-dec-osf*)
104                         compiler_version=`$SXEMACS_CC -V | tr '\n' ' '`
105                         ;;
106
107                 mips-sgi-irix*)
108                         compiler_version=`$SXEMACS_CC -version`
109                         ;;
110                 *)
111                         compiler_version=""
112                         AC_MSG_RESULT([detection failed (please report this)])
113                         AC_MSG_WARN([No C compiler available nor specified])
114                         ;;
115                 esac
116                 ;;
117         esac
118
119         AC_SUBST([compiler_version])
120         AC_MSG_RESULT([$compiler_version])
121
122         dnl Awww, shucks.
123         if test -z "$compiler_version"; then
124                 compiler_version="detection failed (please report this)"
125         fi
126 ])dnl SXE_CHECK_CC_VERSION
127
128 AC_DEFUN([SXE_CHECK_CC__FGNU89_INLINE], [dnl
129         ## defines sxe_cc__fgnu89_inline
130         AC_MSG_CHECKING([whether $CC supports -fgnu89-inline])
131         SXE_DUMP_LIBS
132         SXE_LANG_WERROR([on])
133         CC="$CC -fgnu89-inline"
134         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]])],
135                 [sxe_cc__fgnu89_inline="yes"],
136                 [sxe_cc__fgnu89_inline="no"])
137         SXE_RESTORE_LIBS
138         AC_MSG_RESULT([$sxe_cc__fgnu89_inline])
139         AC_DEFUN([SXE_CHECK_CC__FGNU89_INLINE], [])
140 ])dnl SXE_CHECK_CC__FGNU89_INLINE
141
142 AC_DEFUN([SXE_CHECK_CC_GNU89_EXTERN_INLINE], [dnl
143         ## defines sxe_cc_gnu89_extern_inline
144         AC_MSG_CHECKING([whether $CC supports `extern inline'])
145         SXE_DUMP_LIBS
146         SXE_LANG_WERROR([off])
147         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
148 extern inline void
149 foobar(void)
150 {
151         return;
152 }
153                 ]])],
154                 [sxe_cc_gnu89_extern_inline="yes"],
155                 [sxe_cc_gnu89_extern_inline="no"])
156         SXE_RESTORE_LIBS
157
158         AC_MSG_RESULT([$sxe_cc_gnu89_extern_inline])
159 ])dnl SXE_CHECK_CC_GNU89_EXTERN_INLINE
160
161 AC_DEFUN([SXE_CHECK_CC_EXTERN_INLINE_DARWIN], [
162         AC_MSG_CHECKING([whether $CC supports `extern inline'])
163
164         case "$compiler_version" in
165         gcc*\ 4.0.1* | * )
166                 # For now we assume all MacOS compilers
167                 # are not able to handle EXTERN_INLINE
168                 AC_DEFINE([SXE_STATIC_EXTERN_INLINE], [1],
169                         [The MacOS gcc does not support extern inline])
170                 sxe_cc_gnu89_extern_inline="no"
171                 ;;
172         esac
173
174         AC_MSG_RESULT([$sxe_cc_gnu89_extern_inline])
175 ])dnl SXE_CHECK_CC_EXTERN_INLINE_DARWIN
176
177
178 AC_DEFUN([SXE_CHECK_CC_GNU89_EXTERN_INLINE_ALLERGY], [dnl
179         ## defines sxe_cc_gnu89_extern_inline_allergy
180         AC_MSG_CHECKING([whether $CC is allergic against gnu89 `extern inline' in C99])
181         SXE_DUMP_LIBS
182         SXE_LANG_WERROR([on])
183         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
184 extern inline void
185 foobar(void)
186 {
187         return;
188 }
189                 ]])],
190                 [sxe_cc_gnu89_extern_inline_allergy="no"],
191                 [sxe_cc_gnu89_extern_inline_allergy="yes"])
192         SXE_RESTORE_LIBS
193         AC_MSG_RESULT([$sxe_cc_gnu89_extern_inline_allergy])
194 ])dnl SXE_CHECK_CC_GNU89_EXTERN_INLINE_ALLERGY
195
196 AC_DEFUN([SXE_CHECK_CC___ATTRIBUTE__GNU_INLINE], [dnl
197         ## defines sxe_cc___attribute__gnu_inline
198
199         AC_MSG_CHECKING([whether attribute `gnu_inline' is an efficacious medicine])
200         SXE_DUMP_LIBS
201         SXE_LANG_WERROR([on])
202         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
203 extern inline void
204 __attribute__((gnu_inline))
205 foobar(void)
206 {
207         return;
208 }
209                 ]])],
210                 [sxe_cc___attribute__gnu_inline="yes"],
211                 [sxe_cc___attribute__gnu_inline="no"])
212         SXE_RESTORE_LIBS
213         AC_MSG_RESULT([$sxe_cc___attribute__gnu_inline])
214 ])dnl SXE_CHECK_CC___ATTRIBUTE__GNU_INLINE
215
216 AC_DEFUN([_SXE_CHECK_CC__FGNU89_INLINE_MEDICINE], [dnl
217         mytmp_save_CC="$CC"
218         CC="$CC -fgnu89-inline"
219         save_sxe_cc_blabla="$sxe_cc_gnu89_extern_inline_allergy"
220         SXE_CHECK_CC_GNU89_EXTERN_INLINE_ALLERGY
221         if test "$save_sxe_cc_blabla" = "yes" -a \
222                 "$sxe_cc_gnu89_extern_inline_allergy" = "no"; then
223                 sxe_cc__fgnu89_inline_medicine="yes"
224         else
225                 sxe_cc__fgnu89_inline_medicine="no"
226         fi
227         CC="$mytmp_save_CC"
228         sxe_cc_gnu89_extern_inline_allergy="$save_sxe_cc_blabla"
229         AC_MSG_CHECKING([whether flag -fgnu89-inline has been an efficacious medicine])
230         AC_MSG_RESULT([$sxe_cc__fgnu89_inline_medicine])
231 ])dnl _SXE_CHECK_CC__FGNU89_INLINE_MEDICINE
232
233 AC_DEFUN([SXE_CHECK_CC__FGNU89_INLINE_MEDICINE], [dnl
234         ## defines sxe_cc__fgnu89_inline_medicine
235         AC_REQUIRE([SXE_CHECK_CC__FGNU89_INLINE])
236         AC_MSG_CHECKING([whether flag -fgnu89-inline is an efficacious medicine])
237         if test "$sxe_cc__fgnu89_inline" = "yes"; then
238                 AC_MSG_RESULT([])
239                 _SXE_CHECK_CC__FGNU89_INLINE_MEDICINE
240         else
241                 sxe_cc__fgnu89_inline_medicine="no"
242                 AC_MSG_RESULT([$sxe_cc__fgnu89_inline_medicine])
243         fi
244 ])dnl SXE_CHECK_CC__FGNU89_INLINE_MEDICINE
245
246 AC_DEFUN([SXE_CHECK_CC_GNU89_EXTERN_INLINE_MEDICINE], [dnl
247         ## check if we have a medicine against it
248         ## defines gnu89_extern_inline_medicine
249         AC_REQUIRE([SXE_CHECK_CC__FGNU89_INLINE])
250         if test "$sxe_cc_gnu89_extern_inline" = "yes" -a \
251                 "$sxe_cc_gnu89_extern_inline_allergy" = "yes"; then
252                 SXE_CHECK_CC___ATTRIBUTE__GNU_INLINE
253                 SXE_CHECK_CC__FGNU89_INLINE_MEDICINE
254         fi
255         if test "$sxe_cc__fgnu89_inline_medicine" = "yes"; then
256                 CC="$CC -fgnu89-inline"
257         elif test "$sxe_cc__fgnu89_inline" = "yes"; then
258                 ## use gnu89-inline anyway
259                 ## this is to cope with gcc 4.3.0 which seems to support
260                 ## real C99 extern inlines, which in turn would break
261                 ## our build as we paid no heed at this (yet)
262                 CC="$CC -fgnu89-inline"
263         fi
264 ])dnl SXE_CHECK_CC_GNU89_EXTERN_INLINE_MEDICINE
265
266 AC_DEFUN([SXE_CHECK_CC_EXTERN_INLINE], [dnl
267
268         case "$ac_cv_build" in
269         *-*-darwin* )
270                 ## don't bother at all ... just invoke the darwin handler
271                 SXE_CHECK_CC_EXTERN_INLINE_DARWIN
272                 ;;
273         *)
274                 ## we simply presume that extern inline is possible first
275                 SXE_CHECK_CC_GNU89_EXTERN_INLINE
276                 ## check if gcc dislikes gnu89 inlines in c99
277                 SXE_CHECK_CC_GNU89_EXTERN_INLINE_ALLERGY
278                 ## generally check if we support -fgnu89-inline
279                 SXE_CHECK_CC__FGNU89_INLINE
280         esac
281
282         if test "$sxe_cc_gnu89_extern_inline" = "yes" -a \
283                 "$sxe_cc_gnu89_extern_inline_allergy" = "yes"; then
284                 SXE_CHECK_CC_GNU89_EXTERN_INLINE_MEDICINE
285         elif test "$sxe_cc__fgnu89_inline" = "yes"; then
286                 ## use gnu89-inline anyway
287                 ## this is to cope with gcc 4.3.0 which seems to support
288                 ## real C99 extern inlines, which in turn would break
289                 ## our build as we paid no heed at this (yet)
290                 CC="$CC -fgnu89-inline"
291         fi
292 ])dnl SXE_CHECK_CC_EXTERN_INLINE
293
294 AC_DEFUN([SXE_CHECK_CC_CHAR], [dnl
295
296         ## ----------------------------------------------------------------
297         ## Checking for gnuc va list need in solaris
298         ## ----------------------------------------------------------------
299         if test "$GCC" = "yes" -a "$opsys" = "sol2" ; then
300                 AC_MSG_CHECKING(for need to define gnuc_va_list)
301                 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
302 #include <stdarg.h>
303 #define __GNUC_VA_LIST
304 #define _VA_LIST_
305 #define _VA_LIST va_list
306 typedef void *__gnuc_va_list;
307 typedef __gnuc_va_list va_list;]],[[1]])], [dnl
308                 AC_MSG_RESULT(yes)
309                 AC_DEFINE([NEED_GNUC_VA_LIST], [1], [Description here!])], [dnl
310                 AC_MSG_RESULT(no)])
311         fi
312
313         AC_C_BIGENDIAN
314         AC_C_VOLATILE
315         AC_C_CONST
316         AC_C_INLINE
317         SXE_C_TYPEOF
318         AC_C_CHAR_UNSIGNED
319         AC_TYPE_LONG_DOUBLE  dnl only in >= 2.60
320         AC_TYPE_LONG_DOUBLE_WIDER  dnl only in >= 2.60
321         AC_C_STRINGIZE
322         AC_C_PROTOTYPES
323
324         dnl in case we need the modules
325         SXE_LD_EXPORT_DYNAMIC
326         dnl in case compiler issues PIE by default which breaks pdump
327         SXE_LD_NO_PIE
328 ])dnl SXE_CHECK_CC_CHAR
329
330 AC_DEFUN([SXE_CHECK_CC_HACKS], [dnl
331
332         ## Identify compilers to enable compiler-specific hacks.
333         ## Add support for other compilers HERE!
334         ## GCC is already identified elsewhere.
335         AC_RUN_IFELSE([AC_LANG_SOURCE([[
336 int main ()
337 {
338 #if defined __SUNPRO_C
339         return 11;
340 #elif defined __DECC
341         return 12;
342 #elif defined __USLC__ && defined __SCO_VERSION__
343         return 13;
344 #elif defined __INTEL_COMPILER
345         return 14;
346 #else
347         return 0;
348 #endif
349 }]])], [], [dnl
350         case "$?" in
351         11)
352                 echo "You appear to be using the SunPro C compiler."
353                 __SUNPRO_C=yes
354                 ;;
355         12)
356                 echo "You appear to be using the DEC C compiler."
357                 __DECC=yes
358                 ;;
359         13)
360                 echo "You appear to be using the SCO C compiler."
361                 __USLC__=yes
362                 ;;
363         14)
364                 echo "You appear to be using the Intel C++ compiler."
365                 __ICC=yes
366                 ## Newer versions of icc claim to be GCC
367                 GCC=no
368                 ;;
369         esac], [AS_MESSAGE([cannot cross-compile])])
370 ])dnl SXE_CHECK_CC_HACKS
371
372
373 AC_DEFUN([SXE_DO_CC_HACKS], [dnl
374         ## -----------------------
375         ## Compiler-specific hacks
376         ## -----------------------
377
378         dnl DEC C `-std1' means ANSI C mode
379         if test "$__DECC" = "yes"; then
380                 SXE_APPEND_UNDUP([-std1], [CFLAGS])
381         fi
382
383         dnl Some versions of SCO native compiler need -Kalloca
384         if test "$__USLC__" = yes; then
385                 AC_MSG_CHECKING([whether the -Kalloca compiler flag is needed])
386                 need_kalloca=no
387                 AC_LINK_IFELSE([AC_LANG_SOURCE([[void *x = alloca(4);]])], [:], [
388                         SXE_DUMP_LIBS
389                         CFLAGS="$CFLAGS -Kalloca"
390                         AC_LINK_IFELSE([AC_LANG_SOURCE([[void *x = alloca(4);]])],
391                                 [ need_kalloca=yes ])
392                         SXE_RESTORE_LIBS])
393                 AC_MSG_RESULT([$need_kalloca])
394                 if test "$need_kalloca" = "yes"; then
395                         SXE_APPEND_UNDUP([-Kalloca], [c_switch_system])
396                         SXE_APPEND_UNDUP([-Kalloca], [CFLAGS])
397                 fi
398         fi
399
400         dnl Die if g++
401         if test "$CC" = "g++" -o "$SXE_CC" = "g++" ; then
402                 SXE_DIE("Building with g++ is not supported")
403         fi
404
405
406 ])dnl SXE_DO_CC_HACKS
407
408 AC_DEFUN([SXE_CHECK_CC_NESTED_FUNS], [dnl
409         ## defines HAVE_NESTED_FUNS
410
411         AC_MSG_CHECKING([whether functions can be nested])
412         _SXE_CHECK_CC_NESTED_FUNS
413         AC_MSG_RESULT([$sxe_cv_c_nested_funs])
414
415         if test "$sxe_cv_c_nested_funs" != "yes"; then
416                 ## in this case we check if we can do with -fnested-functions
417                 SXE_CHECK_COMPILER_FLAGS([-fnested-functions])
418                 if test "$sxe_cv_c_flags__fnested_functions" = "yes"; then
419                         AC_MSG_CHECKING([whether functions can be nested now])
420                         _SXE_CHECK_CC_NESTED_FUNS([-fnested-functions])
421                         AC_MSG_RESULT([$sxe_cv_c_nested_funs])
422                 fi
423         fi
424
425         if test "$sxe_cv_c_nested_funs" = "yes"; then
426                 AC_DEFINE([HAVE_NESTED_FUNS], [1], [Whether funs can be nested])
427         else
428                 AC_MSG_WARN([Uh oh.])
429                 AC_MSG_WARN([A look into my crystal ball reveals a broken build.])
430                 AC_MSG_WARN([Get a compiler that is capable of nested functions.])
431         fi
432 ])dnl SXE_CHECK_CC_NESTED_FUNS
433
434 AC_DEFUN([_SXE_CHECK_CC_NESTED_FUNS], [dnl
435         ## defines sxe_cv_c_nested_funs
436         ## optional arg 1 may be additional CFLAGS
437         pushdef([ADDCFLAGS], [$1])
438
439         SXE_DUMP_LIBS
440         CFLAGS="${CFLAGS} []ADDCFLAGS[]"
441         AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
442                 /* we are in main now and we nest another function */
443                 auto inline int foobar();
444
445                 inline int foobar(int counter)
446                 {
447                         return counter;
448                 }
449
450                 return foobar(0);
451                 ]])],
452                 [sxe_cv_c_nested_funs="yes"],
453                 [sxe_cv_c_nested_funs="no"])
454         SXE_RESTORE_LIBS
455
456         popdef([ADDCFLAGS])
457 ])dnl _SXE_CHECK_CC_NESTED_FUNS
458
459
460 AC_DEFUN([SXE_CHECK_BROKEN_GCC], [
461 dnl This section needs a rewrite.  I think it should just bomb if we
462 dnl find a gcc that is older than 2.95.3 --SY.
463 dnl Search for GCC specific build problems we know about
464
465 AC_MSG_CHECKING([for buggy gcc versions])
466 GCC_VERSION=`$CC --version`
467
468 case $GCC_VERSION in
469 2.6.*|2.7.*|2.8.*|2.9* )
470         AC_MSG_RESULT([yes])
471         AC_MSG_WARN([Don't use medieval compilers])
472         AC_MSG_ERROR([Aborting due to known problem])
473         ;;
474 3.0.*|3.1.*|3.2.*|3.3.* )
475         AC_MSG_RESULT([yes])
476         AC_MSG_WARN([You are using an antiquated compiler. Proceed at your own risk.])
477         AC_MSG_CHECKING([for other known compiler bugs])
478         ;;
479 esac
480
481 case `uname -s`:`uname -m`:$GCC_VERSION in
482 dnl pie-enabled GCC on Linux needs -nopie to build SXEmacs
483 Linux:i?86:gcc*pie-*)
484         ;;
485
486 dnl egcs 2.90.21 (egcs-1.00 release)
487 dnl egcs 2.90.29 (egcs-1.0.3 release)
488 *:sun4*:2.8.1|*:sun4*:egcs-2.90.*)
489 dnl Don't use -O2 with gcc 2.8.1 and egcs 1.0 under SPARC architectures
490 dnl without also using `-fno-schedule-insns'.
491         case "$CFLAGS" in
492         *-O2*|*-O3*)
493                 case "$CFLAGS" in
494                 *-fno-schedule-insns*)
495                         ;;
496                 *)
497                         AC_MSG_RESULT([yes])
498                         AC_MSG_WARN([Don't use -O2 with gcc 2.8.1 and egcs 1.0 under SPARC architectures])
499                         AC_MSG_WARN([without also using -fno-schedule-insns.])
500                         AC_MSG_ERROR([Aborting due to known problem])
501                         ;;
502                 esac
503                 ;;
504         esac
505         ;;
506
507 dnl egcs-2.91.57 (egcs-1.1 release)
508 dnl egcs-2.91.66 (egcs-1.1.2 release)
509 Linux:alpha:egcs-2.91.*)
510         AC_MSG_RESULT([yes])
511         AC_MSG_WARN([There have been reports of egcs-1.1 not compiling SXEmacs correctly on])
512         AC_MSG_WARN([Alpha Linux.  There have also been reports that egcs-1.0.3a is O.K.])
513         AC_MSG_ERROR([Aborting due to known problem])
514         ;;
515
516 *:*:* )
517         AC_MSG_RESULT([no])
518         ;;
519 esac
520 ])dnl SXE_CHECK_BROKEN_GCC
521
522
523 AC_DEFUN([SXE_DEBUGFLAGS], [dnl
524         ## distinguish between different compilers, no?
525         SXE_CHECK_COMPILER_FLAGS([-g])
526         SXE_CHECK_COMPILER_FLAGS([-g3])
527
528         AC_PATH_PROG([DBX], [dbx])
529         if test -n "$ac_cv_path_DBX"; then
530                 SXE_CHECK_COMPILER_FLAGS([-gstabs])
531                 SXE_CHECK_COMPILER_FLAGS([-gstabs3])
532                 SXE_CHECK_COMPILER_FLAGS([-gxcoff])
533                 SXE_CHECK_COMPILER_FLAGS([-gxcoff3])
534         fi
535
536         AC_PATH_PROG([GDB], [gdb])
537         if test -n "$ac_cv_path_GDB"; then
538                 SXE_CHECK_COMPILER_FLAGS([-ggdb])
539                 SXE_CHECK_COMPILER_FLAGS([-ggdb3])
540         fi
541
542         AC_PATH_PROG([SDB], [sdb])
543         if test -n "$ac_cv_path_SDB"; then
544                 SXE_CHECK_COMPILER_FLAGS([-gcoff])
545                 SXE_CHECK_COMPILER_FLAGS([-gcoff3])
546         fi
547
548         ## final evaluation
549         debugflags=""
550         ## gdb
551         if test "$sxe_cv_c_flags__ggdb3" = "yes"; then
552                 debugflags="$debugflags -ggdb3"
553         elif test "$sxe_cv_c_flags__ggdb" = "yes"; then
554                 debugflags="$debugflags -ggdb"
555         fi
556         ## stabs
557         if test "$sxe_cv_c_flags__gstabs3" = "yes"; then
558                 debugflags="$debugflags -gstabs3"
559         elif test "$sxe_cv_c_flags__gstabs" = "yes"; then
560                 debugflags="$debugflags -gstabs"
561         fi
562         ## coff
563         if test "$sxe_cv_c_flags__gcoff3" = "yes"; then
564                 debugflags="$debugflags -gcoff3"
565         elif test "$sxe_cv_c_flags__gcoff" = "yes"; then
566                 debugflags="$debugflags -gcoff"
567         fi
568         ## xcoff
569         if test "$sxe_cv_c_flags__gxcoff3" = "yes"; then
570                 debugflags="$debugflags -gxcoff3"
571         elif test "$sxe_cv_c_flags__gxcoff" = "yes"; then
572                 debugflags="$debugflags -gxcoff"
573         fi
574
575         if test -z "debugflags" -a \
576                 "$sxe_cv_c_flags__g" = "yes"; then
577                 debugflags="$debugflags -g"
578         fi
579
580         SXE_CHECK_COMPILER_FLAGS([-ftime-report])
581         SXE_CHECK_COMPILER_FLAGS([-fmem-report])
582         SXE_CHECK_COMPILER_FLAGS([-fvar-tracking])
583         SXE_CHECK_COMPILER_FLAGS([-save-temps])
584
585         #if test "$sxe_cv_c_flags__ggdb3" = "yes" -a \
586         #       "$sxe_cv_c_flags__fvar_tracking" = "yes"; then
587         #       debugflags="$debugflags -fvar-tracking"
588         #fi
589
590         AC_MSG_CHECKING([for preferred debugging flags])
591         AC_MSG_RESULT([${debugflags}])
592 ])dnl SXE_DEBUGFLAGS
593
594 AC_DEFUN([SXE_WARNFLAGS], [dnl
595         ## Calculate warning flags.  We separate the flags for warnings from
596         ## the other flags because we want to force the warnings to be seen
597         ## by everyone who doesn't specifically override them.
598
599         ## by default we want the -Wall level
600         SXE_CHECK_COMPILER_FLAGS([-Wall], [warnflags="-Wall"])
601
602         SXE_CHECK_COMPILER_FLAGS([-qinfo], [
603                 warnflags="${warnflags} -qinfo"])
604
605         ## Yuck, bad compares have been worth at
606         ## least 3 crashes!
607         ## Warnings about char subscripts are pretty
608         ## pointless, though,
609         ## and we use them in various places.
610         if test "${with_maximum_warning_output}" = "yes"; then
611                 SXE_CHECK_COMPILER_FLAGS([-Wsign-compare], [
612                         warnflags="$warnflags -Wsign-compare"])
613                 SXE_CHECK_COMPILER_FLAGS([-Wno-char-subscripts], [
614                         warnflags="$warnflags -Wno-char-subscripts"])
615                 SXE_CHECK_COMPILER_FLAGS([-Wundef], [
616                         warnflags="$warnflags -Wundef"])
617         fi
618
619         ## too much at the moment, we rarely define protos
620         #warnflags="$warnflags -Wmissing-prototypes -Wstrict-prototypes"
621         SXE_CHECK_COMPILER_FLAGS([-Wpacked], [
622                 warnflags="$warnflags -Wpacked"])
623
624         ## glibc is intentionally not `-Wpointer-arith'-clean.
625         ## Ulrich Drepper has rejected patches to fix
626         ## the glibc header files.
627         ## we dont care
628         SXE_CHECK_COMPILER_FLAGS([-Wpointer-arith], [
629                 warnflags="$warnflags -Wpointer-arith"])
630
631         SXE_CHECK_COMPILER_FLAGS([-Wshadow], [
632                 warnflags="$warnflags -Wshadow"])
633
634         ## our code lacks declarations almost all the time
635         SXE_CHECK_COMPILER_FLAGS([-Wmissing-declarations], [
636                 warnflags="$warnflags -Wmissing-declarations"])
637         SXE_CHECK_COMPILER_FLAGS([-Wmissing-prototypes], [
638                 warnflags="$warnflags -Wmissing-prototypes"])
639         SXE_CHECK_COMPILER_FLAGS([-Wbad-function-cast], [
640                 warnflags="$warnflags -Wbad-function-cast"])
641         SXE_CHECK_COMPILER_FLAGS([-Wcast-qual], [
642                 warnflags="$warnflags -Wcast-qual"])
643         SXE_CHECK_COMPILER_FLAGS([-Wcast-align], [
644                 warnflags="$warnflags -Wcast-align"])
645
646         ## too aggressive innit
647         if test "${with_maximum_warning_output}" = "yes"; then
648                 SXE_CHECK_COMPILER_FLAGS([-Winline], [
649                         warnflags="$warnflags -Winline"])
650         fi
651
652         ## warn about incomplete switches
653         if test "${with_maximum_warning_output}" = "yes"; then
654                 SXE_CHECK_COMPILER_FLAGS([-Wswitch], [
655                         warnflags="$warnflags -Wswitch"])
656                 SXE_CHECK_COMPILER_FLAGS([-Wswitch-default], [
657                         warnflags="$warnflags -Wswitch-default"])
658                 SXE_CHECK_COMPILER_FLAGS([-Wswitch-enum], [
659                         warnflags="$warnflags -Wswitch-enum"])
660         fi
661
662         ## Wunused's
663         if test "${with_maximum_warning_output}" = "yes"; then
664                 SXE_CHECK_COMPILER_FLAGS([-Wunused-function], [
665                         warnflags="$warnflags -Wunused-function"])
666                 SXE_CHECK_COMPILER_FLAGS([-Wunused-variable], [
667                         warnflags="$warnflags -Wunused-variable"])
668                 SXE_CHECK_COMPILER_FLAGS([-Wunused-parameter], [
669                         warnflags="$warnflags -Wunused-parameter"])
670                 SXE_CHECK_COMPILER_FLAGS([-Wunused-value], [
671                         warnflags="$warnflags -Wunused-value"])
672                 SXE_CHECK_COMPILER_FLAGS([-Wunused], [
673                         warnflags="$warnflags -Wunused"])
674         fi
675
676         ## icc
677         SXE_CHECK_COMPILER_FLAGS([-Wreorder], [
678                 warnflags="$warnflags -Wreorder"])
679         SXE_CHECK_COMPILER_FLAGS([-Wdeprecated], [
680                 warnflags="$warnflags -Wdeprecated"])
681         SXE_CHECK_COMPILER_FLAGS([-Wnopragma], [
682                 warnflags="$warnflags -Wnopragma"])
683
684         ## for upcoming libev support
685         ## libev is a warning emitting cow, the developers can't
686         ## be arsed to fix it, as it turns out
687         SXE_CHECK_COMPILER_FLAGS([-fno-strict-aliasing], [
688                 warnflags="$warnflags -fno-strict-aliasing"])
689
690         ## icc specific
691         SXE_CHECK_COMPILER_FLAGS([-diag-disable 10237], [dnl
692                 warnflags="${warnflags} -diag-disable 10237"], [
693                 SXE_CHECK_COMPILER_FLAGS([-wd 10237], [dnl
694                         warnflags="${warnflags} -wd 10237"])])
695
696         AC_MSG_CHECKING([for preferred warning flags])
697         AC_MSG_RESULT([${warnflags}])
698 ])dnl SXE_WARNFLAGS
699
700 AC_DEFUN([SXE_OPTIFLAGS], [dnl
701         optiflags=""
702         SXE_COMPILER_VENDOR
703
704         case $sxe_cv_c_compiler_vendor in
705         dnl (
706         dec)
707                 SXE_CC_MAXOPT_DEC
708                 ;;
709         dnl (
710         sun)
711                 SXE_CC_MAXOPT_SUN
712                 ;;
713         dnl (
714         hp)
715                 SXE_CC_MAXOPT_HP
716                 ;;
717         dnl (
718         ibm)
719                 SXE_CC_MAXOPT_IBM
720                 ;;
721         dnl (
722         intel)
723                 SXE_CC_MAXOPT_INTEL
724                 ;;
725         dnl (
726         gnu)
727                 SXE_CC_MAXOPT_GNU
728                 ;;
729         esac
730
731         AC_MSG_CHECKING([for preferred optimising flags])
732         AC_MSG_RESULT([$optiflags])
733         if test -z "$optiflags"; then
734                 echo ""
735                 echo "********************************************************"
736                 echo "* WARNING: Don't know the best CFLAGS for this system  *"
737                 echo "* Use ./configure CFLAGS=... to specify your own flags *"
738                 echo "* (otherwise, a default of CFLAGS=-O3 will be used)    *"
739                 echo "********************************************************"
740                 echo ""
741                 optiflags="-O3"
742         fi
743
744         SXE_CHECK_COMPILER_FLAGS([$optiflags], [:], [
745                 echo ""
746                 echo "********************************************************"
747                 echo "* WARNING: The guessed CFLAGS don't seem to work with  *"
748                 echo "* your compiler.                                       *"
749                 echo "* Use ./configure CFLAGS=... to specify your own flags *"
750                 echo "********************************************************"
751                 echo ""
752                 optiflags=""
753         ])
754 ])dnl SXE_OPTIFLAGS
755
756 AC_DEFUN([SXE_FEATFLAGS], [dnl
757         ## default flags for needed features
758
759         ## we need nested functions ... hm, i dont think we do
760         ## but it's always nice to have them
761         SXE_CHECK_COMPILER_FLAGS([-fnested-functions], [
762                 featflags="$featflags -fnested-functions"])
763
764         ## recent gentoos went ballistic again, they compile PIE gcc's
765         ## but there's no way to turn that misconduct off ...
766         ## however I've got one report about a working PIE build
767         ## we'll just check for -nopie here, if it works, we turn it on
768         ## (and hence PIE off) and hope bug 16 remains fixed
769         SXE_CHECK_COMPILER_FLAGS([-nopie],
770                 [featflags="$featflags -nopie"])
771
772         ## icc and gcc related
773         ## check if some stuff can be staticalised
774         ## actually requires SXE_WARNFLAGS so warnings would be disabled
775         ## that affect the outcome of the following tests
776         SXE_CHECK_COMPILER_FLAGS([-static-intel], [
777                 featflags="${featflags} -static-intel"
778                 XCCLDFLAGS="${XCCLDFLAGS} -static-intel"], [:], [${SXE_CFLAGS}])
779         SXE_CHECK_COMPILER_FLAGS([-static-libgcc], [
780                 featflags="${featflags} -static-libgcc"
781                 XCCLDFLAGS="${XCCLDFLAGS} -static-libgcc"], [:], [${SXE_CFLAGS}])
782
783         AC_SUBST([XCCLDFLAGS])
784 ])dnl SXE_FEATFLAGS
785
786
787 AC_DEFUN([SXE_COMPILER_VENDOR], [dnl
788 AC_CACHE_CHECK([for _AC_LANG compiler vendor],
789         sxe_cv_[]_AC_LANG_ABBREV[]_compiler_vendor,
790         [sxe_cv_[]_AC_LANG_ABBREV[]_compiler_vendor=unknown
791         # note: don't check for gcc first since some other compilers define __GNUC__
792         for ventest in \
793                 intel:__ICC,__ECC,__INTEL_COMPILER \
794                 ibm:__xlc__,__xlC__,__IBMC__,__IBMCPP__ \
795                 gnu:__GNUC__ sun:__SUNPRO_C,__SUNPRO_CC \
796                 hp:__HP_cc,__HP_aCC \
797                 dec:__DECC,__DECCXX,__DECC_VER,__DECCXX_VER \
798                 borland:__BORLANDC__,__TURBOC__ \
799                 comeau:__COMO__ \
800                 cray:_CRAYC \
801                 kai:__KCC \
802                 lcc:__LCC__ \
803                 metrowerks:__MWERKS__ \
804                 sgi:__sgi,sgi \
805                 microsoft:_MSC_VER \
806                 watcom:__WATCOMC__ \
807                 portland:__PGI; do
808
809                 vencpp="defined("$(echo \
810                         $ventest | cut -d: -f2 | sed "s/,/) || defined(/g")")"
811                 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[
812 #if !($vencpp)
813       thisisanerror;
814 #endif
815                         ])], [sxe_cv_]_AC_LANG_ABBREV[_compiler_vendor=$(echo $ventest | cut -d: -f1); break; ])
816         done
817         ])
818 ])dnl SXE_COMPILER_VENDOR
819
820
821 AC_DEFUN([SXE_CC_MAXOPT_DEC], [dnl
822         optiflags="-newc -w0 -O5 -ansi_alias -ansi_args -fp_reorder -tune host"
823         if test "$acx_maxopt_portable" = "no"; then
824                 optiflags="$optiflags -arch host"
825         fi
826 ])dnl SXE_CC_MAXOPT_DEC
827
828 AC_DEFUN([SXE_CC_MAXOPT_SUN], [dnl
829         optiflags="-native -fast -xO5 -dalign"
830         if test "$acx_maxopt_portable" = "yes"; then
831                 optiflags="$optiflags -xarch=generic"
832         fi
833 ])dnl SXE_CC_MAXOPT_SUN
834
835 AC_DEFUN([SXE_CC_MAXOPT_HP], [dnl
836         optiflags="+Oall +Optrs_ansi +DSnative"
837         if test "$acx_maxopt_portable" = "yes"; then
838                 optiflags="$optiflags +DAportable"
839         fi
840 ])dnl SXE_CC_MAXOPT_HP
841
842 AC_DEFUN([SXE_CC_MAXOPT_IBM], [dnl
843         if test "$acx_maxopt_portable" = "no"; then
844                 xlc_opt="-qarch=auto -qtune=auto"
845         else
846                 xlc_opt="-qtune=auto"
847         fi
848         SXE_CHECK_COMPILER_FLAGS([$xlc_opt],
849                 [optiflags="-O3 -qansialias -w $xlc_opt"],
850                 [optiflags="-O3 -qansialias -w"
851                 echo "******************************************************"
852                 echo "*  You seem to have the IBM  C compiler.  It is      *"
853                 echo "*  recommended for best performance that you use:    *"
854                 echo "*                                                    *"
855                 echo "*    CFLAGS=-O3 -qarch=xxx -qtune=xxx -qansialias -w *"
856                 echo "*                      ^^^        ^^^                *"
857                 echo "*  where xxx is pwr2, pwr3, 604, or whatever kind of *"
858                 echo "*  CPU you have.  (Set the CFLAGS environment var.   *"
859                 echo "*  and re-run configure.)  For more info, man cc.    *"
860                 echo "******************************************************"])
861 ])dnl SXE_CC_MAXOPT_IBM
862
863 AC_DEFUN([SXE_CC_MAXOPT_INTEL], [dnl
864         optiflags="-O3 -ansi_alias"
865         if test "$acx_maxopt_portable" = "no"; then
866                 icc_archflag=unknown
867                 icc_flags=""
868                 case "$host_cpu" in
869                 ## (
870                 i686*|x86_64*)
871                         # icc accepts gcc assembly syntax,
872                         # so these should work:
873                         SXE_CHECK_CPU_PC
874                         ;;
875                 esac
876                 if test "$icc_flags" != ""; then
877                         for flag in $icc_flags; do
878                                 SXE_CHECK_COMPILER_FLAGS([$flag],
879                                         [icc_archflag=$flag; break])
880                         done
881                 fi
882                 AC_MSG_CHECKING([for icc architecture flag])
883                 AC_MSG_RESULT([$icc_archflag])
884                 if test "$icc_archflag" != "unknown"; then
885                         optiflags="$optiflags $icc_archflag"
886                 fi
887         fi
888 ])dnl SXE_CC_MAXOPT_INTEL
889
890 AC_DEFUN([SXE_CC_MAXOPT_GNU], [dnl
891         ## default optimisation flags for gcc on all systems
892         ## this is the preferred compiler
893         optiflags="-O3"
894
895         AC_REQUIRE([SXE_CHECK_SIMD_EXTENSIONS])
896         optiflags="$optiflags $simdflags"
897
898         ## note that we enable "unsafe" fp optimisation with other compilers, too
899         SXE_CHECK_COMPILER_FLAGS([-ftree-vectorize],
900                 [optiflags="$optiflags -ftree-vectorize"])
901
902         ## check for -march and/or -mtune
903         SXE_GCC_ARCHFLAG([$acx_maxopt_portable])
904         optiflags="$optiflags $archflags"
905
906         ## a softer variant of omit-frame-pointer
907         SXE_CHECK_COMPILER_FLAGS([-momit-leaf-frame-pointer],
908                 [optiflags="$optiflags -momit-leaf-frame-pointer"])
909
910         ## check for openmp support
911         ## there are: -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp
912         SXE_CHECK_COMPILER_FLAGS([-fopenmp])
913
914         if test "$sxe_cv_c_flags__fopenmp" = "yes" -a "$with_omp"; then
915                 SXE_MSG_CHECKING([whether it is safe to use -fopenmp])
916                 case "$compiler_version" in
917                 gcc*\ 4.4.*)
918                         optiflags="$optiflags -fopenmp"
919                         sxe_cv_feat_omp="yes"
920                         SXE_MSG_RESULT([yes])
921                         ;;
922                 *)
923                         SXE_MSG_RESULT([no])
924                         ;;
925                 esac
926         fi
927
928         ## these belong to the corresponding MAXOPT macro
929 dnl     SXE_CHECK_COMPILER_FLAGS([-xopenmp], [
930 dnl             optiflags="$optiflags -xopenmp"
931 dnl             sxe_cv_feat_omp="yes"
932 dnl             ])
933 dnl     SXE_CHECK_COMPILER_FLAGS([-openmp], [
934 dnl             optiflags="$optiflags -openmp"
935 dnl             sxe_cv_feat_omp="yes"
936 dnl             ])
937 dnl     SXE_CHECK_COMPILER_FLAGS([-mp], [
938 dnl             optiflags="$optiflags -mp"
939 dnl             sxe_cv_feat_omp="yes"
940 dnl             ])
941 dnl     SXE_CHECK_COMPILER_FLAGS([-omp], [
942 dnl             optiflags="$optiflags -omp"
943 dnl             sxe_cv_feat_omp="yes"
944 dnl             ])
945 dnl     SXE_CHECK_COMPILER_FLAGS([-qsmp=omp], [
946 dnl             optiflags="$optiflags -qsmp=omp"
947 dnl             sxe_cv_feat_omp="yes"
948 dnl             ])
949         ## add -lgomp to ldflags
950         if test "$sxe_cv_feat_omp" = "yes"; then
951                 LDFLAGS="$LDFLAGS -lgomp"
952         fi
953
954         # -malign-double for x86 systems
955         SXE_CHECK_COMPILER_FLAGS([-malign-double])
956         ## won't add this one, since it is causing problems
957         ##      [optiflags="$optiflags -malign-double"])
958
959         ## would be nice to have this but it triggers too many
960         ## meaningless warnings
961 dnl     ## -fstrict-aliasing for gcc-2.95+
962 dnl     SXE_CHECK_COMPILER_FLAGS([-fstrict-aliasing],
963 dnl             [optiflags="$optiflags -fstrict-aliasing"])
964
965         SXE_CHECK_COMPILER_FLAGS([-fearly-inlining],
966                 [optiflags="$optiflags -fearly-inlining"])
967
968         SXE_CHECK_COMPILER_FLAGS([-fdelete-null-pointer-checks],
969                 [optiflags="$optiflags -fdelete-null-pointer-checks"])
970
971         SXE_CHECK_COMPILER_FLAGS([-fmodulo-sched],
972                 [optiflags="$optiflags -fmodulo-sched"])
973
974         SXE_CHECK_COMPILER_FLAGS([-fmudflap])
975         SXE_CHECK_COMPILER_FLAGS([-fmudflapth])
976         SXE_CHECK_COMPILER_FLAGS([-fmudflapir])
977         if test "$sxe_cv_c_flags__fmudflapth" -a \
978                 "$sxe_cv_c_flags__fmudflapir"; then
979                 ## preferred
980                 : ##optiflags="$optiflags -fmudflapth -fmudflapir"
981         elif test "$sxe_cv_c_flags__fmudflap" -a \
982                 "$sxe_cv_c_flags__fmudflapir"; then
983                 : ##optiflags="$optiflags -fmudflap -fmudflapir"
984         fi
985         SXE_CHECK_COMPILER_FLAGS([-fsection-anchors],
986                 [optiflags="$optiflags -fsection-anchors"])
987
988         SXE_CHECK_COMPILER_FLAGS([-fbranch-target-load-optimize])
989         SXE_CHECK_COMPILER_FLAGS([-fbranch-target-load-optimize2])
990         if test "$sxe_cv_c_flags__fbranch_target_load_optimize2" = "yes"; then
991                 optiflags="$optiflags -fbranch-target-load-optimize2"
992         elif test "$sxe_cv_c_flags__fbranch_target_load_optimize" = "yes"; then
993                 optiflags="$optiflags -fbranch-target-load-optimize"
994         fi
995
996         SXE_CHECK_COMPILER_FLAGS([-fgcse],
997                 [optiflags="$optiflags -fgcse"])
998         SXE_CHECK_COMPILER_FLAGS([-fgcse-lm],
999                 [optiflags="$optiflags -fgcse-lm"])
1000         SXE_CHECK_COMPILER_FLAGS([-fgcse-sm],
1001                 [optiflags="$optiflags -fgcse-sm"])
1002         SXE_CHECK_COMPILER_FLAGS([-fgcse-las],
1003                 [optiflags="$optiflags -fgcse-las"])
1004         SXE_CHECK_COMPILER_FLAGS([-fgcse-after-reload],
1005                 [optiflags="$optiflags -fgcse-after-reload"])
1006         SXE_CHECK_COMPILER_FLAGS([-funsafe-loop-optimizations],
1007                 [optiflags="$optiflags -funsafe-loop-optimizations"])
1008         SXE_CHECK_COMPILER_FLAGS([-funroll-loops],
1009                 [optiflags="$optiflags -funswitch-loops"])
1010         SXE_CHECK_COMPILER_FLAGS([-funswitch-loops],
1011                 [optiflags="$optiflags -funswitch-loops"])
1012         SXE_CHECK_COMPILER_FLAGS([-frename-registers],
1013                 [optiflags="$optiflags -frename-registers"])
1014
1015         ## maths speedup
1016         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations -fno-signaling-nans],
1017                 [optiflags="$optiflags -fno-signaling-nans"])
1018         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations -fno-trapping-math],
1019                 [optiflags="$optiflags -fno-trapping-math"])
1020         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations -fno-signed-zeros],
1021                 [optiflags="$optiflags -fno-signed-zeros"])
1022         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations -fassociative-math],
1023                 [optiflags="$optiflags -fassociative-math"])
1024         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations -fno-rounding-math],
1025                 [optiflags="$optiflags -fno-rounding-math"])
1026         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations -fno-math-errno],
1027                 [optiflags="$optiflags -fno-math-errno"])
1028         ## the same as the previous 5, but sometimes gcc doesn't know'em all
1029         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations],
1030                 [optiflags="$optiflags -funsafe-math-optimizations"])
1031         ## another of these
1032         SXE_CHECK_COMPILER_FLAGS([-ffast-math],
1033                 [optiflags="$optiflags -ffast-math"])
1034         ## and yet some more
1035         SXE_CHECK_COMPILER_FLAGS([-mrecip],
1036                 [optiflags="$optiflags -mrecip"])
1037         SXE_CHECK_COMPILER_FLAGS([-msahf],
1038                 [optiflags="$optiflags -msahf"])
1039
1040         SXE_CHECK_COMPILER_FLAGS([-minline-all-stringops],
1041                 [optiflags="$optiflags -minline-all-stringops"])
1042
1043 ])dnl SXE_CC_MAXOPT_GNU
1044
1045
1046 ##### http://autoconf-archive.cryp.to/ax_check_compiler_flags.html
1047 ## renamed the prefix to SXE_
1048 AC_DEFUN([SXE_CHECK_COMPILER_FLAGS], [dnl
1049 dnl SXE_CHECK_COMPILER_FLAGS(<FLAG>, <ACTION-IF-FOUND>, <ACTION-IF-NOT-FOUND>,
1050 dnl     <ADDITIONAL-FLAGS>)
1051         AC_MSG_CHECKING([whether _AC_LANG compiler accepts $1])
1052
1053         dnl Some hackery here since AC_CACHE_VAL can't handle a non-literal varname:
1054         SXE_LANG_WERROR([push+on])
1055         AS_LITERAL_IF([$1], [
1056                 AC_CACHE_VAL(AS_TR_SH(sxe_cv_[]_AC_LANG_ABBREV[]_flags_$1), [
1057                         sxe_save_FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
1058                         _AC_LANG_PREFIX[]FLAGS="$4 $1"
1059                         AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1060                                 AS_TR_SH(sxe_cv_[]_AC_LANG_ABBREV[]_flags_$1)="yes",
1061                                 AS_TR_SH(sxe_cv_[]_AC_LANG_ABBREV[]_flags_$1)="no")
1062                         _AC_LANG_PREFIX[]FLAGS=$sxe_save_FLAGS])], [
1063                 sxe_save_FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
1064                 _AC_LANG_PREFIX[]FLAGS="$4 $1"
1065                 AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1066                         eval AS_TR_SH(sxe_cv_[]_AC_LANG_ABBREV[]_flags_$1)="yes",
1067                         eval AS_TR_SH(sxe_cv_[]_AC_LANG_ABBREV[]_flags_$1)="no")
1068                 _AC_LANG_PREFIX[]FLAGS=$sxe_save_FLAGS])
1069         eval sxe_check_compiler_flags=$AS_TR_SH(sxe_cv_[]_AC_LANG_ABBREV[]_flags_$1)
1070         SXE_LANG_WERROR([pop])
1071
1072         AC_MSG_RESULT([$sxe_check_compiler_flags])
1073         if test "$sxe_check_compiler_flags" = "yes"; then
1074                 m4_default([$2], :)
1075         else
1076                 m4_default([$3], :)
1077         fi
1078 ])dnl SXE_CHECK_COMPILER_FLAGS
1079
1080
1081 AC_DEFUN([SXE_CHECK_COMPILER_XFLAG], [dnl
1082         ## if libtool then
1083         case "${LD}" in
1084         *"libtool"*)
1085                 SXE_CHECK_COMPILER_FLAGS([-XCClinker], [
1086                         XFLAG="-XCClinker"], [
1087                         XFLAG=""])
1088                 ;;
1089         *"ld"*)
1090                 ## no XFLAG needed
1091                 XFLAG=""
1092                 ;;
1093         *)
1094                 SXE_CHECK_COMPILER_FLAGS([-Xlinker], [
1095                         XFLAG="-Xlinker"], [
1096                         XFLAG=""])
1097                 ;;
1098         esac
1099 ])dnl SXE_CHECK_COMPILER_XFLAG
1100
1101
1102 AC_DEFUN([SXE_CHECK_CPU], [dnl
1103         case "$host_cpu" in
1104         dnl (
1105         i*86*|x86_64*)
1106                 ## pc-style hardware
1107                 SXE_CHECK_CPU_PC
1108                 ;;
1109         dnl (
1110         sparc*)
1111                 ## sparc stuff
1112                 SXE_CHECK_CPU_SPARC
1113                 ;;
1114         dnl (
1115         alpha*)
1116                 ## alpha cruft
1117                 SXE_CHECK_CPU_ALPHA
1118                 ;;
1119         dnl (
1120         powerpc*)
1121                 ## ya know what
1122                 SXE_CHECK_CPU_PPC
1123                 ;;
1124         esac
1125 ])dnl SXE_CHECK_CPU
1126
1127 AC_DEFUN([SXE_CHECK_CPU_SPARC], [dnl
1128         AC_PATH_PROG([PRTDIAG], [prtdiag], [prtdiag],
1129                 [$PATH:/usr/platform/`uname -i`/sbin/:/usr/platform/`uname -m`/sbin/])
1130         cputype=$((((grep cpu /proc/cpuinfo | cut -d: -f2) ; \
1131                 ($PRTDIAG -v |grep -i sparc) ; \
1132                 grep -i cpu "/var/run/dmesg.boot" ) | head -n 1) 2> /dev/null)
1133         cputype=$(echo "$cputype" | tr -d ' -' |tr $as_cr_LETTERS $as_cr_letters)
1134
1135         case "$cputype" in
1136         dnl (
1137         *ultrasparciv*)
1138                 sxe_gcc_arch="ultrasparc4 ultrasparc3 ultrasparc v9"
1139                 ;;
1140         dnl (
1141         *ultrasparciii*)
1142                 sxe_gcc_arch="ultrasparc3 ultrasparc v9"
1143                 ;;
1144         dnl (
1145         *ultrasparc*)
1146                 sxe_gcc_arch="ultrasparc v9"
1147                 ;;
1148         dnl (
1149         *supersparc*|*tms390z5[[05]]*)
1150                 sxe_gcc_arch="supersparc v8"
1151                 ;;
1152         dnl (
1153         *hypersparc*|*rt62[[056]]*)
1154                 sxe_gcc_arch="hypersparc v8"
1155                 ;;
1156         dnl (
1157         *cypress*)
1158                 sxe_gcc_arch=cypress
1159                 ;;
1160         esac
1161 ])dnl SXE_CHECK_CPU_SPARC
1162
1163 AC_DEFUN([SXE_CHECK_CPU_ALPHA], [dnl
1164         case "$host_cpu" in
1165         dnl (
1166         alphaev5)
1167                 sxe_gcc_arch="ev5"
1168                 ;;
1169         dnl (
1170         alphaev56)
1171                 sxe_gcc_arch="ev56"
1172                 ;;
1173         dnl (
1174         alphapca56)
1175                 sxe_gcc_arch="pca56 ev56"
1176                 ;;
1177         dnl (
1178         alphapca57)
1179                 sxe_gcc_arch="pca57 pca56 ev56"
1180                 ;;
1181         dnl (
1182         alphaev6)
1183                 sxe_gcc_arch="ev6"
1184                 ;;
1185         dnl (
1186         alphaev67)
1187                 sxe_gcc_arch="ev67"
1188                 ;;
1189         dnl (
1190         alphaev68)
1191                 sxe_gcc_arch="ev68 ev67"
1192                 ;;
1193         dnl (
1194         alphaev69)
1195                 sxe_gcc_arch="ev69 ev68 ev67"
1196                 ;;
1197         dnl (
1198         alphaev7)
1199                 sxe_gcc_arch="ev7 ev69 ev68 ev67"
1200                 ;;
1201         dnl (
1202         alphaev79)
1203                 sxe_gcc_arch="ev79 ev7 ev69 ev68 ev67"
1204                 ;;
1205         esac
1206 ])dnl SXE_CHECK_CPU_ALPHA
1207
1208 AC_DEFUN([SXE_CHECK_CPU_PPC], [dnl
1209         cputype=$(((grep cpu /proc/cpuinfo | head -n 1 | \
1210                 cut -d: -f2 | cut -d, -f1 | sed 's/ //g') ; \
1211                 /usr/bin/machine ; \
1212                 /bin/machine; \
1213                 grep CPU /var/run/dmesg.boot | \
1214                 head -n 1 | cut -d" " -f2) 2> /dev/null)
1215         cputype=$(echo $cputype | sed -e 's/ppc//g;s/ *//g')
1216
1217         case "$cputype" in
1218         dnl (
1219         *750*)
1220                 sxe_gcc_arch="750 G3"
1221                 ;;
1222         dnl (
1223         *740[[0-9]]*)
1224                 sxe_gcc_arch="$cputype 7400 G4"
1225                 ;;
1226         dnl (
1227         *74[[4-5]][[0-9]]*)
1228                 sxe_gcc_arch="$cputype 7450 G4"
1229                 ;;
1230         dnl (
1231         *74[[0-9]][[0-9]]*)
1232                 sxe_gcc_arch="$cputype G4"
1233                 ;;
1234         dnl (
1235         *970*)
1236                 sxe_gcc_arch="970 G5 power4"
1237                 ;;
1238         dnl (
1239         *POWER4*|*power4*|*gq*)
1240                 sxe_gcc_arch="power4 970"
1241                 ;;
1242         dnl (
1243         *POWER5*|*power5*|*gr*|*gs*)
1244                 sxe_gcc_arch="power5 power4 970"
1245                 ;;
1246         dnl (
1247         603ev|8240)
1248                 sxe_gcc_arch="$cputype 603e 603"
1249                 ;;
1250         dnl (
1251         *)
1252                 sxe_gcc_arch="$cputype"
1253                 ;;
1254         esac
1255         sxe_gcc_arch="$sxe_gcc_arch powerpc"
1256 ])dnl SXE_CHECK_CPU_PPC
1257
1258 AC_DEFUN([SXE_CHECK_CPU_PC], [dnl
1259         ## use cpuid codes,
1260         AC_REQUIRE([SXE_PROC_CPUID])
1261
1262         case "$sxe_cv_proc_cpuid_00000000" in
1263         dnl (
1264         *:756e6547:*:*)
1265                 ## Intel
1266                 case "$sxe_cv_proc_cpuid_00000001" in
1267                 dnl (
1268                 *5[[48]]?:*:*:*)
1269                         sxe_gcc_arch="pentium-mmx pentium"
1270                         ;;
1271                 dnl (
1272                 *5??:*:*:*)
1273                         sxe_gcc_arch="pentium"
1274                         ;;
1275                 dnl (
1276                 *6[[3456]]?:*:*:*)
1277                         sxe_gcc_arch="pentium2 pentiumpro"
1278                         ;;
1279                 dnl (
1280                 *6a?:*[[01]]:*:*)
1281                         sxe_gcc_arch="pentium2 pentiumpro"
1282                         ;;
1283                 dnl (
1284                 *6a?:*[[234]]:*:*)
1285                         sxe_gcc_arch="pentium3 pentiumpro"
1286                         icc_flags="-xK"
1287                         ;;
1288                 dnl (
1289                 *69?:*:*:*)
1290                         sxe_gcc_arch="pentium-m pentium3 pentiumpro"
1291                         icc_flags="-xK"
1292                         ;;
1293                 dnl (
1294                 *6d?:*:*:*)
1295                         sxe_gcc_arch="pentium-m pentium3 pentiumpro"
1296                         ;;
1297                 dnl (
1298                 *6[[78b]]?:*:*:*)
1299                         sxe_gcc_arch="pentium3 pentiumpro"
1300                         icc_flags="-xK"
1301                         ;;
1302                 dnl (
1303                 *6f?:*:*:*)
1304                         ## intel core 2 duo
1305                         sxe_gcc_arch="nocona pentium4 pentiumpro"
1306                         ## icc flags here
1307                         ## icc_flags="??"
1308                         ;;
1309                 dnl (
1310                 *6??:*:*:*)
1311                         sxe_gcc_arch="pentiumpro"
1312                         ;;
1313                 dnl (
1314                 *f3[[347]]:*:*:*|*f4[1347]:*:*:*)
1315                         icc_flags="-xP -xN -xW -xK"
1316                         case "$host_cpu" in
1317                         dnl (
1318                         x86_64*)
1319                                 sxe_gcc_arch="nocona pentium4 pentiumpro"
1320                                 ;;
1321                         dnl (
1322                         *)
1323                                 sxe_gcc_arch="prescott pentium4 pentiumpro"
1324                                 ;;
1325                         esac
1326                         ;;
1327                 dnl (
1328                 *f??:*:*:*)
1329                         icc_flags="-xN -xW -xK"
1330                         sxe_gcc_arch="pentium4 pentiumpro"
1331                         ;;
1332                 esac
1333                 ;;
1334         dnl (
1335         *:68747541:*:*)
1336                 ## AMD
1337                 case "$sxe_cv_proc_cpuid_00000001" in
1338                 dnl (
1339                 *5[[67]]?:*:*:*)
1340                         sxe_gcc_arch="k6"
1341                         ;;
1342                 dnl (
1343                 *5[[8d]]?:*:*:*)
1344                         sxe_gcc_arch="k6-2 k6"
1345                         ;;
1346                 dnl (
1347                 *5[[9]]?:*:*:*)
1348                         sxe_gcc_arch="k6-3 k6"
1349                         ;;
1350                 dnl (
1351                 *60?:*:*:*)
1352                         sxe_gcc_arch="k7"
1353                         ;;
1354                 dnl (
1355                 *6[[12]]?:*:*:*)
1356                         sxe_gcc_arch="athlon k7"
1357                         ;;
1358                 dnl (
1359                 *6[[34]]?:*:*:*)
1360                         sxe_gcc_arch="athlon-tbird k7"
1361                         ;;
1362                 dnl (
1363                 *67?:*:*:*)
1364                         sxe_gcc_arch="athlon-4 athlon k7"
1365                         ;;
1366                 dnl (
1367                 *6[[68a]]?:*:*:*)
1368                         case "$sxe_cv_proc_cpuid_80000006" in
1369                         dnl (
1370                         *:*:*[[1-9a-f]]??????:*) # (L2 = ecx >> 16) >= 256
1371                                 sxe_gcc_arch="athlon-xp athlon-4 athlon k7"
1372                                 ;;
1373                         dnl (
1374                         *)
1375                                 sxe_gcc_arch="athlon-4 athlon k7"
1376                                 ;;
1377                         esac
1378                         ;;
1379                 dnl (
1380                 *f[[4cef8b]]?:*:*:*)
1381                         sxe_gcc_arch="athlon64 k8"
1382                         ;;
1383                 dnl (
1384                 *f5?:*:*:*)
1385                         sxe_gcc_arch="opteron k8"
1386                         ;;
1387                 dnl (
1388                 *f7?:*:*:*)
1389                         sxe_gcc_arch="athlon-fx opteron k8"
1390                         ;;
1391                 dnl (
1392                 *f??:*:*:*)
1393                         sxe_gcc_arch="k8"
1394                         ;;
1395                 esac
1396                 ;;
1397         dnl (
1398         *:746e6543:*:*)
1399                 # IDT
1400                 case "$sxe_cv_proc_cpuid_00000001" in
1401                 dnl (
1402                 *54?:*:*:*)
1403                         sxe_gcc_arch="winchip-c6"
1404                         ;;
1405                 dnl (
1406                 *58?:*:*:*)
1407                         sxe_gcc_arch="winchip2"
1408                         ;;
1409                 dnl (
1410                 *6[[78]]?:*:*:*)
1411                         sxe_gcc_arch="c3"
1412                         ;;
1413                 dnl (
1414                 *69?:*:*:*)
1415                         sxe_gcc_arch="c3-2 c3"
1416                         ;;
1417                 esac
1418                 ;;
1419         esac
1420
1421         ## nothing found? => fallback
1422         if test -z "$sxe_gcc_arch"; then
1423                 ## apply a generic strategy
1424                 case "$host_cpu" in
1425                 i586*)
1426                         sxe_gcc_arch="pentium"
1427                         ;;
1428                 i686*)
1429                         sxe_gcc_arch="pentiumpro"
1430                         ;;
1431                 esac
1432         fi
1433 ])dnl SXE_CHECK_CPU_PC
1434
1435
1436 AC_DEFUN([SXE_GCC_ARCHFLAG], [dnl
1437         AC_REQUIRE([AC_PROG_CC])
1438         AC_REQUIRE([AC_CANONICAL_HOST])
1439
1440         AC_ARG_WITH([gcc-arch], AS_HELP_STRING([--with-gcc-arch=<arch>], [
1441                         use architecture <arch> for gcc -march/-mtune,
1442                         instead of guessing]),
1443                 [sxe_gcc_arch=$withval], [sxe_gcc_arch=yes])
1444
1445         AC_MSG_CHECKING([for gcc architecture flag])
1446         AC_MSG_RESULT([])
1447         AC_CACHE_VAL([sxe_cv_gcc_archflag], [
1448                 ## initialise to unknown
1449                 sxe_cv_gcc_archflag="unknown"
1450
1451                 if test "$GCC" = yes; then
1452                         if test "$sxe_gcc_arch" = "yes" -a \
1453                                 "$cross_compiling" = "no"; then
1454                                 sxe_gcc_arch=""
1455                                 SXE_CHECK_CPU
1456                         fi
1457
1458                         if test -n "$sxe_gcc_arch" -a "$sxe_gcc_arch" != "no"; then
1459                                 for arch in $sxe_gcc_arch; do
1460                                         if test "[]m4_default([$1],yes)" = "yes"; then
1461                                                 ## if we require portable code
1462                                                 archflags="-mtune=$arch"
1463                                                 ## -mcpu=$arch and m$arch generate
1464                                                 ## nonportable code on every arch except
1465                                                 ## x86.  And some other arches
1466                                                 ## (e.g. Alpha) don't accept -mtune.
1467                                                 ## Grrr.
1468                                                 case "$host_cpu" in
1469                                                 dnl (
1470                                                 i*86|x86_64*)
1471                                                         archflags="$archflags -mcpu=$arch -m$arch"
1472                                                         ;;
1473                                                 esac
1474                                         else
1475                                                 archflags="-march=$arch -mcpu=$arch -m$arch"
1476                                         fi
1477                                         for flag in $archflags; do
1478                                                 SXE_CHECK_COMPILER_FLAGS([$flag],
1479                                                         [sxe_cv_gcc_archflag="$flag"; break])
1480                                         done
1481                                         if test "$sxe_cv_gcc_archflag" != "unknown"; then
1482                                                 break
1483                                         fi
1484                                 done
1485                         fi
1486                 fi
1487                 ])
1488
1489         AC_MSG_CHECKING([for gcc architecture flag])
1490         AC_MSG_RESULT([$sxe_cv_gcc_archflag])
1491         if test "$sxe_cv_gcc_archflag" = "unknown"; then
1492                 m4_default([$3],:)
1493         else
1494                 m4_default([$2], [archflags="$sxe_cv_gcc_archflag"])
1495         fi
1496 ])dnl SXE_GCC_ARCHFLAG
1497
1498
1499 #### http://autoconf-archive.cryp.to/sxe_check_define.html
1500 AC_DEFUN([SXE_CHECK_DEFINED], [dnl
1501         AS_VAR_PUSHDEF([ac_var],[ac_cv_defined_$2])dnl
1502
1503         AC_CACHE_CHECK([for $1 defined], ac_var,
1504                 AC_TRY_COMPILE($1,[
1505 #ifndef $2
1506 int ok;
1507 #else
1508 choke me
1509 #endif
1510                 ],
1511                 AS_VAR_SET(ac_var, [yes]),
1512                 AS_VAR_SET(ac_var, [no])))
1513
1514         AS_IF([test AS_VAR_GET(ac_var) != "no"], [$3], [$4])
1515         AS_VAR_POPDEF([ac_var])
1516 ])dnl SXE_CHECK_DEFINED
1517
1518 AC_DEFUN([SXE_CHECK_FUNC], [dnl
1519         AS_VAR_PUSHDEF([ac_var], [ac_cv_func_$2])dnl
1520         AC_CACHE_CHECK([for $2], ac_var, [
1521                 dnl AC_LANG_FUNC_LINK_TRY
1522                 AC_LINK_IFELSE([AC_LANG_PROGRAM([$1
1523 #undef $2
1524 char $2 ();
1525                         ], [
1526 char (*f) () = $2;
1527 return f != $2;
1528                         ])], [
1529                         AS_VAR_SET(ac_var, [yes])], [
1530                         AS_VAR_SET(ac_var, [no])])])
1531
1532         AS_IF([test AS_VAR_GET(ac_var) = "yes"], [$3], [$4])
1533         AS_VAR_POPDEF([ac_var])
1534 ])dnl SXE_CHECK_FUNC
1535
1536
1537
1538 AC_DEFUN([SXE_CHECK_C99_NJSF], [dnl
1539         dnl If we have a compiler that could do c99 do try to add the flag
1540         if test "$__GCC3" = "yes" ; then
1541                 SXE_APPEND_UNDUP("-std=c99", c_switch_site)
1542                 AC_MSG_CHECKING([for C99 support])
1543                 save_c_switch_site=$c_switch_site
1544                 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1545 #include <stdlib.h>
1546 ]],[[
1547 return 0;
1548 ]])],  [AC_MSG_RESULT(yes)
1549         have_c99="yes"],
1550        [c_switch_site=$sace_c_switch_site
1551                 AC_MSG_RESULT(no)
1552                 AC_MSG_WARN([C99 not supported, reverting option append])
1553                 have_c99="no"])
1554         elif test "$__SUNPRO_C" = "yes" ; then
1555                 AC_MSG_CHECKING([for C99 support])
1556                 save_c_switch_site=$c_switch_site
1557                 SXE_APPEND_UNDUP("-xc99", c_switch_site)
1558                 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1559 #include <stdlib.h>
1560 ]],[[
1561 return 0;
1562 ]])],  [AC_MSG_RESULT(yes)
1563                 have_c99="yes"],
1564        [c_switch_site=$sace_c_switch_site
1565                 AC_MSG_RESULT(no)
1566                 have_c99="no"])
1567         fi
1568 ])dnl SXE_CHECK_C99_NJSF
1569
1570
1571 AC_DEFUN([SXE_C_TYPEOF], [dnl
1572         dnl check for the typeof extension
1573         AC_MSG_CHECKING([for typeof])
1574         AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1575 int i; __typeof__(i) j;
1576 ]])], [typeofname="__typeof__"], [dnl else
1577                 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1578 int i; typeof(i) j;
1579 ]])], [typeofname="typeof"], [typeofname=no])])
1580         AC_MSG_RESULT([$typeofname])
1581         if test "$typeofname" != "no"; then
1582                 AC_DEFINE_UNQUOTED([TYPEOF], [$typeofname],
1583                         [How to use the typeof extension.])
1584         fi
1585 ])dnl SXE_C_TYPEOF
1586
1587 AC_DEFUN([SXE_C_INLINE], [dnl
1588         AC_C_INLINE
1589         if test "$ac_cv_c_inline" != "no" -a "$GCC" = "yes"; then
1590                 SXE_ADD_CRUFT_OBJS([inline.o])
1591         fi
1592 ])dnl SXE_C_INLINE
1593
1594
1595 AC_DEFUN([SXE_CHECK_BROKEN_RESTRICT], [dnl
1596         AC_MSG_CHECKING([support for restrict keyword])
1597         AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1598 extern void f(void*restrict[]);
1599 ]])], [have_restrict="yes"], [have_restrict="no"])
1600         if test "$have_restrict" = "no"; then
1601                 AC_DEFINE_UNQUOTED([restrict], [],
1602                         [Define restrict to nothing])
1603         fi
1604         AC_MSG_RESULT([$typeofname])
1605 ])dnl SXE_CHECK_BROKEN_RESTRICT
1606
1607 AC_DEFUN([SXE_STACK_FLAGS], [dnl
1608         ## actually this belongs to error-checking stuff
1609         SXE_CHECK_COMPILER_FLAGS([-fstack-protector])
1610         if test "${sxe_cv_c_flags__fstack_protector}" = "yes"; then
1611                 case "$opsys" in
1612                 freebsd)
1613                         diagflags="${diagflags} -fstack-protector"
1614                         ;;
1615                 *)
1616                         AC_CHECK_LIB([ssp], [__stack_chk_guard])
1617                         if test "${ac_cv_lib_ssp___stack_chk_guard}" = "yes"; then
1618                                 diagflags="${diagflags} -fstack-protector"
1619                         fi
1620                         ;;
1621                 esac
1622         fi
1623 ])dnl SXE_STACK_FLAGS
1624
1625 dnl recommended interface macros
1626 ## compiler wrapper
1627 AC_DEFUN([SXE_CHECK_CC], [dnl
1628
1629         AC_PROG_CPP
1630         AC_HEADER_STDC
1631         AC_PROG_CC([gcc icc cc])
1632         dnl AC_PROG_CC_STDC
1633         AC_PROG_CC_C99
1634
1635         ## check for machine and architecture
1636         SXE_CHECK_MACHARCH
1637
1638         ## check for C compiler characteristics
1639         SXE_CHECK_CC_VERSION
1640         if test "$GCC" = "yes"; then
1641                 SXE_CHECK_BROKEN_GCC
1642         fi
1643         AC_C_RESTRICT
1644         if test "$ac_cv_prog_cc_c99" != ""; then
1645                 SXE_CHECK_BROKEN_RESTRICT
1646         fi
1647
1648         ## check for libc
1649         SXE_CHECK_LIBC
1650         SXE_CHECK_LIBC_VERSION
1651         dnl Non-ordinary link usually requires -lc
1652         if test "$ordinary_link" = "no" -a -z "$libs_standard"; then
1653                 libs_standard="-lc"
1654         fi
1655
1656         SXE_CHECK_CC_HACKS
1657         SXE_CHECK_CC_CHAR
1658         SXE_CHECK_CC_NESTED_FUNS
1659
1660         ## Canonicalize the configuration name.
1661         ## Commented out, lets see if anything breaks. --SY.
1662         ## SXE_STRIP_4TH_COMPONENT(ac_cv_build_alias)
1663         ## SXE_STRIP_4TH_COMPONENT(ac_cv_build)
1664         AC_SUBST([configuration], [$ac_cv_build])
1665
1666         AM_PROG_CC_C_O
1667
1668 ])dnl SXE_CHECK_CC
1669
1670
1671 AC_DEFUN([SXE_CHECK_CFLAGS], [dnl
1672         dnl #### This may need to be overhauled so that all of SXEMACS_CC's flags
1673         dnl are handled separately, not just the xe_cflags_warning stuff.
1674
1675         ## diagnostic stuff and error checking
1676         ## this may somehow be in contradiction to optimisation flags later on
1677         ## so we issue the tests right here
1678         if test "${with_error_checking_stack}" = "yes"; then
1679                 SXE_STACK_FLAGS
1680         fi
1681         if test "${with_error_checking_malldbg}" = "yes"; then
1682                 ## keep MALLOC_PERTURB_ and friends?
1683                 :
1684         else
1685                 EXTRA_BATCHENV="MALLOC_PERTURB_= MALLOC_CHECK_="
1686                 AC_SUBST([EXTRA_BATCHENV])
1687         fi
1688         SXE_CFLAGS="${SXE_CFLAGS} ${diagflags}"
1689
1690         ## Use either command line flag, environment var, or autodetection
1691         if test "$with_ridiculously_aggressive_optimisations" = "yes"; then
1692                 CFLAGS=""
1693                 SXE_DEBUGFLAGS
1694                 SXE_WARNFLAGS
1695                 SXE_OPTIFLAGS
1696                 SXE_CFLAGS="$SXE_CFLAGS $debugflags $optiflags $warnflags"
1697
1698                 SXE_FEATFLAGS
1699                 SXE_CFLAGS="$SXE_CFLAGS $featflags"
1700
1701         elif test "$CFLAGS_uspecified_p" = "no" -o \
1702                 "$ac_test_CFLAGS" != "set"; then
1703                 SXE_DEBUGFLAGS
1704                 SXE_WARNFLAGS
1705
1706                 ## the old settings
1707                 ## Following values of CFLAGS are known to work well.
1708                 ## Should we take debugging options into consideration?
1709                 SXE_CHECK_COMPILER_FLAGS([-xO4], [dnl
1710                         ## ah, it's sunos4*
1711                         optiflags="${optiflags} -xO4"], [dnl
1712                         SXE_CHECK_COMPILER_FLAGS([-xO2], [dnl
1713                                 ## oh, a sol2
1714                                 optiflags="${optiflags} -xO2"])])
1715                 SXE_CHECK_COMPILER_FLAGS([-O3], [dnl
1716                         ## gcc, icc, decc, et al.
1717                         optiflags="${optiflags} -O3"])
1718
1719                 ## xlc specific
1720                 SXE_CHECK_COMPILER_FLAGS([-qnoansialias -qlibansi], [dnl
1721                         optiflags="${optiflags} -qnoansialias -qlibansi"])
1722                 SXE_CHECK_COMPILER_FLAGS([-qro -qmaxmem=20000], [dnl
1723                         optiflags="${optiflags} -qro -qmaxmem=20000"])
1724
1725                 ## icc specific
1726                 SXE_CHECK_COMPILER_FLAGS([-inline-level=2], [dnl
1727                         ## ah, one of the new flavours, tasty
1728                         optiflags="${optiflags} -inline-level=2"], [dnl
1729                         SXE_CHECK_COMPILER_FLAGS([-Ob2], [dnl
1730                                 ## deprecated nowadays
1731                                 optiflags="${optiflags} -Ob2"])])
1732
1733                 ## final check
1734                 if test -z "${optiflags}"; then
1735                         SXE_CHECK_COMPILER_FLAGS([-O], [dnl
1736                                 ## The only POSIX-approved flag
1737                                 optiflags="-O"])
1738                 fi
1739
1740                 SXE_CFLAGS="$SXE_CFLAGS $debugflags $optiflags $warnflags"
1741
1742                 SXE_FEATFLAGS
1743                 SXE_CFLAGS="$SXE_CFLAGS $featflags"
1744         else
1745                 SXE_CFLAGS="${SXE_CFLAGS} ${USER_CFLAGS}"
1746                 featflags=""
1747                 debugflags=""
1748                 optiflags=""
1749                 warnflags=""
1750                 diagflags=""
1751         fi
1752
1753         ## unset the werror flag again
1754         SXE_LANG_WERROR([off])
1755
1756         CFLAGS="$SXE_CFLAGS"
1757         AC_MSG_CHECKING([for preferred CFLAGS])
1758         AC_MSG_RESULT([${SXE_CFLAGS}])
1759
1760         AC_MSG_NOTICE([
1761 If you wish to ADD your own flags you want to stop here and rerun the
1762 configure script like so:
1763   configure CFLAGS=<to-be-added-flags>
1764
1765 You can always override the determined CFLAGS, partially or totally,
1766 using
1767   make -C <directory> CFLAGS=<your-own-flags> [target]
1768 or
1769   make CFLAGS=<your-own-flags> [target]
1770 respectively
1771
1772 NOTE: -C <directory> option is not available on all systems
1773                 ])
1774 ])dnl SXE_CHECK_CFLAGS
1775
1776
1777 AC_DEFUN([SXE_CC_LIBRARY_PATH], [dnl
1778         ## arg #1 variable to store name in,
1779         ## if omitted defaults to `sxe_cv_tmp_gcc_library_path'
1780         pushdef([VAR], ifelse($1,[],[sxe_cv_tmp_gcc_library_path],$1))
1781
1782         for i in ${LDFLAGS}; do
1783                 case $i in
1784                 -L*)
1785                         __LP=${i:2}:${__LP:-.}
1786                         ;;
1787                 *)
1788                         ;;
1789                 esac
1790         done
1791         SXE_EXPAND_VAR([${libdir}], [__ld])
1792         []VAR[]=${__ld:-.}:${__LP:-.}
1793
1794         popdef([VAR])
1795 ])dnl SXE_CC_LIBRARY_PATH
1796
1797
1798 AC_DEFUN([SXE_CC_LIBRARY_LOCATION], [dnl
1799         ## arg #1 the library to seek after
1800         ## arg #2 (optional) checking message
1801         pushdef([liborig], [$1])
1802         pushdef([liblink], patsubst(patsubst(liborig, [lib], [-l]), [\.[^.]+$], []))
1803         pushdef([libname], translit(liborig, [-,.], [___]))
1804         pushdef([LIBNAME], translit(liborig, [-,.a-z], [___A-Z]))
1805         pushdef([libchk], ifelse($2,[],[for absolute path of ]liborig,$2))
1806
1807         ## use gcc's -print-file-name
1808         AC_REQUIRE([SXE_CC_LIBRARY_PATH])
1809         AC_MSG_CHECKING([]libchk[])
1810         ## not protected against other CCs (yet)!
1811         sxe_cv_loc_[]libname[]=$(LIBRARY_PATH=${sxe_cv_tmp_gcc_library_path} \
1812                 ${CC} -print-file-name=[]liborig[])
1813         AC_MSG_RESULT(${sxe_cv_loc_[]libname[]})
1814
1815         []LIBNAME[]=${sxe_cv_loc_[]libname[]}
1816
1817         popdef([libchk])
1818         popdef([liblink])
1819         popdef([liborig])
1820         popdef([libname])
1821         popdef([LIBNAME])
1822 ])dnl SXE_CC_LIBRARY_LOCATION
1823
1824
1825 AC_DEFUN([SXE_CHECK_ANON_STRUCTS], [
1826         AC_MSG_CHECKING([whether C compiler can cope with anonymous structures])
1827         AC_LANG_PUSH(C)
1828         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1829 union __test_u {
1830         int i;
1831         struct {
1832                 char c;
1833                 char padc;
1834                 short int pads;
1835         };
1836 };
1837         ]], [[
1838         union __test_u tmp = {.c = '4'};
1839         ]])], [
1840                 sxe_cv_have_anon_structs="yes"
1841         ], [
1842                 sxe_cv_have_anon_structs="no"
1843         ])
1844         AC_MSG_RESULT([${sxe_cv_have_anon_structs}])
1845
1846         if test "${sxe_cv_have_anon_structs}" = "yes"; then
1847                 AC_DEFINE([HAVE_ANON_STRUCTS], [1], [
1848                         Whether c1x anon structs work])
1849                 $1
1850                 :
1851         else
1852                 $2
1853                 :
1854         fi
1855         AC_LANG_POP()
1856 ])dnl SXE_CHECK_ANON_STRUCTS
1857
1858 dnl sxe-compiler.m4 ends here