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