Improved assertions from Nelson
[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 dnl     ## actually this belongs to error-checking stuff
989 dnl     SXE_CHECK_COMPILER_FLAGS([-fstack-protector],
990 dnl             [optiflags="$optiflags -fstack-protector"])
991 dnl     if test "$sxe_cv_c_flags__fstack_protector" = "yes"; then
992 dnl             ## just check for ssp in this case
993 dnl             AC_CHECK_LIB([ssp], [__stack_chk_guard])
994 dnl     fi
995
996         SXE_CHECK_COMPILER_FLAGS([-fbranch-target-load-optimize])
997         SXE_CHECK_COMPILER_FLAGS([-fbranch-target-load-optimize2])
998         if test "$sxe_cv_c_flags__fbranch_target_load_optimize2" = "yes"; then
999                 optiflags="$optiflags -fbranch-target-load-optimize2"
1000         elif test "$sxe_cv_c_flags__fbranch_target_load_optimize" = "yes"; then
1001                 optiflags="$optiflags -fbranch-target-load-optimize"
1002         fi
1003
1004         SXE_CHECK_COMPILER_FLAGS([-fgcse],
1005                 [optiflags="$optiflags -fgcse"])
1006         SXE_CHECK_COMPILER_FLAGS([-fgcse-lm],
1007                 [optiflags="$optiflags -fgcse-lm"])
1008         SXE_CHECK_COMPILER_FLAGS([-fgcse-sm],
1009                 [optiflags="$optiflags -fgcse-sm"])
1010         SXE_CHECK_COMPILER_FLAGS([-fgcse-las],
1011                 [optiflags="$optiflags -fgcse-las"])
1012         SXE_CHECK_COMPILER_FLAGS([-fgcse-after-reload],
1013                 [optiflags="$optiflags -fgcse-after-reload"])
1014         SXE_CHECK_COMPILER_FLAGS([-funsafe-loop-optimizations],
1015                 [optiflags="$optiflags -funsafe-loop-optimizations"])
1016         SXE_CHECK_COMPILER_FLAGS([-funroll-loops],
1017                 [optiflags="$optiflags -funswitch-loops"])
1018         SXE_CHECK_COMPILER_FLAGS([-funswitch-loops],
1019                 [optiflags="$optiflags -funswitch-loops"])
1020         SXE_CHECK_COMPILER_FLAGS([-frename-registers],
1021                 [optiflags="$optiflags -frename-registers"])
1022
1023         ## maths speedup
1024         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations -fno-signaling-nans],
1025                 [optiflags="$optiflags -fno-signaling-nans"])
1026         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations -fno-trapping-math],
1027                 [optiflags="$optiflags -fno-trapping-math"])
1028         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations -fno-signed-zeros],
1029                 [optiflags="$optiflags -fno-signed-zeros"])
1030         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations -fassociative-math],
1031                 [optiflags="$optiflags -fassociative-math"])
1032         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations -fno-rounding-math],
1033                 [optiflags="$optiflags -fno-rounding-math"])
1034         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations -fno-math-errno],
1035                 [optiflags="$optiflags -fno-math-errno"])
1036         ## the same as the previous 5, but sometimes gcc doesn't know'em all
1037         SXE_CHECK_COMPILER_FLAGS([-funsafe-math-optimizations],
1038                 [optiflags="$optiflags -funsafe-math-optimizations"])
1039         ## another of these
1040         SXE_CHECK_COMPILER_FLAGS([-ffast-math],
1041                 [optiflags="$optiflags -ffast-math"])
1042         ## and yet some more
1043         SXE_CHECK_COMPILER_FLAGS([-mrecip],
1044                 [optiflags="$optiflags -mrecip"])
1045         SXE_CHECK_COMPILER_FLAGS([-msahf],
1046                 [optiflags="$optiflags -msahf"])
1047
1048         SXE_CHECK_COMPILER_FLAGS([-minline-all-stringops],
1049                 [optiflags="$optiflags -minline-all-stringops"])
1050
1051 ])dnl SXE_CC_MAXOPT_GNU
1052
1053
1054 ##### http://autoconf-archive.cryp.to/ax_check_compiler_flags.html
1055 ## renamed the prefix to SXE_
1056 AC_DEFUN([SXE_CHECK_COMPILER_FLAGS], [dnl
1057 dnl SXE_CHECK_COMPILER_FLAGS(<FLAG>, <ACTION-IF-FOUND>, <ACTION-IF-NOT-FOUND>,
1058 dnl     <ADDITIONAL-FLAGS>)
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="$4 $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="$4 $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_COMPILER_XFLAG], [dnl
1090         ## if libtool then
1091         case "${LD}" in
1092         *"libtool"*)
1093                 SXE_CHECK_COMPILER_FLAGS([-XCClinker], [
1094                         XFLAG="-XCClinker"], [
1095                         XFLAG=""])
1096                 ;;
1097         *"ld"*)
1098                 ## no XFLAG needed
1099                 XFLAG=""
1100                 ;;
1101         *)
1102                 SXE_CHECK_COMPILER_FLAGS([-Xlinker], [
1103                         XFLAG="-Xlinker"], [
1104                         XFLAG=""])
1105                 ;;
1106         esac
1107 ])dnl SXE_CHECK_COMPILER_XFLAG
1108
1109
1110 AC_DEFUN([SXE_CHECK_CPU], [dnl
1111         case "$host_cpu" in
1112         dnl (
1113         i*86*|x86_64*)
1114                 ## pc-style hardware
1115                 SXE_CHECK_CPU_PC
1116                 ;;
1117         dnl (
1118         sparc*)
1119                 ## sparc stuff
1120                 SXE_CHECK_CPU_SPARC
1121                 ;;
1122         dnl (
1123         alpha*)
1124                 ## alpha cruft
1125                 SXE_CHECK_CPU_ALPHA
1126                 ;;
1127         dnl (
1128         powerpc*)
1129                 ## ya know what
1130                 SXE_CHECK_CPU_PPC
1131                 ;;
1132         esac
1133 ])dnl SXE_CHECK_CPU
1134
1135 AC_DEFUN([SXE_CHECK_CPU_SPARC], [dnl
1136         AC_PATH_PROG([PRTDIAG], [prtdiag], [prtdiag],
1137                 [$PATH:/usr/platform/`uname -i`/sbin/:/usr/platform/`uname -m`/sbin/])
1138         cputype=$((((grep cpu /proc/cpuinfo | cut -d: -f2) ; \
1139                 ($PRTDIAG -v |grep -i sparc) ; \
1140                 grep -i cpu "/var/run/dmesg.boot" ) | head -n 1) 2> /dev/null)
1141         cputype=$(echo "$cputype" | tr -d ' -' |tr $as_cr_LETTERS $as_cr_letters)
1142
1143         case "$cputype" in
1144         dnl (
1145         *ultrasparciv*)
1146                 sxe_gcc_arch="ultrasparc4 ultrasparc3 ultrasparc v9"
1147                 ;;
1148         dnl (
1149         *ultrasparciii*)
1150                 sxe_gcc_arch="ultrasparc3 ultrasparc v9"
1151                 ;;
1152         dnl (
1153         *ultrasparc*)
1154                 sxe_gcc_arch="ultrasparc v9"
1155                 ;;
1156         dnl (
1157         *supersparc*|*tms390z5[[05]]*)
1158                 sxe_gcc_arch="supersparc v8"
1159                 ;;
1160         dnl (
1161         *hypersparc*|*rt62[[056]]*)
1162                 sxe_gcc_arch="hypersparc v8"
1163                 ;;
1164         dnl (
1165         *cypress*)
1166                 sxe_gcc_arch=cypress
1167                 ;;
1168         esac
1169 ])dnl SXE_CHECK_CPU_SPARC
1170
1171 AC_DEFUN([SXE_CHECK_CPU_ALPHA], [dnl
1172         case "$host_cpu" in
1173         dnl (
1174         alphaev5)
1175                 sxe_gcc_arch="ev5"
1176                 ;;
1177         dnl (
1178         alphaev56)
1179                 sxe_gcc_arch="ev56"
1180                 ;;
1181         dnl (
1182         alphapca56)
1183                 sxe_gcc_arch="pca56 ev56"
1184                 ;;
1185         dnl (
1186         alphapca57)
1187                 sxe_gcc_arch="pca57 pca56 ev56"
1188                 ;;
1189         dnl (
1190         alphaev6)
1191                 sxe_gcc_arch="ev6"
1192                 ;;
1193         dnl (
1194         alphaev67)
1195                 sxe_gcc_arch="ev67"
1196                 ;;
1197         dnl (
1198         alphaev68)
1199                 sxe_gcc_arch="ev68 ev67"
1200                 ;;
1201         dnl (
1202         alphaev69)
1203                 sxe_gcc_arch="ev69 ev68 ev67"
1204                 ;;
1205         dnl (
1206         alphaev7)
1207                 sxe_gcc_arch="ev7 ev69 ev68 ev67"
1208                 ;;
1209         dnl (
1210         alphaev79)
1211                 sxe_gcc_arch="ev79 ev7 ev69 ev68 ev67"
1212                 ;;
1213         esac
1214 ])dnl SXE_CHECK_CPU_ALPHA
1215
1216 AC_DEFUN([SXE_CHECK_CPU_PPC], [dnl
1217         cputype=$(((grep cpu /proc/cpuinfo | head -n 1 | \
1218                 cut -d: -f2 | cut -d, -f1 | sed 's/ //g') ; \
1219                 /usr/bin/machine ; \
1220                 /bin/machine; \
1221                 grep CPU /var/run/dmesg.boot | \
1222                 head -n 1 | cut -d" " -f2) 2> /dev/null)
1223         cputype=$(echo $cputype | sed -e 's/ppc//g;s/ *//g')
1224
1225         case "$cputype" in
1226         dnl (
1227         *750*)
1228                 sxe_gcc_arch="750 G3"
1229                 ;;
1230         dnl (
1231         *740[[0-9]]*)
1232                 sxe_gcc_arch="$cputype 7400 G4"
1233                 ;;
1234         dnl (
1235         *74[[4-5]][[0-9]]*)
1236                 sxe_gcc_arch="$cputype 7450 G4"
1237                 ;;
1238         dnl (
1239         *74[[0-9]][[0-9]]*)
1240                 sxe_gcc_arch="$cputype G4"
1241                 ;;
1242         dnl (
1243         *970*)
1244                 sxe_gcc_arch="970 G5 power4"
1245                 ;;
1246         dnl (
1247         *POWER4*|*power4*|*gq*)
1248                 sxe_gcc_arch="power4 970"
1249                 ;;
1250         dnl (
1251         *POWER5*|*power5*|*gr*|*gs*)
1252                 sxe_gcc_arch="power5 power4 970"
1253                 ;;
1254         dnl (
1255         603ev|8240)
1256                 sxe_gcc_arch="$cputype 603e 603"
1257                 ;;
1258         dnl (
1259         *)
1260                 sxe_gcc_arch="$cputype"
1261                 ;;
1262         esac
1263         sxe_gcc_arch="$sxe_gcc_arch powerpc"
1264 ])dnl SXE_CHECK_CPU_PPC
1265
1266 AC_DEFUN([SXE_CHECK_CPU_PC], [dnl
1267         ## use cpuid codes,
1268         AC_REQUIRE([SXE_PROC_CPUID])
1269
1270         case "$sxe_cv_proc_cpuid_00000000" in
1271         dnl (
1272         *:756e6547:*:*)
1273                 ## Intel
1274                 case "$sxe_cv_proc_cpuid_00000001" in
1275                 dnl (
1276                 *5[[48]]?:*:*:*)
1277                         sxe_gcc_arch="pentium-mmx pentium"
1278                         ;;
1279                 dnl (
1280                 *5??:*:*:*)
1281                         sxe_gcc_arch="pentium"
1282                         ;;
1283                 dnl (
1284                 *6[[3456]]?:*:*:*)
1285                         sxe_gcc_arch="pentium2 pentiumpro"
1286                         ;;
1287                 dnl (
1288                 *6a?:*[[01]]:*:*)
1289                         sxe_gcc_arch="pentium2 pentiumpro"
1290                         ;;
1291                 dnl (
1292                 *6a?:*[[234]]:*:*)
1293                         sxe_gcc_arch="pentium3 pentiumpro"
1294                         icc_flags="-xK"
1295                         ;;
1296                 dnl (
1297                 *69?:*:*:*)
1298                         sxe_gcc_arch="pentium-m pentium3 pentiumpro"
1299                         icc_flags="-xK"
1300                         ;;
1301                 dnl (
1302                 *6d?:*:*:*)
1303                         sxe_gcc_arch="pentium-m pentium3 pentiumpro"
1304                         ;;
1305                 dnl (
1306                 *6[[78b]]?:*:*:*)
1307                         sxe_gcc_arch="pentium3 pentiumpro"
1308                         icc_flags="-xK"
1309                         ;;
1310                 dnl (
1311                 *6f?:*:*:*)
1312                         ## intel core 2 duo
1313                         sxe_gcc_arch="nocona pentium4 pentiumpro"
1314                         ## icc flags here
1315                         ## icc_flags="??"
1316                         ;;
1317                 dnl (
1318                 *6??:*:*:*)
1319                         sxe_gcc_arch="pentiumpro"
1320                         ;;
1321                 dnl (
1322                 *f3[[347]]:*:*:*|*f4[1347]:*:*:*)
1323                         icc_flags="-xP -xN -xW -xK"
1324                         case "$host_cpu" in
1325                         dnl (
1326                         x86_64*)
1327                                 sxe_gcc_arch="nocona pentium4 pentiumpro"
1328                                 ;;
1329                         dnl (
1330                         *)
1331                                 sxe_gcc_arch="prescott pentium4 pentiumpro"
1332                                 ;;
1333                         esac
1334                         ;;
1335                 dnl (
1336                 *f??:*:*:*)
1337                         icc_flags="-xN -xW -xK"
1338                         sxe_gcc_arch="pentium4 pentiumpro"
1339                         ;;
1340                 esac
1341                 ;;
1342         dnl (
1343         *:68747541:*:*)
1344                 ## AMD
1345                 case "$sxe_cv_proc_cpuid_00000001" in
1346                 dnl (
1347                 *5[[67]]?:*:*:*)
1348                         sxe_gcc_arch="k6"
1349                         ;;
1350                 dnl (
1351                 *5[[8d]]?:*:*:*)
1352                         sxe_gcc_arch="k6-2 k6"
1353                         ;;
1354                 dnl (
1355                 *5[[9]]?:*:*:*)
1356                         sxe_gcc_arch="k6-3 k6"
1357                         ;;
1358                 dnl (
1359                 *60?:*:*:*)
1360                         sxe_gcc_arch="k7"
1361                         ;;
1362                 dnl (
1363                 *6[[12]]?:*:*:*)
1364                         sxe_gcc_arch="athlon k7"
1365                         ;;
1366                 dnl (
1367                 *6[[34]]?:*:*:*)
1368                         sxe_gcc_arch="athlon-tbird k7"
1369                         ;;
1370                 dnl (
1371                 *67?:*:*:*)
1372                         sxe_gcc_arch="athlon-4 athlon k7"
1373                         ;;
1374                 dnl (
1375                 *6[[68a]]?:*:*:*)
1376                         case "$sxe_cv_proc_cpuid_80000006" in
1377                         dnl (
1378                         *:*:*[[1-9a-f]]??????:*) # (L2 = ecx >> 16) >= 256
1379                                 sxe_gcc_arch="athlon-xp athlon-4 athlon k7"
1380                                 ;;
1381                         dnl (
1382                         *)
1383                                 sxe_gcc_arch="athlon-4 athlon k7"
1384                                 ;;
1385                         esac
1386                         ;;
1387                 dnl (
1388                 *f[[4cef8b]]?:*:*:*)
1389                         sxe_gcc_arch="athlon64 k8"
1390                         ;;
1391                 dnl (
1392                 *f5?:*:*:*)
1393                         sxe_gcc_arch="opteron k8"
1394                         ;;
1395                 dnl (
1396                 *f7?:*:*:*)
1397                         sxe_gcc_arch="athlon-fx opteron k8"
1398                         ;;
1399                 dnl (
1400                 *f??:*:*:*)
1401                         sxe_gcc_arch="k8"
1402                         ;;
1403                 esac
1404                 ;;
1405         dnl (
1406         *:746e6543:*:*)
1407                 # IDT
1408                 case "$sxe_cv_proc_cpuid_00000001" in
1409                 dnl (
1410                 *54?:*:*:*)
1411                         sxe_gcc_arch="winchip-c6"
1412                         ;;
1413                 dnl (
1414                 *58?:*:*:*)
1415                         sxe_gcc_arch="winchip2"
1416                         ;;
1417                 dnl (
1418                 *6[[78]]?:*:*:*)
1419                         sxe_gcc_arch="c3"
1420                         ;;
1421                 dnl (
1422                 *69?:*:*:*)
1423                         sxe_gcc_arch="c3-2 c3"
1424                         ;;
1425                 esac
1426                 ;;
1427         esac
1428
1429         ## nothing found? => fallback
1430         if test -z "$sxe_gcc_arch"; then
1431                 ## apply a generic strategy
1432                 case "$host_cpu" in
1433                 i586*)
1434                         sxe_gcc_arch="pentium"
1435                         ;;
1436                 i686*)
1437                         sxe_gcc_arch="pentiumpro"
1438                         ;;
1439                 esac
1440         fi
1441 ])dnl SXE_CHECK_CPU_PC
1442
1443
1444 AC_DEFUN([SXE_GCC_ARCHFLAG], [dnl
1445         AC_REQUIRE([AC_PROG_CC])
1446         AC_REQUIRE([AC_CANONICAL_HOST])
1447
1448         AC_ARG_WITH([gcc-arch], AS_HELP_STRING([--with-gcc-arch=<arch>], [
1449                         use architecture <arch> for gcc -march/-mtune,
1450                         instead of guessing]),
1451                 [sxe_gcc_arch=$withval], [sxe_gcc_arch=yes])
1452
1453         AC_MSG_CHECKING([for gcc architecture flag])
1454         AC_MSG_RESULT([])
1455         AC_CACHE_VAL([sxe_cv_gcc_archflag], [
1456                 ## initialise to unknown
1457                 sxe_cv_gcc_archflag="unknown"
1458
1459                 if test "$GCC" = yes; then
1460                         if test "$sxe_gcc_arch" = "yes" -a \
1461                                 "$cross_compiling" = "no"; then
1462                                 sxe_gcc_arch=""
1463                                 SXE_CHECK_CPU
1464                         fi
1465
1466                         if test -n "$sxe_gcc_arch" -a "$sxe_gcc_arch" != "no"; then
1467                                 for arch in $sxe_gcc_arch; do
1468                                         if test "[]m4_default([$1],yes)" = "yes"; then
1469                                                 ## if we require portable code
1470                                                 archflags="-mtune=$arch"
1471                                                 ## -mcpu=$arch and m$arch generate
1472                                                 ## nonportable code on every arch except
1473                                                 ## x86.  And some other arches
1474                                                 ## (e.g. Alpha) don't accept -mtune.
1475                                                 ## Grrr.
1476                                                 case "$host_cpu" in
1477                                                 dnl (
1478                                                 i*86|x86_64*)
1479                                                         archflags="$archflags -mcpu=$arch -m$arch"
1480                                                         ;;
1481                                                 esac
1482                                         else
1483                                                 archflags="-march=$arch -mcpu=$arch -m$arch"
1484                                         fi
1485                                         for flag in $archflags; do
1486                                                 SXE_CHECK_COMPILER_FLAGS([$flag],
1487                                                         [sxe_cv_gcc_archflag="$flag"; break])
1488                                         done
1489                                         if test "$sxe_cv_gcc_archflag" != "unknown"; then
1490                                                 break
1491                                         fi
1492                                 done
1493                         fi
1494                 fi
1495                 ])
1496
1497         AC_MSG_CHECKING([for gcc architecture flag])
1498         AC_MSG_RESULT([$sxe_cv_gcc_archflag])
1499         if test "$sxe_cv_gcc_archflag" = "unknown"; then
1500                 m4_default([$3],:)
1501         else
1502                 m4_default([$2], [archflags="$sxe_cv_gcc_archflag"])
1503         fi
1504 ])dnl SXE_GCC_ARCHFLAG
1505
1506
1507 #### http://autoconf-archive.cryp.to/sxe_check_define.html
1508 AC_DEFUN([SXE_CHECK_DEFINED], [dnl
1509         AS_VAR_PUSHDEF([ac_var],[ac_cv_defined_$2])dnl
1510
1511         AC_CACHE_CHECK([for $1 defined], ac_var,
1512                 AC_TRY_COMPILE($1,[
1513 #ifndef $2
1514 int ok;
1515 #else
1516 choke me
1517 #endif
1518                 ],
1519                 AS_VAR_SET(ac_var, [yes]),
1520                 AS_VAR_SET(ac_var, [no])))
1521
1522         AS_IF([test AS_VAR_GET(ac_var) != "no"], [$3], [$4])
1523         AS_VAR_POPDEF([ac_var])
1524 ])dnl SXE_CHECK_DEFINED
1525
1526 AC_DEFUN([SXE_CHECK_FUNC], [dnl
1527         AS_VAR_PUSHDEF([ac_var], [ac_cv_func_$2])dnl
1528         AC_CACHE_CHECK([for $2], ac_var, [
1529                 dnl AC_LANG_FUNC_LINK_TRY
1530                 AC_LINK_IFELSE([AC_LANG_PROGRAM([$1
1531 #undef $2
1532 char $2 ();
1533                         ], [
1534 char (*f) () = $2;
1535 return f != $2;
1536                         ])], [
1537                         AS_VAR_SET(ac_var, [yes])], [
1538                         AS_VAR_SET(ac_var, [no])])])
1539
1540         AS_IF([test AS_VAR_GET(ac_var) = "yes"], [$3], [$4])
1541         AS_VAR_POPDEF([ac_var])
1542 ])dnl SXE_CHECK_FUNC
1543
1544
1545
1546 AC_DEFUN([SXE_CHECK_C99_NJSF], [dnl
1547         dnl If we have a compiler that could do c99 do try to add the flag
1548         if test "$__GCC3" = "yes" ; then
1549                 SXE_APPEND_UNDUP("-std=c99", c_switch_site)
1550                 AC_MSG_CHECKING([for C99 support])
1551                 save_c_switch_site=$c_switch_site
1552                 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1553 #include <stdlib.h>
1554 ]],[[
1555 return 0;
1556 ]])],  [AC_MSG_RESULT(yes)
1557         have_c99="yes"],
1558        [c_switch_site=$sace_c_switch_site
1559                 AC_MSG_RESULT(no)
1560                 AC_MSG_WARN([C99 not supported, reverting option append])
1561                 have_c99="no"])
1562         elif test "$__SUNPRO_C" = "yes" ; then
1563                 AC_MSG_CHECKING([for C99 support])
1564                 save_c_switch_site=$c_switch_site
1565                 SXE_APPEND_UNDUP("-xc99", c_switch_site)
1566                 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1567 #include <stdlib.h>
1568 ]],[[
1569 return 0;
1570 ]])],  [AC_MSG_RESULT(yes)
1571                 have_c99="yes"],
1572        [c_switch_site=$sace_c_switch_site
1573                 AC_MSG_RESULT(no)
1574                 have_c99="no"])
1575         fi
1576 ])dnl SXE_CHECK_C99_NJSF
1577
1578
1579 AC_DEFUN([SXE_C_TYPEOF], [dnl
1580         dnl check for the typeof extension
1581         AC_MSG_CHECKING([for typeof])
1582         AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1583 int i; __typeof__(i) j;
1584 ]])], [typeofname="__typeof__"], [dnl else
1585                 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1586 int i; typeof(i) j;
1587 ]])], [typeofname="typeof"], [typeofname=no])])
1588         AC_MSG_RESULT([$typeofname])
1589         if test "$typeofname" != "no"; then
1590                 AC_DEFINE_UNQUOTED([TYPEOF], [$typeofname],
1591                         [How to use the typeof extension.])
1592         fi
1593 ])dnl SXE_C_TYPEOF
1594
1595 AC_DEFUN([SXE_C_INLINE], [dnl
1596         AC_C_INLINE
1597         if test "$ac_cv_c_inline" != "no" -a "$GCC" = "yes"; then
1598                 SXE_ADD_CRUFT_OBJS([inline.o])
1599         fi
1600 ])dnl SXE_C_INLINE
1601
1602
1603 AC_DEFUN([SXE_CHECK_BROKEN_RESTRICT], [dnl
1604         AC_MSG_CHECKING([support for restrict keyword])
1605         AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1606 extern void f(void*restrict[]);
1607 ]])], [have_restrict="yes"], [have_restrict="no"])
1608         if test "$have_restrict" = "no"; then
1609                 AC_DEFINE_UNQUOTED([restrict], [],
1610                         [Define restrict to nothing])
1611         fi
1612         AC_MSG_RESULT([$typeofname])
1613 ])dnl SXE_CHECK_BROKEN_RESTRICT 
1614
1615 dnl recommended interface macros
1616 ## compiler wrapper
1617 AC_DEFUN([SXE_CHECK_CC], [dnl
1618
1619         AC_PROG_CPP
1620         AC_HEADER_STDC
1621         AC_PROG_CC([gcc icc cc])
1622         dnl AC_PROG_CC_STDC
1623         AC_PROG_CC_C99
1624
1625         ## check for machine and architecture
1626         SXE_CHECK_MACHARCH
1627
1628         ## check for C compiler characteristics
1629         SXE_CHECK_CC_VERSION
1630         if test "$GCC" = "yes"; then
1631                 SXE_CHECK_BROKEN_GCC
1632         fi
1633         AC_C_RESTRICT
1634         if test "$ac_cv_prog_cc_c99" != ""; then
1635                 SXE_CHECK_BROKEN_RESTRICT
1636         fi
1637
1638         ## check for libc
1639         SXE_CHECK_LIBC
1640         SXE_CHECK_LIBC_VERSION
1641         dnl Non-ordinary link usually requires -lc
1642         if test "$ordinary_link" = "no" -a -z "$libs_standard"; then
1643                 libs_standard="-lc"
1644         fi
1645
1646         SXE_CHECK_CC_HACKS
1647         SXE_CHECK_CC_CHAR
1648         SXE_CHECK_CC_NESTED_FUNS
1649
1650         ## Canonicalize the configuration name.
1651         ## Commented out, lets see if anything breaks. --SY.
1652         ## SXE_STRIP_4TH_COMPONENT(ac_cv_build_alias)
1653         ## SXE_STRIP_4TH_COMPONENT(ac_cv_build)
1654         AC_SUBST([configuration], [$ac_cv_build])
1655
1656         AM_PROG_CC_C_O
1657
1658 ])dnl SXE_CHECK_CC
1659
1660
1661 AC_DEFUN([SXE_CHECK_CFLAGS], [dnl
1662         dnl #### This may need to be overhauled so that all of SXEMACS_CC's flags
1663         dnl are handled separately, not just the xe_cflags_warning stuff.
1664
1665         ## Use either command line flag, environment var, or autodetection
1666         if test "$with_ridiculously_aggressive_optimisations" = "yes"; then
1667                 CFLAGS=""
1668                 SXE_DEBUGFLAGS
1669                 SXE_WARNFLAGS
1670                 SXE_OPTIFLAGS
1671                 SXE_CFLAGS="$debugflags $optiflags $warnflags"
1672
1673                 SXE_FEATFLAGS
1674                 SXE_CFLAGS="$debugflags $featflags $optiflags $warnflags"
1675
1676         elif test "$CFLAGS_uspecified_p" = "no" -o \
1677                 "$ac_test_CFLAGS" != "set"; then
1678                 SXE_DEBUGFLAGS
1679                 SXE_WARNFLAGS
1680
1681                 ## the old settings
1682                 ## Following values of CFLAGS are known to work well.
1683                 ## Should we take debugging options into consideration?
1684                 SXE_CHECK_COMPILER_FLAGS([-xO4], [dnl
1685                         ## ah, it's sunos4*
1686                         optiflags="${optiflags} -xO4"], [dnl
1687                         SXE_CHECK_COMPILER_FLAGS([-xO2], [dnl
1688                                 ## oh, a sol2
1689                                 optiflags="${optiflags} -xO2"])])
1690                 SXE_CHECK_COMPILER_FLAGS([-O3], [dnl
1691                         ## gcc, icc, decc, et al.
1692                         optiflags="${optiflags} -O3"])
1693
1694                 ## xlc specific
1695                 SXE_CHECK_COMPILER_FLAGS([-qnoansialias -qlibansi], [dnl
1696                         optiflags="${optiflags} -qnoansialias -qlibansi"])
1697                 SXE_CHECK_COMPILER_FLAGS([-qro -qmaxmem=20000], [dnl
1698                         optiflags="${optiflags} -qro -qmaxmem=20000"])
1699
1700                 ## icc specific
1701                 SXE_CHECK_COMPILER_FLAGS([-inline-level=2], [dnl
1702                         ## ah, one of the new flavours, tasty
1703                         optiflags="${optiflags} -inline-level=2"], [dnl
1704                         SXE_CHECK_COMPILER_FLAGS([-Ob2], [dnl
1705                                 ## deprecated nowadays
1706                                 optiflags="${optiflags} -Ob2"])])
1707
1708                 ## final check
1709                 if test -z "${optiflags}"; then
1710                         SXE_CHECK_COMPILER_FLAGS([-O], [dnl
1711                                 ## The only POSIX-approved flag
1712                                 optiflags="-O"])
1713                 fi
1714
1715                 SXE_CFLAGS="$debugflags $optiflags $warnflags"
1716
1717                 SXE_FEATFLAGS
1718                 SXE_CFLAGS="$debugflags $featflags $optiflags $warnflags"
1719         else
1720                 SXE_CFLAGS=${USER_CFLAGS}
1721                 featflags=""
1722                 debugflags=""
1723                 optiflags=""
1724                 warnflags=""
1725         fi
1726
1727         ## unset the werror flag again
1728         SXE_LANG_WERROR([off])
1729
1730         CFLAGS="$SXE_CFLAGS"
1731         AC_MSG_CHECKING([for preferred CFLAGS])
1732         AC_MSG_RESULT([${SXE_CFLAGS}])
1733
1734         AC_MSG_NOTICE([
1735 If you wish to ADD your own flags you want to stop here and rerun the
1736 configure script like so:
1737   configure CFLAGS=<to-be-added-flags>
1738
1739 You can always override the determined CFLAGS, partially or totally,
1740 using
1741   make -C <directory> CFLAGS=<your-own-flags> [target]
1742 or
1743   make CFLAGS=<your-own-flags> [target]
1744 respectively
1745
1746 NOTE: -C <directory> option is not available on all systems
1747                 ])
1748 ])dnl SXE_CHECK_CFLAGS
1749
1750
1751 AC_DEFUN([SXE_CC_LIBRARY_PATH], [dnl
1752         ## arg #1 variable to store name in,
1753         ## if omitted defaults to `sxe_cv_tmp_gcc_library_path'
1754         pushdef([VAR], ifelse($1,[],[sxe_cv_tmp_gcc_library_path],$1))
1755
1756         for i in ${LDFLAGS}; do
1757                 case $i in
1758                 -L*)
1759                         __LP=${i:2}:${__LP:-.}
1760                         ;;
1761                 *)
1762                         ;;
1763                 esac
1764         done
1765         SXE_EXPAND_VAR([${libdir}], [__ld])
1766         []VAR[]=${__ld:-.}:${__LP:-.}
1767
1768         popdef([VAR])
1769 ])dnl SXE_CC_LIBRARY_PATH
1770
1771
1772 AC_DEFUN([SXE_CC_LIBRARY_LOCATION], [dnl
1773         ## arg #1 the library to seek after
1774         ## arg #2 (optional) checking message
1775         pushdef([liborig], [$1])
1776         pushdef([liblink], patsubst(patsubst(liborig, [lib], [-l]), [\.[^.]+$], []))
1777         pushdef([libname], translit(liborig, [-,.], [___]))
1778         pushdef([LIBNAME], translit(liborig, [-,.a-z], [___A-Z]))
1779         pushdef([libchk], ifelse($2,[],[for absolute path of ]liborig,$2))
1780
1781         ## use gcc's -print-file-name
1782         AC_REQUIRE([SXE_CC_LIBRARY_PATH])
1783         AC_MSG_CHECKING([]libchk[])
1784         ## not protected against other CCs (yet)!
1785         sxe_cv_loc_[]libname[]=$(LIBRARY_PATH=${sxe_cv_tmp_gcc_library_path} \
1786                 ${CC} -print-file-name=[]liborig[])
1787         AC_MSG_RESULT(${sxe_cv_loc_[]libname[]})
1788
1789         []LIBNAME[]=${sxe_cv_loc_[]libname[]}
1790
1791         popdef([libchk])
1792         popdef([liblink])
1793         popdef([liborig])
1794         popdef([libname])
1795         popdef([LIBNAME])
1796 ])dnl SXE_CC_LIBRARY_LOCATION
1797
1798
1799 AC_DEFUN([SXE_CHECK_ANON_STRUCTS], [
1800         AC_MSG_CHECKING([whether C compiler can cope with anonymous structures])
1801         AC_LANG_PUSH(C)
1802         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1803 union __test_u {
1804         int i;
1805         struct {
1806                 char c;
1807                 char padc;
1808                 short int pads;
1809         };
1810 };
1811         ]], [[
1812         union __test_u tmp = {.c = '4'};
1813         ]])], [
1814                 sxe_cv_have_anon_structs="yes"
1815         ], [
1816                 sxe_cv_have_anon_structs="no"
1817         ])
1818         AC_MSG_RESULT([${sxe_cv_have_anon_structs}])
1819
1820         if test "${sxe_cv_have_anon_structs}" = "yes"; then
1821                 AC_DEFINE([HAVE_ANON_STRUCTS], [1], [
1822                         Whether c1x anon structs work])
1823                 $1
1824                 :
1825         else
1826                 $2
1827                 :
1828         fi
1829         AC_LANG_POP()
1830 ])dnl SXE_CHECK_ANON_STRUCTS
1831
1832 dnl sxe-compiler.m4 ends here