Initial git import
[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
327         ## check whether CC reacts to `extern inline' gnu89 inline declarations
328         ## with a warning
329         SXE_CHECK_CC_EXTERN_INLINE
330 ])dnl SXE_CHECK_CC_CHAR
331
332 AC_DEFUN([SXE_CHECK_CC_HACKS], [dnl
333
334         ## Identify compilers to enable compiler-specific hacks.
335         ## Add support for other compilers HERE!
336         ## GCC is already identified elsewhere.
337         AC_RUN_IFELSE([AC_LANG_SOURCE([[
338 int main ()
339 {
340 #if defined __SUNPRO_C
341         return 11;
342 #elif defined __DECC
343         return 12;
344 #elif defined __USLC__ && defined __SCO_VERSION__
345         return 13;
346 #elif defined __INTEL_COMPILER
347         return 14;
348 #else
349         return 0;
350 #endif
351 }]])], [], [dnl
352         case "$?" in
353         11)
354                 echo "You appear to be using the SunPro C compiler."
355                 __SUNPRO_C=yes
356                 ;;
357         12)
358                 echo "You appear to be using the DEC C compiler."
359                 __DECC=yes
360                 ;;
361         13)
362                 echo "You appear to be using the SCO C compiler."
363                 __USLC__=yes
364                 ;;
365         14)
366                 echo "You appear to be using the Intel C++ compiler."
367                 __ICC=yes
368                 ## Newer versions of icc claim to be GCC
369                 GCC=no
370                 ;;
371         esac], [AS_MESSAGE([cannot cross-compile])])
372 ])dnl SXE_CHECK_CC_HACKS
373
374
375 AC_DEFUN([SXE_DO_CC_HACKS], [dnl
376         ## -----------------------
377         ## Compiler-specific hacks
378         ## -----------------------
379
380         dnl DEC C `-std1' means ANSI C mode
381         if test "$__DECC" = "yes"; then
382                 SXE_APPEND([-std1], [CFLAGS])
383         fi
384
385         dnl Some versions of SCO native compiler need -Kalloca
386         if test "$__USLC__" = yes; then
387                 AC_MSG_CHECKING([whether the -Kalloca compiler flag is needed])
388                 need_kalloca=no
389                 AC_LINK_IFELSE([AC_LANG_SOURCE([[void *x = alloca(4);]])], [:], [
390                         SXE_DUMP_LIBS
391                         CFLAGS="$CFLAGS -Kalloca"
392                         AC_LINK_IFELSE([AC_LANG_SOURCE([[void *x = alloca(4);]])],
393                                 [ need_kalloca=yes ])
394                         SXE_RESTORE_LIBS])
395                 AC_MSG_RESULT([$need_kalloca])
396                 if test "$need_kalloca" = "yes"; then
397                         SXE_APPEND([-Kalloca], [c_switch_system])
398                         SXE_APPEND([-Kalloca], [CFLAGS])
399                 fi
400         fi
401
402         ## Die if g++
403         if test "$CC" = "g++" -o "$SXE_CC" = "g++" ; then
404                 SXE_DIE("Building with g++ is not supported")
405         fi
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         ## If this stays nil, it will be set to warnflags before use.
603         dnl Following warning flags are known to work well.
604         if test "$__SUNPRO_C" = "yes"; then
605                 warnflags=""
606
607         elif test "$CC" = "xlc"; then
608                 warnflags="-qinfo"
609
610         elif test "$GCC" = "yes" -a \
611                 "$with_maximum_warning_output" = "yes"; then
612                 warnflags="-Wall"
613
614                 ## Yuck, bad compares have been worth at
615                 ## least 3 crashes!
616                 ## Warnings about char subscripts are pretty
617                 ## pointless, though,
618                 ## and we use them in various places.
619                 SXE_CHECK_COMPILER_FLAGS([-Wsign-compare], [
620                         warnflags="$warnflags -Wsign-compare"])
621                 SXE_CHECK_COMPILER_FLAGS([-Wno-char-subscripts], [
622                         warnflags="$warnflags -Wno-char-subscripts"])
623                 SXE_CHECK_COMPILER_FLAGS([-Wundef], [
624                         warnflags="$warnflags -Wundef"])
625
626                 ## too much at the moment, we rarely define protos
627                 #warnflags="$warnflags -Wmissing-prototypes -Wstrict-prototypes"
628                 SXE_CHECK_COMPILER_FLAGS([-Wpacked], [
629                         warnflags="$warnflags -Wpacked"])
630
631                 ## glibc is intentionally not `-Wpointer-arith'-clean.
632                 ## Ulrich Drepper has rejected patches to fix
633                 ## the glibc header files.
634                 ## we dont care
635                 SXE_CHECK_COMPILER_FLAGS([-Wpointer-arith], [
636                         warnflags="$warnflags -Wpointer-arith"])
637
638                 SXE_CHECK_COMPILER_FLAGS([-Wshadow], [
639                         warnflags="$warnflags -Wshadow"])
640
641                 ## our code lacks declarations almost all the time
642                 SXE_CHECK_COMPILER_FLAGS([-Wmissing-declarations], [
643                         warnflags="$warnflags -Wmissing-declarations"])
644
645                 case "$compiler_version" in
646                 gcc*\ 4.5.0*)
647                         ## gcc 4.5.0 cannot cope with -Winline
648                         ;;
649                 *)
650                         SXE_CHECK_COMPILER_FLAGS([-Winline], [
651                                 warnflags="$warnflags -Winline"])
652                         ;;
653                 esac
654
655                 SXE_CHECK_COMPILER_FLAGS([-Wbad-function-cast], [
656                         warnflags="$warnflags -Wbad-function-cast"])
657                 SXE_CHECK_COMPILER_FLAGS([-Wcast-qual], [
658                         warnflags="$warnflags -Wcast-qual"])
659                 SXE_CHECK_COMPILER_FLAGS([-Wcast-align], [
660                         warnflags="$warnflags -Wcast-align"])
661
662                 ## warn about incomplete switches
663                 SXE_CHECK_COMPILER_FLAGS([-Wswitch], [
664                         warnflags="$warnflags -Wswitch"])
665                 SXE_CHECK_COMPILER_FLAGS([-Wswitch-default], [
666                         warnflags="$warnflags -Wswitch-default"])
667                 SXE_CHECK_COMPILER_FLAGS([-Wswitch-enum], [
668                         warnflags="$warnflags -Wswitch-enum"])
669
670                 if test "$sxe_cv_c_flags__save_temps" = "yes"; then
671                         : ##warnflags="$warnflags -save-temps"
672                 fi
673
674                 ## for upcoming openmp support
675                 ## which is of course configurable but shut the compiler
676                 ## up in case we dont want/have omp, pragmas are a PITA
677                 SXE_CHECK_COMPILER_FLAGS([-Wnopragma], [
678                         warnflags="$warnflags -Wnopragma"])
679
680         elif test "$__ICC" = "yes" -a \
681                 "$with_maximum_warning_output" = "yes"; then
682                 SXE_CHECK_COMPILER_FLAGS([-Wunused-function], [
683                         warnflags="$warnflags -Wunused-function"])
684                 SXE_CHECK_COMPILER_FLAGS([-Wunused-variable], [
685                         warnflags="$warnflags -Wunused-variable"])
686                 SXE_CHECK_COMPILER_FLAGS([-Wunknown-pragmas], [
687                         warnflags="$warnflags -Wunknown-pragmas"])
688                 SXE_CHECK_COMPILER_FLAGS([-Wuninitialized], [
689                         warnflags="$warnflags -Wuninitialized"])
690                 SXE_CHECK_COMPILER_FLAGS([-Wshadow], [
691                         warnflags="$warnflags -Wshadow"])
692                 SXE_CHECK_COMPILER_FLAGS([-Wmissing-declarations], [
693                         warnflags="$warnflags -Wmissing-declarations"])
694                 SXE_CHECK_COMPILER_FLAGS([-Wmissing-prototypes], [
695                         warnflags="$warnflags -Wmissing-prototypes"])
696                 SXE_CHECK_COMPILER_FLAGS([-Wreorder], [
697                         warnflags="$warnflags -Wreorder"])
698                 SXE_CHECK_COMPILER_FLAGS([-Wdeprecated], [
699                         warnflags="$warnflags -Wdeprecated"])
700                 SXE_CHECK_COMPILER_FLAGS([-Wnopragma], [
701                         warnflags="$warnflags -Wnopragma"])
702         fi
703
704         ## for upcoming libev support
705         ## libev is a warning emitting cow, the developers can't
706         ## be arsed to fix it, as it turns out
707         SXE_CHECK_COMPILER_FLAGS([-fno-strict-aliasing], [
708                 warnflags="$warnflags -fno-strict-aliasing"])
709
710         AC_MSG_CHECKING([for preferred warning flags])
711         AC_MSG_RESULT([${warnflags}])
712 ])dnl SXE_WARNFLAGS
713
714 AC_DEFUN([SXE_OPTIFLAGS], [dnl
715         optiflags=""
716         SXE_COMPILER_VENDOR
717
718         case $sxe_cv_c_compiler_vendor in
719         dnl (
720         dec)
721                 SXE_CC_MAXOPT_DEC
722                 ;;
723         dnl (
724         sun)
725                 SXE_CC_MAXOPT_SUN
726                 ;;
727         dnl (
728         hp)
729                 SXE_CC_MAXOPT_HP
730                 ;;
731         dnl (
732         ibm)
733                 SXE_CC_MAXOPT_IBM
734                 ;;
735         dnl (
736         intel)
737                 SXE_CC_MAXOPT_INTEL
738                 ;;
739         dnl (
740         gnu)
741                 SXE_CC_MAXOPT_GNU
742                 ;;
743         esac
744
745         AC_MSG_CHECKING([for preferred optimising flags])
746         AC_MSG_RESULT([$optiflags])
747         if test -z "$optiflags"; then
748                 echo ""
749                 echo "********************************************************"
750                 echo "* WARNING: Don't know the best CFLAGS for this system  *"
751                 echo "* Use ./configure CFLAGS=... to specify your own flags *"
752                 echo "* (otherwise, a default of CFLAGS=-O3 will be used)    *"
753                 echo "********************************************************"
754                 echo ""
755                 optiflags="-O3"
756         fi
757         
758         SXE_CHECK_COMPILER_FLAGS([$optiflags], [:], [
759                 echo ""
760                 echo "********************************************************"
761                 echo "* WARNING: The guessed CFLAGS don't seem to work with  *"
762                 echo "* your compiler.                                       *"
763                 echo "* Use ./configure CFLAGS=... to specify your own flags *"
764                 echo "********************************************************"
765                 echo ""
766                 optiflags=""
767         ])
768 ])dnl SXE_OPTIFLAGS
769
770 AC_DEFUN([SXE_FEATFLAGS], [dnl
771         ## default flags for needed features
772
773         ## we need nested functions ... hm, i dont think we do
774         ## but it's always nice to have them
775         SXE_CHECK_COMPILER_FLAGS([-fnested-functions], [
776                 featflags="$featflags -fnested-functions"])
777
778         ## recent gentoos went ballistic again, they compile PIE gcc's
779         ## but there's no way to turn that misconduct off ...
780         ## however I've got one report about a working PIE build
781         ## we'll just check for -nopie here, if it works, we turn it on
782         ## (and hence PIE off) and hope bug 16 remains fixed
783         SXE_CHECK_COMPILER_FLAGS([-nopie],
784                 [featflags="$featflags -nopie"])
785
786 ])dnl SXE_FEATFLAGS
787
788
789 AC_DEFUN([SXE_COMPILER_VENDOR], [dnl
790 AC_CACHE_CHECK([for _AC_LANG compiler vendor],
791         sxe_cv_[]_AC_LANG_ABBREV[]_compiler_vendor,
792         [sxe_cv_[]_AC_LANG_ABBREV[]_compiler_vendor=unknown
793         # note: don't check for gcc first since some other compilers define __GNUC__
794         for ventest in \
795                 intel:__ICC,__ECC,__INTEL_COMPILER \
796                 ibm:__xlc__,__xlC__,__IBMC__,__IBMCPP__ \
797                 gnu:__GNUC__ sun:__SUNPRO_C,__SUNPRO_CC \
798                 hp:__HP_cc,__HP_aCC \
799                 dec:__DECC,__DECCXX,__DECC_VER,__DECCXX_VER \
800                 borland:__BORLANDC__,__TURBOC__ \
801                 comeau:__COMO__ \
802                 cray:_CRAYC \
803                 kai:__KCC \
804                 lcc:__LCC__ \
805                 metrowerks:__MWERKS__ \
806                 sgi:__sgi,sgi \
807                 microsoft:_MSC_VER \
808                 watcom:__WATCOMC__ \
809                 portland:__PGI; do
810
811                 vencpp="defined("$(echo \
812                         $ventest | cut -d: -f2 | sed "s/,/) || defined(/g")")"
813                 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[
814 #if !($vencpp)
815       thisisanerror;
816 #endif
817                         ])], [sxe_cv_]_AC_LANG_ABBREV[_compiler_vendor=$(echo $ventest | cut -d: -f1); break; ])
818         done
819         ])
820 ])dnl SXE_COMPILER_VENDOR
821
822
823 AC_DEFUN([SXE_CC_MAXOPT_DEC], [dnl
824         optiflags="-newc -w0 -O5 -ansi_alias -ansi_args -fp_reorder -tune host"
825         if test "$acx_maxopt_portable" = "no"; then
826                 optiflags="$optiflags -arch host"
827         fi
828 ])dnl SXE_CC_MAXOPT_DEC
829
830 AC_DEFUN([SXE_CC_MAXOPT_SUN], [dnl
831         optiflags="-native -fast -xO5 -dalign"
832         if test "$acx_maxopt_portable" = "yes"; then
833                 optiflags="$optiflags -xarch=generic"
834         fi
835 ])dnl SXE_CC_MAXOPT_SUN
836
837 AC_DEFUN([SXE_CC_MAXOPT_HP], [dnl
838         optiflags="+Oall +Optrs_ansi +DSnative"
839         if test "$acx_maxopt_portable" = "yes"; then
840                 optiflags="$optiflags +DAportable"
841         fi
842 ])dnl SXE_CC_MAXOPT_HP
843
844 AC_DEFUN([SXE_CC_MAXOPT_IBM], [dnl
845         if test "$acx_maxopt_portable" = "no"; then
846                 xlc_opt="-qarch=auto -qtune=auto"
847         else
848                 xlc_opt="-qtune=auto"
849         fi
850         SXE_CHECK_COMPILER_FLAGS([$xlc_opt],
851                 [optiflags="-O3 -qansialias -w $xlc_opt"],
852                 [optiflags="-O3 -qansialias -w"
853                 echo "******************************************************"
854                 echo "*  You seem to have the IBM  C compiler.  It is      *"
855                 echo "*  recommended for best performance that you use:    *"
856                 echo "*                                                    *"
857                 echo "*    CFLAGS=-O3 -qarch=xxx -qtune=xxx -qansialias -w *"
858                 echo "*                      ^^^        ^^^                *"
859                 echo "*  where xxx is pwr2, pwr3, 604, or whatever kind of *"
860                 echo "*  CPU you have.  (Set the CFLAGS environment var.   *"
861                 echo "*  and re-run configure.)  For more info, man cc.    *"
862                 echo "******************************************************"])
863 ])dnl SXE_CC_MAXOPT_IBM
864
865 AC_DEFUN([SXE_CC_MAXOPT_INTEL], [dnl
866         optiflags="-O3 -ansi_alias"
867         if test "$acx_maxopt_portable" = "no"; then
868                 icc_archflag=unknown
869                 icc_flags=""
870                 case "$host_cpu" in
871                 ## (
872                 i686*|x86_64*)
873                         # icc accepts gcc assembly syntax,
874                         # so these should work:
875                         SXE_CHECK_CPU_PC
876                         ;;
877                 esac
878                 if test "$icc_flags" != ""; then
879                         for flag in $icc_flags; do
880                                 SXE_CHECK_COMPILER_FLAGS([$flag],
881                                         [icc_archflag=$flag; break])
882                         done
883                 fi
884                 AC_MSG_CHECKING([for icc architecture flag])
885                 AC_MSG_RESULT([$icc_archflag])
886                 if test "$icc_archflag" != "unknown"; then
887                         optiflags="$optiflags $icc_archflag"
888                 fi
889         fi
890 ])dnl SXE_CC_MAXOPT_INTEL
891
892 AC_DEFUN([SXE_CC_MAXOPT_GNU], [dnl
893         ## default optimisation flags for gcc on all systems
894         ## this is the preferred compiler
895         optiflags="-O3"
896
897         AC_REQUIRE([SXE_CHECK_SIMD_EXTENSIONS])
898         optiflags="$optiflags $simdflags"
899
900         ## note that we enable "unsafe" fp optimisation with other compilers, too
901         SXE_CHECK_COMPILER_FLAGS([-ftree-vectorize],
902                 [optiflags="$optiflags -ftree-vectorize"])
903
904         ## check for -march and/or -mtune
905         SXE_GCC_ARCHFLAG([$acx_maxopt_portable])
906         optiflags="$optiflags $archflags"
907
908         ## a softer variant of omit-frame-pointer
909         SXE_CHECK_COMPILER_FLAGS([-momit-leaf-frame-pointer],
910                 [optiflags="$optiflags -momit-leaf-frame-pointer"])
911
912         ## check for openmp support
913         ## there are: -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp
914         SXE_CHECK_COMPILER_FLAGS([-fopenmp])
915
916         if test "$sxe_cv_c_flags__fopenmp" = "yes" -a "$with_omp"; then
917                 SXE_MSG_CHECKING([whether it is safe to use -fopenmp])
918                 case "$compiler_version" in
919                 gcc*\ 4.4.*)
920                         optiflags="$optiflags -fopenmp"
921                         sxe_cv_feat_omp="yes"
922                         SXE_MSG_RESULT([yes])
923                         ;;
924                 *)
925                         SXE_MSG_RESULT([no])
926                         ;;
927                 esac
928         fi
929
930         ## these belong to the corresponding MAXOPT macro
931 dnl     SXE_CHECK_COMPILER_FLAGS([-xopenmp], [
932 dnl             optiflags="$optiflags -xopenmp"
933 dnl             sxe_cv_feat_omp="yes"
934 dnl             ])
935 dnl     SXE_CHECK_COMPILER_FLAGS([-openmp], [
936 dnl             optiflags="$optiflags -openmp"
937 dnl             sxe_cv_feat_omp="yes"
938 dnl             ])
939 dnl     SXE_CHECK_COMPILER_FLAGS([-mp], [
940 dnl             optiflags="$optiflags -mp"
941 dnl             sxe_cv_feat_omp="yes"
942 dnl             ])
943 dnl     SXE_CHECK_COMPILER_FLAGS([-omp], [
944 dnl             optiflags="$optiflags -omp"
945 dnl             sxe_cv_feat_omp="yes"
946 dnl             ])
947 dnl     SXE_CHECK_COMPILER_FLAGS([-qsmp=omp], [
948 dnl             optiflags="$optiflags -qsmp=omp"
949 dnl             sxe_cv_feat_omp="yes"
950 dnl             ])
951         ## add -lgomp to ldflags
952         if test "$sxe_cv_feat_omp" = "yes"; then
953                 LDFLAGS="$LDFLAGS -lgomp"
954         fi
955
956         # -malign-double for x86 systems
957         SXE_CHECK_COMPILER_FLAGS([-malign-double])
958         ## won't add this one, since it is causing problems
959         ##      [optiflags="$optiflags -malign-double"])
960
961         ## would be nice to have this but it triggers too many
962         ## meaningless warnings
963 dnl     ## -fstrict-aliasing for gcc-2.95+
964 dnl     SXE_CHECK_COMPILER_FLAGS([-fstrict-aliasing],
965 dnl             [optiflags="$optiflags -fstrict-aliasing"])
966
967         SXE_CHECK_COMPILER_FLAGS([-fearly-inlining],
968                 [optiflags="$optiflags -fearly-inlining"])
969
970         SXE_CHECK_COMPILER_FLAGS([-fdelete-null-pointer-checks],
971                 [optiflags="$optiflags -fdelete-null-pointer-checks"])
972
973         SXE_CHECK_COMPILER_FLAGS([-fmodulo-sched],
974                 [optiflags="$optiflags -fmodulo-sched"])
975
976         SXE_CHECK_COMPILER_FLAGS([-fmudflap])
977         SXE_CHECK_COMPILER_FLAGS([-fmudflapth])
978         SXE_CHECK_COMPILER_FLAGS([-fmudflapir])
979         if test "$sxe_cv_c_flags__fmudflapth" -a \
980                 "$sxe_cv_c_flags__fmudflapir"; then
981                 ## preferred
982                 : ##optiflags="$optiflags -fmudflapth -fmudflapir"
983         elif test "$sxe_cv_c_flags__fmudflap" -a \
984                 "$sxe_cv_c_flags__fmudflapir"; then
985                 : ##optiflags="$optiflags -fmudflap -fmudflapir"
986         fi
987         SXE_CHECK_COMPILER_FLAGS([-fsection-anchors],
988                 [optiflags="$optiflags -fsection-anchors"])
989
990 dnl     ## actually this belongs to error-checking stuff
991 dnl     SXE_CHECK_COMPILER_FLAGS([-fstack-protector],
992 dnl             [optiflags="$optiflags -fstack-protector"])
993 dnl     if test "$sxe_cv_c_flags__fstack_protector" = "yes"; then
994 dnl             ## just check for ssp in this case
995 dnl             AC_CHECK_LIB([ssp], [__stack_chk_guard])
996 dnl     fi
997
998         SXE_CHECK_COMPILER_FLAGS([-fbranch-target-load-optimize])
999         SXE_CHECK_COMPILER_FLAGS([-fbranch-target-load-optimize2])
1000         if test "$sxe_cv_c_flags__fbranch_target_load_optimize2" = "yes"; then
1001                 optiflags="$optiflags -fbranch-target-load-optimize2"
1002         elif test "$sxe_cv_c_flags__fbranch_target_load_optimize" = "yes"; then
1003                 optiflags="$optiflags -fbranch-target-load-optimize"
1004         fi
1005
1006         SXE_CHECK_COMPILER_FLAGS([-fgcse],
1007                 [optiflags="$optiflags -fgcse"])
1008         SXE_CHECK_COMPILER_FLAGS([-fgcse-lm],
1009                 [optiflags="$optiflags -fgcse-lm"])
1010         SXE_CHECK_COMPILER_FLAGS([-fgcse-sm],
1011                 [optiflags="$optiflags -fgcse-sm"])
1012         SXE_CHECK_COMPILER_FLAGS([-fgcse-las],
1013                 [optiflags="$optiflags -fgcse-las"])
1014         SXE_CHECK_COMPILER_FLAGS([-fgcse-after-reload],
1015                 [optiflags="$optiflags -fgcse-after-reload"])
1016         SXE_CHECK_COMPILER_FLAGS([-funsafe-loop-optimizations],
1017                 [optiflags="$optiflags -funsafe-loop-optimizations"])
1018         SXE_CHECK_COMPILER_FLAGS([-funroll-loops],
1019                 [optiflags="$optiflags -funswitch-loops"])
1020         SXE_CHECK_COMPILER_FLAGS([-funswitch-loops],
1021                 [optiflags="$optiflags -funswitch-loops"])
1022         SXE_CHECK_COMPILER_FLAGS([-frename-registers],
1023                 [optiflags="$optiflags -frename-registers"])
1024
1025         ## maths speedup
1026         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations -fno-signaling-nans],
1027                 [optiflags="$optiflags -fno-signaling-nans"])
1028         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations -fno-trapping-math],
1029                 [optiflags="$optiflags -fno-trapping-math"])
1030         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations -fno-signed-zeros],
1031                 [optiflags="$optiflags -fno-signed-zeros"])
1032         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations -fassociative-math],
1033                 [optiflags="$optiflags -fassociative-math"])
1034         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations -fno-rounding-math],
1035                 [optiflags="$optiflags -fno-rounding-math"])
1036         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations -fno-math-errno],
1037                 [optiflags="$optiflags -fno-math-errno"])
1038         ## the same as the previous 5, but sometimes gcc doesn't know'em all
1039         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations],
1040                 [optiflags="$optiflags -funsafe-math-optimizations"])
1041         ## another of these
1042         SXE_CHECK_COMPILER_FLAGS([-ffast-math],
1043                 [optiflags="$optiflags -ffast-math"])
1044         ## and yet some more
1045         SXE_CHECK_COMPILER_FLAGS([-mrecip],
1046                 [optiflags="$optiflags -mrecip"])
1047         SXE_CHECK_COMPILER_FLAGS([-msahf],
1048                 [optiflags="$optiflags -msahf"])
1049
1050         SXE_CHECK_COMPILER_FLAGS([-minline-all-stringops],
1051                 [optiflags="$optiflags -minline-all-stringops"])
1052
1053 ])dnl SXE_CC_MAXOPT_GNU
1054
1055
1056 ##### http://autoconf-archive.cryp.to/ax_check_compiler_flags.html
1057 ## renamed the prefix to SXE_
1058 AC_DEFUN([SXE_CHECK_COMPILER_FLAGS], [dnl
1059         AC_MSG_CHECKING([whether _AC_LANG compiler accepts $1])
1060
1061         dnl Some hackery here since AC_CACHE_VAL can't handle a non-literal varname:
1062         SXE_LANG_WERROR([push+on])
1063         AS_LITERAL_IF([$1], [
1064                 AC_CACHE_VAL(AS_TR_SH(sxe_cv_[]_AC_LANG_ABBREV[]_flags_$1), [
1065                         sxe_save_FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
1066                         _AC_LANG_PREFIX[]FLAGS="$1"
1067                         AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1068                                 AS_TR_SH(sxe_cv_[]_AC_LANG_ABBREV[]_flags_$1)="yes",
1069                                 AS_TR_SH(sxe_cv_[]_AC_LANG_ABBREV[]_flags_$1)="no")
1070                         _AC_LANG_PREFIX[]FLAGS=$sxe_save_FLAGS])], [
1071                 sxe_save_FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
1072                 _AC_LANG_PREFIX[]FLAGS="$1"
1073                 AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1074                         eval AS_TR_SH(sxe_cv_[]_AC_LANG_ABBREV[]_flags_$1)="yes",
1075                         eval AS_TR_SH(sxe_cv_[]_AC_LANG_ABBREV[]_flags_$1)="no")
1076                 _AC_LANG_PREFIX[]FLAGS=$sxe_save_FLAGS])
1077         eval sxe_check_compiler_flags=$AS_TR_SH(sxe_cv_[]_AC_LANG_ABBREV[]_flags_$1)
1078         SXE_LANG_WERROR([pop])
1079
1080         AC_MSG_RESULT([$sxe_check_compiler_flags])
1081         if test "$sxe_check_compiler_flags" = "yes"; then
1082                 m4_default([$2], :)
1083         else
1084                 m4_default([$3], :)
1085         fi
1086 ])dnl SXE_CHECK_COMPILER_FLAGS
1087
1088
1089 AC_DEFUN([SXE_CHECK_CPU], [dnl
1090         case "$host_cpu" in
1091         dnl (
1092         i*86*|x86_64*)
1093                 ## pc-style hardware
1094                 SXE_CHECK_CPU_PC
1095                 ;;
1096         dnl (
1097         sparc*)
1098                 ## sparc stuff
1099                 SXE_CHECK_CPU_SPARC
1100                 ;;
1101         dnl (
1102         alpha*)
1103                 ## alpha cruft
1104                 SXE_CHECK_CPU_ALPHA
1105                 ;;
1106         dnl (
1107         powerpc*)
1108                 ## ya know what
1109                 SXE_CHECK_CPU_PPC
1110                 ;;
1111         esac
1112 ])dnl SXE_CHECK_CPU
1113
1114 AC_DEFUN([SXE_CHECK_CPU_SPARC], [dnl
1115         AC_PATH_PROG([PRTDIAG], [prtdiag], [prtdiag],
1116                 [$PATH:/usr/platform/`uname -i`/sbin/:/usr/platform/`uname -m`/sbin/])
1117         cputype=$((((grep cpu /proc/cpuinfo | cut -d: -f2) ; \
1118                 ($PRTDIAG -v |grep -i sparc) ; \
1119                 grep -i cpu "/var/run/dmesg.boot" ) | head -n 1) 2> /dev/null)
1120         cputype=$(echo "$cputype" | tr -d ' -' |tr $as_cr_LETTERS $as_cr_letters)
1121
1122         case "$cputype" in
1123         dnl (
1124         *ultrasparciv*)
1125                 sxe_gcc_arch="ultrasparc4 ultrasparc3 ultrasparc v9"
1126                 ;;
1127         dnl (
1128         *ultrasparciii*)
1129                 sxe_gcc_arch="ultrasparc3 ultrasparc v9"
1130                 ;;
1131         dnl (
1132         *ultrasparc*)
1133                 sxe_gcc_arch="ultrasparc v9"
1134                 ;;
1135         dnl (
1136         *supersparc*|*tms390z5[[05]]*)
1137                 sxe_gcc_arch="supersparc v8"
1138                 ;;
1139         dnl (
1140         *hypersparc*|*rt62[[056]]*)
1141                 sxe_gcc_arch="hypersparc v8"
1142                 ;;
1143         dnl (
1144         *cypress*)
1145                 sxe_gcc_arch=cypress
1146                 ;;
1147         esac
1148 ])dnl SXE_CHECK_CPU_SPARC
1149
1150 AC_DEFUN([SXE_CHECK_CPU_ALPHA], [dnl
1151         case "$host_cpu" in
1152         dnl (
1153         alphaev5)
1154                 sxe_gcc_arch="ev5"
1155                 ;;
1156         dnl (
1157         alphaev56)
1158                 sxe_gcc_arch="ev56"
1159                 ;;
1160         dnl (
1161         alphapca56)
1162                 sxe_gcc_arch="pca56 ev56"
1163                 ;;
1164         dnl (
1165         alphapca57)
1166                 sxe_gcc_arch="pca57 pca56 ev56"
1167                 ;;
1168         dnl (
1169         alphaev6)
1170                 sxe_gcc_arch="ev6"
1171                 ;;
1172         dnl (
1173         alphaev67)
1174                 sxe_gcc_arch="ev67"
1175                 ;;
1176         dnl (
1177         alphaev68)
1178                 sxe_gcc_arch="ev68 ev67"
1179                 ;;
1180         dnl (
1181         alphaev69)
1182                 sxe_gcc_arch="ev69 ev68 ev67"
1183                 ;;
1184         dnl (
1185         alphaev7)
1186                 sxe_gcc_arch="ev7 ev69 ev68 ev67"
1187                 ;;
1188         dnl (
1189         alphaev79)
1190                 sxe_gcc_arch="ev79 ev7 ev69 ev68 ev67"
1191                 ;;
1192         esac
1193 ])dnl SXE_CHECK_CPU_ALPHA
1194
1195 AC_DEFUN([SXE_CHECK_CPU_PPC], [dnl
1196         cputype=$(((grep cpu /proc/cpuinfo | head -n 1 | \
1197                 cut -d: -f2 | cut -d, -f1 | sed 's/ //g') ; \
1198                 /usr/bin/machine ; \
1199                 /bin/machine; \
1200                 grep CPU /var/run/dmesg.boot | \
1201                 head -n 1 | cut -d" " -f2) 2> /dev/null)
1202         cputype=$(echo $cputype | sed -e 's/ppc//g;s/ *//g')
1203
1204         case "$cputype" in
1205         dnl (
1206         *750*)
1207                 sxe_gcc_arch="750 G3"
1208                 ;;
1209         dnl (
1210         *740[[0-9]]*)
1211                 sxe_gcc_arch="$cputype 7400 G4"
1212                 ;;
1213         dnl (
1214         *74[[4-5]][[0-9]]*)
1215                 sxe_gcc_arch="$cputype 7450 G4"
1216                 ;;
1217         dnl (
1218         *74[[0-9]][[0-9]]*)
1219                 sxe_gcc_arch="$cputype G4"
1220                 ;;
1221         dnl (
1222         *970*)
1223                 sxe_gcc_arch="970 G5 power4"
1224                 ;;
1225         dnl (
1226         *POWER4*|*power4*|*gq*)
1227                 sxe_gcc_arch="power4 970"
1228                 ;;
1229         dnl (
1230         *POWER5*|*power5*|*gr*|*gs*)
1231                 sxe_gcc_arch="power5 power4 970"
1232                 ;;
1233         dnl (
1234         603ev|8240)
1235                 sxe_gcc_arch="$cputype 603e 603"
1236                 ;;
1237         dnl (
1238         *)
1239                 sxe_gcc_arch="$cputype"
1240                 ;;
1241         esac
1242         sxe_gcc_arch="$sxe_gcc_arch powerpc"
1243 ])dnl SXE_CHECK_CPU_PPC
1244
1245 AC_DEFUN([SXE_CHECK_CPU_PC], [dnl
1246         ## use cpuid codes,
1247         AC_REQUIRE([SXE_PROC_CPUID])
1248
1249         case "$sxe_cv_proc_cpuid_00000000" in
1250         dnl (
1251         *:756e6547:*:*)
1252                 ## Intel
1253                 case "$sxe_cv_proc_cpuid_00000001" in
1254                 dnl (
1255                 *5[[48]]?:*:*:*)
1256                         sxe_gcc_arch="pentium-mmx pentium"
1257                         ;;
1258                 dnl (
1259                 *5??:*:*:*)
1260                         sxe_gcc_arch="pentium"
1261                         ;;
1262                 dnl (
1263                 *6[[3456]]?:*:*:*)
1264                         sxe_gcc_arch="pentium2 pentiumpro"
1265                         ;;
1266                 dnl (
1267                 *6a?:*[[01]]:*:*)
1268                         sxe_gcc_arch="pentium2 pentiumpro"
1269                         ;;
1270                 dnl (
1271                 *6a?:*[[234]]:*:*)
1272                         sxe_gcc_arch="pentium3 pentiumpro"
1273                         icc_flags="-xK"
1274                         ;;
1275                 dnl (
1276                 *69?:*:*:*)
1277                         sxe_gcc_arch="pentium-m pentium3 pentiumpro"
1278                         icc_flags="-xK"
1279                         ;;
1280                 dnl (
1281                 *6d?:*:*:*)
1282                         sxe_gcc_arch="pentium-m pentium3 pentiumpro"
1283                         ;;
1284                 dnl (
1285                 *6[[78b]]?:*:*:*)
1286                         sxe_gcc_arch="pentium3 pentiumpro"
1287                         icc_flags="-xK"
1288                         ;;
1289                 dnl (
1290                 *6f?:*:*:*)
1291                         ## intel core 2 duo
1292                         sxe_gcc_arch="nocona pentium4 pentiumpro"
1293                         ## icc flags here
1294                         ## icc_flags="??"
1295                         ;;
1296                 dnl (
1297                 *6??:*:*:*)
1298                         sxe_gcc_arch="pentiumpro"
1299                         ;;
1300                 dnl (
1301                 *f3[[347]]:*:*:*|*f4[1347]:*:*:*)
1302                         icc_flags="-xP -xN -xW -xK"
1303                         case "$host_cpu" in
1304                         dnl (
1305                         x86_64*)
1306                                 sxe_gcc_arch="nocona pentium4 pentiumpro"
1307                                 ;;
1308                         dnl (
1309                         *)
1310                                 sxe_gcc_arch="prescott pentium4 pentiumpro"
1311                                 ;;
1312                         esac
1313                         ;;
1314                 dnl (
1315                 *f??:*:*:*)
1316                         icc_flags="-xN -xW -xK"
1317                         sxe_gcc_arch="pentium4 pentiumpro"
1318                         ;;
1319                 esac
1320                 ;;
1321         dnl (
1322         *:68747541:*:*)
1323                 ## AMD
1324                 case "$sxe_cv_proc_cpuid_00000001" in
1325                 dnl (
1326                 *5[[67]]?:*:*:*)
1327                         sxe_gcc_arch="k6"
1328                         ;;
1329                 dnl (
1330                 *5[[8d]]?:*:*:*)
1331                         sxe_gcc_arch="k6-2 k6"
1332                         ;;
1333                 dnl (
1334                 *5[[9]]?:*:*:*)
1335                         sxe_gcc_arch="k6-3 k6"
1336                         ;;
1337                 dnl (
1338                 *60?:*:*:*)
1339                         sxe_gcc_arch="k7"
1340                         ;;
1341                 dnl (
1342                 *6[[12]]?:*:*:*)
1343                         sxe_gcc_arch="athlon k7"
1344                         ;;
1345                 dnl (
1346                 *6[[34]]?:*:*:*)
1347                         sxe_gcc_arch="athlon-tbird k7"
1348                         ;;
1349                 dnl (
1350                 *67?:*:*:*)
1351                         sxe_gcc_arch="athlon-4 athlon k7"
1352                         ;;
1353                 dnl (
1354                 *6[[68a]]?:*:*:*)
1355                         case "$sxe_cv_proc_cpuid_80000006" in
1356                         dnl (
1357                         *:*:*[[1-9a-f]]??????:*) # (L2 = ecx >> 16) >= 256
1358                                 sxe_gcc_arch="athlon-xp athlon-4 athlon k7"
1359                                 ;;
1360                         dnl (
1361                         *)
1362                                 sxe_gcc_arch="athlon-4 athlon k7"
1363                                 ;;
1364                         esac
1365                         ;;
1366                 dnl (
1367                 *f[[4cef8b]]?:*:*:*)
1368                         sxe_gcc_arch="athlon64 k8"
1369                         ;;
1370                 dnl (
1371                 *f5?:*:*:*)
1372                         sxe_gcc_arch="opteron k8"
1373                         ;;
1374                 dnl (
1375                 *f7?:*:*:*)
1376                         sxe_gcc_arch="athlon-fx opteron k8"
1377                         ;;
1378                 dnl (
1379                 *f??:*:*:*)
1380                         sxe_gcc_arch="k8"
1381                         ;;
1382                 esac
1383                 ;;
1384         dnl (
1385         *:746e6543:*:*)
1386                 # IDT
1387                 case "$sxe_cv_proc_cpuid_00000001" in
1388                 dnl (
1389                 *54?:*:*:*)
1390                         sxe_gcc_arch="winchip-c6"
1391                         ;;
1392                 dnl (
1393                 *58?:*:*:*)
1394                         sxe_gcc_arch="winchip2"
1395                         ;;
1396                 dnl (
1397                 *6[[78]]?:*:*:*)
1398                         sxe_gcc_arch="c3"
1399                         ;;
1400                 dnl (
1401                 *69?:*:*:*)
1402                         sxe_gcc_arch="c3-2 c3"
1403                         ;;
1404                 esac
1405                 ;;
1406         esac
1407
1408         ## nothing found? => fallback
1409         if test -z "$sxe_gcc_arch"; then
1410                 ## apply a generic strategy
1411                 case "$host_cpu" in
1412                 i586*)
1413                         sxe_gcc_arch="pentium"
1414                         ;;
1415                 i686*)
1416                         sxe_gcc_arch="pentiumpro"
1417                         ;;
1418                 esac
1419         fi
1420 ])dnl SXE_CHECK_CPU_PC
1421
1422
1423 AC_DEFUN([SXE_GCC_ARCHFLAG], [dnl
1424         AC_REQUIRE([AC_PROG_CC])
1425         AC_REQUIRE([AC_CANONICAL_HOST])
1426
1427         AC_ARG_WITH([gcc-arch], AS_HELP_STRING([--with-gcc-arch=<arch>], [
1428                         use architecture <arch> for gcc -march/-mtune,
1429                         instead of guessing]),
1430                 [sxe_gcc_arch=$withval], [sxe_gcc_arch=yes])
1431
1432         AC_MSG_CHECKING([for gcc architecture flag])
1433         AC_MSG_RESULT([])
1434         AC_CACHE_VAL([sxe_cv_gcc_archflag], [
1435                 ## initialise to unknown
1436                 sxe_cv_gcc_archflag="unknown"
1437
1438                 if test "$GCC" = yes; then
1439                         if test "$sxe_gcc_arch" = "yes" -a \
1440                                 "$cross_compiling" = "no"; then
1441                                 sxe_gcc_arch=""
1442                                 SXE_CHECK_CPU
1443                         fi
1444
1445                         if test -n "$sxe_gcc_arch" -a "$sxe_gcc_arch" != "no"; then
1446                                 for arch in $sxe_gcc_arch; do
1447                                         if test "[]m4_default([$1],yes)" = "yes"; then
1448                                                 ## if we require portable code
1449                                                 archflags="-mtune=$arch"
1450                                                 ## -mcpu=$arch and m$arch generate
1451                                                 ## nonportable code on every arch except
1452                                                 ## x86.  And some other arches
1453                                                 ## (e.g. Alpha) don't accept -mtune.
1454                                                 ## Grrr.
1455                                                 case "$host_cpu" in
1456                                                 dnl (
1457                                                 i*86|x86_64*)
1458                                                         archflags="$archflags -mcpu=$arch -m$arch"
1459                                                         ;;
1460                                                 esac
1461                                         else
1462                                                 archflags="-march=$arch -mcpu=$arch -m$arch"
1463                                         fi
1464                                         for flag in $archflags; do
1465                                                 SXE_CHECK_COMPILER_FLAGS([$flag],
1466                                                         [sxe_cv_gcc_archflag="$flag"; break])
1467                                         done
1468                                         if test "$sxe_cv_gcc_archflag" != "unknown"; then
1469                                                 break
1470                                         fi
1471                                 done
1472                         fi
1473                 fi
1474                 ])
1475
1476         AC_MSG_CHECKING([for gcc architecture flag])
1477         AC_MSG_RESULT([$sxe_cv_gcc_archflag])
1478         if test "$sxe_cv_gcc_archflag" = "unknown"; then
1479                 m4_default([$3],:)
1480         else
1481                 m4_default([$2], [archflags="$sxe_cv_gcc_archflag"])
1482         fi
1483 ])dnl SXE_GCC_ARCHFLAG
1484
1485
1486 #### http://autoconf-archive.cryp.to/sxe_check_define.html
1487 AC_DEFUN([SXE_CHECK_DEFINED], [dnl
1488         AS_VAR_PUSHDEF([ac_var],[ac_cv_defined_$2])dnl
1489
1490         AC_CACHE_CHECK([for $1 defined], ac_var,
1491                 AC_TRY_COMPILE($1,[
1492 #ifndef $2
1493 int ok;
1494 #else
1495 choke me
1496 #endif
1497                 ],
1498                 AS_VAR_SET(ac_var, [yes]),
1499                 AS_VAR_SET(ac_var, [no])))
1500
1501         AS_IF([test AS_VAR_GET(ac_var) != "no"], [$3], [$4])
1502         AS_VAR_POPDEF([ac_var])
1503 ])dnl SXE_CHECK_DEFINED
1504
1505 AC_DEFUN([SXE_CHECK_FUNC], [dnl
1506         AS_VAR_PUSHDEF([ac_var], [ac_cv_func_$2])dnl
1507         AC_CACHE_CHECK([for $2], ac_var, [
1508                 dnl AC_LANG_FUNC_LINK_TRY
1509                 AC_LINK_IFELSE([AC_LANG_PROGRAM([$1
1510 #undef $2
1511 char $2 ();
1512                         ], [
1513 char (*f) () = $2;
1514 return f != $2;
1515                         ])], [
1516                         AS_VAR_SET(ac_var, [yes])], [
1517                         AS_VAR_SET(ac_var, [no])])])
1518
1519         AS_IF([test AS_VAR_GET(ac_var) = "yes"], [$3], [$4])
1520         AS_VAR_POPDEF([ac_var])
1521 ])dnl SXE_CHECK_FUNC
1522
1523
1524
1525 AC_DEFUN([SXE_CHECK_C99_NJSF], [dnl
1526         dnl If we have a compiler that could do c99 do try to add the flag
1527         if test "$__GCC3" = "yes" ; then
1528                 SXE_APPEND("-std=c99", c_switch_site)
1529                 AC_MSG_CHECKING([for C99 support])
1530                 save_c_switch_site=$c_switch_site
1531                 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1532 #include <stdlib.h>
1533 ]],[[
1534 return 0;
1535 ]])],  [AC_MSG_RESULT(yes)
1536         have_c99="yes"],
1537        [c_switch_site=$sace_c_switch_site
1538                 AC_MSG_RESULT(no)
1539                 AC_MSG_WARN([C99 not supported, reverting option append])
1540                 have_c99="no"])
1541         elif test "$__SUNPRO_C" = "yes" ; then
1542                 AC_MSG_CHECKING([for C99 support])
1543                 save_c_switch_site=$c_switch_site
1544                 SXE_APPEND("-xc99", c_switch_site)
1545                 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1546 #include <stdlib.h>
1547 ]],[[
1548 return 0;
1549 ]])],  [AC_MSG_RESULT(yes)
1550                 have_c99="yes"],
1551        [c_switch_site=$sace_c_switch_site
1552                 AC_MSG_RESULT(no)
1553                 have_c99="no"])
1554         fi
1555 ])dnl SXE_CHECK_C99_NJSF
1556
1557
1558 AC_DEFUN([SXE_C_TYPEOF], [dnl
1559         dnl check for the typeof extension
1560         AC_MSG_CHECKING([for typeof])
1561         AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1562 int i; __typeof__(i) j;
1563 ]])], [typeofname="__typeof__"], [dnl else
1564                 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1565 int i; typeof(i) j;
1566 ]])], [typeofname="typeof"], [typeofname=no])])
1567         AC_MSG_RESULT([$typeofname])
1568         if test "$typeofname" != "no"; then
1569                 AC_DEFINE_UNQUOTED([TYPEOF], [$typeofname],
1570                         [How to use the typeof extension.])
1571         fi
1572 ])dnl SXE_C_TYPEOF
1573
1574 AC_DEFUN([SXE_C_INLINE], [dnl
1575         AC_C_INLINE
1576         if test "$ac_cv_c_inline" != "no" -a "$GCC" = "yes"; then
1577                 SXE_ADD_CRUFT_OBJS([inline.o])
1578         fi
1579 ])dnl SXE_C_INLINE
1580
1581
1582 AC_DEFUN([SXE_CHECK_BROKEN_RESTRICT], [dnl
1583         AC_MSG_CHECKING([support for restrict keyword])
1584         AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1585 extern void f(void*restrict[]);
1586 ]])], [have_restrict="yes"], [have_restrict="no"])
1587         if test "$have_restrict" = "no"; then
1588                 AC_DEFINE_UNQUOTED([restrict], [],
1589                         [Define restrict to nothing])
1590         fi
1591         AC_MSG_RESULT([$typeofname])
1592 ])dnl SXE_CHECK_BROKEN_RESTRICT 
1593
1594 dnl recommended interface macros
1595 ## compiler wrapper
1596 AC_DEFUN([SXE_CHECK_CC], [dnl
1597
1598         AC_PROG_CPP
1599         AC_HEADER_STDC
1600         AC_PROG_CC([gcc icc cc])
1601         dnl AC_PROG_CC_STDC
1602         AC_PROG_CC_C99
1603
1604         ## check for machine and architecture
1605         SXE_CHECK_MACHARCH
1606
1607         ## check for C compiler characteristics
1608         SXE_CHECK_CC_VERSION
1609         if test "$GCC" = "yes"; then
1610                 SXE_CHECK_BROKEN_GCC
1611         fi
1612         AC_C_RESTRICT
1613         if test "$ac_cv_prog_cc_c99" != ""; then
1614                 SXE_CHECK_BROKEN_RESTRICT
1615         fi
1616
1617         ## check for libc
1618         SXE_CHECK_LIBC
1619         SXE_CHECK_LIBC_VERSION
1620         dnl Non-ordinary link usually requires -lc
1621         if test "$ordinary_link" = "no" -a -z "$libs_standard"; then
1622                 libs_standard="-lc"
1623         fi
1624
1625         SXE_CHECK_CC_HACKS
1626         SXE_CHECK_CC_CHAR
1627         SXE_CHECK_CC_NESTED_FUNS
1628
1629         ## Canonicalize the configuration name.
1630         ## Commented out, lets see if anything breaks. --SY.
1631         ## SXE_STRIP_4TH_COMPONENT(ac_cv_build_alias)
1632         ## SXE_STRIP_4TH_COMPONENT(ac_cv_build)
1633         AC_SUBST([configuration], [$ac_cv_build])
1634
1635         AM_PROG_CC_C_O
1636
1637 ])dnl SXE_CHECK_CC
1638
1639
1640 AC_DEFUN([SXE_CHECK_CFLAGS], [dnl
1641         dnl #### This may need to be overhauled so that all of SXEMACS_CC's flags
1642         dnl are handled separately, not just the xe_cflags_warning stuff.
1643
1644         ## Use either command line flag, environment var, or autodetection
1645         if test "$with_ridiculously_aggressive_optimisations" = "yes"; then
1646                 CFLAGS=""
1647                 SXE_DEBUGFLAGS
1648                 SXE_WARNFLAGS
1649                 SXE_OPTIFLAGS
1650                 SXE_FEATFLAGS
1651                 SXE_CFLAGS="$debugflags $featflags $optiflags $warnflags"
1652         elif test "$CFLAGS_uspecified_p" = "no" -o \
1653                 "$ac_test_CFLAGS" != "set"; then
1654                 SXE_DEBUGFLAGS
1655                 SXE_WARNFLAGS
1656                 SXE_FEATFLAGS
1657
1658                 ## the old settings
1659                 ## Following values of CFLAGS are known to work well.
1660                 ## Should we take debugging options into consideration?
1661                 if test "$GCC" = "yes"; then
1662                         optiflags="-O3"
1663                 elif test "$__SUNPRO_C" = "yes"; then
1664                         case "$opsys" in
1665                         sol2    ) optiflags="-xO4" ;;
1666                         sunos4* ) optiflags="-xO2" ;;
1667                         esac
1668                 elif test "$__DECC" = "yes"; then
1669                         optiflags="-O3"
1670                 elif test "$CC" = "xlc"; then
1671                         optiflags="-g -O3 -qstrict -qnoansialias -qlibansi -qro -qmaxmem=20000"
1672                 elif test "$__ICC" = "yes"; then
1673                         optiflags="-g -O3 -Ob2"
1674                 ### Add optimal CFLAGS support for other compilers HERE!
1675                 else
1676                         optiflags="-O" ## The only POSIX-approved flag
1677                 fi
1678
1679                 SXE_CFLAGS="$debugflags $featflags $optiflags $warnflags"
1680         else
1681                 SXE_CFLAGS=${USER_CFLAGS}
1682                 featflags=""
1683                 debugflags=""
1684                 optiflags=""
1685                 warnflags=""
1686         fi
1687
1688         ## unset the werror flag again
1689         SXE_LANG_WERROR([off])
1690
1691         CFLAGS="$SXE_CFLAGS"
1692         AC_MSG_CHECKING([for preferred CFLAGS])
1693         AC_MSG_RESULT([${SXE_CFLAGS}])
1694
1695         AC_MSG_NOTICE([
1696 If you wish to ADD your own flags you want to stop here and rerun the
1697 configure script like so:
1698   configure CFLAGS=<to-be-added-flags>
1699
1700 You can always override the determined CFLAGS, partially or totally,
1701 using
1702   make -C <directory> CFLAGS=<your-own-flags> [target]
1703 or
1704   make CFLAGS=<your-own-flags> [target]
1705 respectively
1706
1707 NOTE: -C <directory> option is not available on all systems
1708                 ])
1709
1710 ])dnl SXE_CHECK_CFLAGS
1711
1712
1713 AC_DEFUN([SXE_CC_LIBRARY_PATH], [dnl
1714         ## arg #1 variable to store name in,
1715         ## if omitted defaults to `sxe_cv_tmp_gcc_library_path'
1716         pushdef([VAR], ifelse($1,[],[sxe_cv_tmp_gcc_library_path],$1))
1717
1718         for i in ${LDFLAGS}; do
1719                 case $i in
1720                 -L*)
1721                         __LP=${i:2}:${__LP:-.}
1722                         ;;
1723                 *)
1724                         ;;
1725                 esac
1726         done
1727         SXE_EXPAND_VAR([${libdir}], [__ld])
1728         []VAR[]=${__ld:-.}:${__LP:-.}
1729
1730         popdef([VAR])
1731 ])dnl SXE_CC_LIBRARY_PATH
1732
1733
1734 AC_DEFUN([SXE_CC_LIBRARY_LOCATION], [dnl
1735         ## arg #1 the library to seek after
1736         ## arg #2 (optional) checking message
1737         pushdef([liborig], [$1])
1738         pushdef([liblink], patsubst(patsubst(liborig, [lib], [-l]), [\.[^.]+$], []))
1739         pushdef([libname], translit(liborig, [-,.], [___]))
1740         pushdef([LIBNAME], translit(liborig, [-,.a-z], [___A-Z]))
1741         pushdef([libchk], ifelse($2,[],[for absolute path of ]liborig,$2))
1742
1743         ## use gcc's -print-file-name
1744         AC_REQUIRE([SXE_CC_LIBRARY_PATH])
1745         AC_MSG_CHECKING([]libchk[])
1746         ## not protected against other CCs (yet)!
1747         sxe_cv_loc_[]libname[]=$(LIBRARY_PATH=${sxe_cv_tmp_gcc_library_path} \
1748                 ${CC} -print-file-name=[]liborig[])
1749         AC_MSG_RESULT(${sxe_cv_loc_[]libname[]})
1750
1751         []LIBNAME[]=${sxe_cv_loc_[]libname[]}
1752
1753         popdef([libchk])
1754         popdef([liblink])
1755         popdef([liborig])
1756         popdef([libname])
1757         popdef([LIBNAME])
1758 ])dnl SXE_CC_LIBRARY_LOCATION
1759
1760 dnl sxe-compiler.m4 ends here