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