root/mpich2/trunk/confdb/aclocal_cc.m4 @ 4777

Revision 4777, 82.5 KB (checked in by balaji, 5 months ago)

Use PAC_ARG_STRICT instead of AC_ARG_ENABLE + PAC_CC_STRICT
combination, in cases where we don't care about the output value.

Also, remove some duplication in PAC_ARG_STRICT and just call
PAC_CC_STRICT internally, instead.

Reviewed by goodell.

Line 
1dnl
2dnl This is a replacement for AC_PROG_CC that does not prefer gcc and
3dnl that does not mess with CFLAGS.  See acspecific.m4 for the original defn.
4dnl
5dnl/*D
6dnl PAC_PROG_CC - Find a working C compiler
7dnl
8dnl Synopsis:
9dnl PAC_PROG_CC
10dnl
11dnl Output Effect:
12dnl   Sets the variable CC if it is not already set
13dnl
14dnl Notes:
15dnl   Unlike AC_PROG_CC, this does not prefer gcc and does not set CFLAGS.
16dnl   It does check that the compiler can compile a simple C program.
17dnl   It also sets the variable GCC to yes if the compiler is gcc.  It does
18dnl   not yet check for some special options needed in particular for
19dnl   parallel computers, such as -Tcray-t3e, or special options to get
20dnl   full ANSI/ISO C, such as -Aa for HP.
21dnl
22dnl D*/
23dnl 2.52 doesn't have AC_PROG_CC_GNU
24ifdef([AC_PROG_CC_GNU],,[AC_DEFUN([AC_PROG_CC_GNU],)])
25AC_DEFUN([PAC_PROG_CC],[
26AC_PROVIDE([AC_PROG_CC])
27AC_CHECK_PROGS(CC, cc xlC xlc pgcc icc pathcc gcc )
28test -z "$CC" && AC_MSG_ERROR([no acceptable cc found in \$PATH])
29PAC_PROG_CC_WORKS
30AC_PROG_CC_GNU
31if test "$ac_cv_prog_gcc" = yes; then
32  GCC=yes
33else
34  GCC=
35fi
36])
37dnl
38dnl/*D
39dnl PAC_C_CHECK_COMPILER_OPTION - Check that a compiler option is accepted
40dnl without warning messages
41dnl
42dnl Synopsis:
43dnl PAC_C_CHECK_COMPILER_OPTION(optionname,action-if-ok,action-if-fail)
44dnl
45dnl Output Effects:
46dnl
47dnl If no actions are specified, a working value is added to 'COPTIONS'
48dnl
49dnl Notes:
50dnl This is now careful to check that the output is different, since
51dnl some compilers are noisy.
52dnl
53dnl We are extra careful to prototype the functions in case compiler options
54dnl that complain about poor code are in effect.
55dnl
56dnl Because this is a long script, we have ensured that you can pass a
57dnl variable containing the option name as the first argument.
58dnl D*/
59AC_DEFUN([PAC_C_CHECK_COMPILER_OPTION],[
60AC_MSG_CHECKING([whether C compiler accepts option $1])
61save_CFLAGS="$CFLAGS"
62CFLAGS="$1 $CFLAGS"
63rm -f conftest.out
64echo 'int foo(void);int foo(void){return 0;}' > conftest2.c
65echo 'int main(void);int main(void){return 0;}' > conftest.c
66if ${CC-cc} $save_CFLAGS $CPPFLAGS -o conftest conftest.c $LDFLAGS >conftest.bas 2>&1 ; then
67   if ${CC-cc} $CFLAGS $CPPFLAGS -o conftest conftest.c $LDFLAGS >conftest.out 2>&1 ; then
68      if diff -b conftest.out conftest.bas >/dev/null 2>&1 ; then
69         AC_MSG_RESULT(yes)
70         AC_MSG_CHECKING([whether routines compiled with $1 can be linked with ones compiled without $1])       
71         rm -f conftest.out
72         rm -f conftest.bas
73         if ${CC-cc} -c $save_CFLAGS $CPPFLAGS conftest2.c >conftest2.out 2>&1 ; then
74            if ${CC-cc} $CFLAGS $CPPFLAGS -o conftest conftest2.o conftest.c $LDFLAGS >conftest.bas 2>&1 ; then
75               if ${CC-cc} $CFLAGS $CPPFLAGS -o conftest conftest2.o conftest.c $LDFLAGS >conftest.out 2>&1 ; then
76                  if diff -b conftest.out conftest.bas >/dev/null 2>&1 ; then
77                     AC_MSG_RESULT(yes)   
78                     CFLAGS="$save_CFLAGS"
79                     ifelse($2,,COPTIONS="$COPTIONS $1",$2)
80                  elif test -s conftest.out ; then
81                     cat conftest.out >&AC_FD_CC
82                     AC_MSG_RESULT(no)
83                     CFLAGS="$save_CFLAGS"
84                     $3
85                  else
86                     AC_MSG_RESULT(no)
87                     CFLAGS="$save_CFLAGS"
88                     $3
89                  fi 
90               else
91                  if test -s conftest.out ; then
92                     cat conftest.out >&AC_FD_CC
93                  fi
94                  AC_MSG_RESULT(no)
95                  CFLAGS="$save_CFLAGS"
96                  $3
97               fi
98            else
99               # Could not link with the option!
100               AC_MSG_RESULT(no)
101            fi
102         else
103            if test -s conftest2.out ; then
104               cat conftest2.out >&AC_FD_CC
105            fi
106            AC_MSG_RESULT(no)
107            CFLAGS="$save_CFLAGS"
108            $3
109         fi
110      else
111         cat conftest.out >&AC_FD_CC
112         AC_MSG_RESULT(no)
113         $3
114         CFLAGS="$save_CFLAGS"         
115      fi
116   else
117      AC_MSG_RESULT(no)
118      $3
119      if test -s conftest.out ; then cat conftest.out >&AC_FD_CC ; fi   
120      CFLAGS="$save_CFLAGS"
121   fi
122else
123    # Could not compile without the option!
124    AC_MSG_RESULT(no)
125fi
126# This is needed for Mac OSX 10.5
127rm -rf conftest.dSYM
128rm -f conftest*
129])
130dnl
131dnl/*D
132dnl PAC_C_OPTIMIZATION - Determine C options for producing optimized code
133dnl
134dnl Synopsis
135dnl PAC_C_OPTIMIZATION([action if found])
136dnl
137dnl Output Effect:
138dnl Adds options to 'COPTIONS' if no other action is specified
139dnl
140dnl Notes:
141dnl This is a temporary standin for compiler optimization.
142dnl It should try to match known systems to known compilers (checking, of
143dnl course), and then falling back to some common defaults.
144dnl Note that many compilers will complain about -g and aggressive
145dnl optimization. 
146dnl D*/
147AC_DEFUN([PAC_C_OPTIMIZATION],[
148    for copt in "-O4 -Ofast" "-Ofast" "-fast" "-O3" "-xO3" "-O" ; do
149        PAC_C_CHECK_COMPILER_OPTION($copt,found_opt=yes,found_opt=no)
150        if test "$found_opt" = "yes" ; then
151            ifelse($1,,COPTIONS="$COPTIONS $copt",$1)
152            break
153        fi
154    done
155    if test "$ac_cv_prog_gcc" = "yes" ; then
156        for copt in "-fomit-frame-pointer" "-finline-functions" \
157                 "-funroll-loops" ; do
158            PAC_C_CHECK_COMPILER_OPTION($copt,found_opt=yes,found_opt=no)
159            if test $found_opt = "yes" ; then
160                ifelse($1,,COPTIONS="$COPTIONS $copt",$1)
161                # no break because we're trying to add them all
162            fi
163        done
164        # We could also look for architecture-specific gcc options
165    fi
166
167])
168dnl
169dnl/*D
170dnl PAC_C_DEPENDS - Determine how to use the C compiler to generate
171dnl dependency information
172dnl
173dnl Synopsis:
174dnl PAC_C_DEPENDS
175dnl
176dnl Output Effects:
177dnl Sets the following shell variables and call AC_SUBST for them:
178dnl+ C_DEPEND_OPT - Compiler options needed to create dependencies
179dnl. C_DEPEND_OUT - Shell redirection for dependency file (may be empty)
180dnl. C_DEPEND_PREFIX - Empty (null) or true; this is used to handle
181dnl  systems that do not provide dependency information
182dnl- C_DEPEND_MV - Command to move created dependency file
183dnl Also creates a Depends file in the top directory (!).
184dnl
185dnl In addition, the variable 'C_DEPEND_DIR' must be set to indicate the
186dnl directory in which the dependency files should live. 
187dnl
188dnl Notes:
189dnl A typical Make rule that exploits this macro is
190dnl.vb
191dnl #
192dnl # Dependency processing
193dnl .SUFFIXES: .dep
194dnl DEP_SOURCES = ${SOURCES:%.c=.dep/%.dep}
195dnl C_DEPEND_DIR = .dep
196dnl Depends: ${DEP_SOURCES}
197dnl         @-rm -f Depends
198dnl         cat .dep/*.dep >Depends
199dnl .dep/%.dep:%.c
200dnl         @if [ ! -d .dep ] ; then mkdir .dep ; fi
201dnl         @@C_DEPEND_PREFIX@ ${C_COMPILE} @C_DEPEND_OPT@ $< @C_DEPEND_OUT@
202dnl         @@C_DEPEND_MV@
203dnl
204dnl depends-clean:
205dnl         @-rm -f *.dep ${srcdir}/*.dep Depends ${srcdir}/Depends
206dnl         @-touch Depends
207dnl.ve
208dnl
209dnl For each file 'foo.c', this creates a file 'foo.dep' and creates a file
210dnl 'Depends' that contains all of the '*.dep' files.
211dnl
212dnl For your convenience, the autoconf variable 'C_DO_DEPENDS' names a file
213dnl that may contain this code (you must have `dependsrule` or
214dnl `dependsrule.in` in the same directory as the other auxillery configure
215dnl scripts (set with dnl 'AC_CONFIG_AUX_DIR').  If you use `dependsrule.in`,
216dnl you must have `dependsrule` in 'AC_OUTPUT' before this `Makefile`.
217dnl
218dnl D*/
219dnl
220dnl Eventually, we can add an option to the C_DEPEND_MV to strip system
221dnl includes, such as /usr/xxxx and /opt/xxxx
222dnl
223AC_DEFUN([PAC_C_DEPENDS],[
224AC_SUBST(C_DEPEND_OPT)AM_IGNORE(C_DEPEND_OPT)
225AC_SUBST(C_DEPEND_OUT)AM_IGNORE(C_DEPEND_OUT)
226AC_SUBST(C_DEPEND_MV)AM_IGNORE(C_DEPEND_MV)
227AC_SUBST(C_DEPEND_PREFIX)AM_IGNORE(C_DEPEND_PREFIX)
228AC_SUBST_FILE(C_DO_DEPENDS)
229dnl set the value of the variable to a
230dnl file that contains the dependency code, such as
231dnl ${top_srcdir}/maint/dependrule
232if test -n "$ac_cv_c_depend_opt" ; then
233    AC_MSG_RESULT([Option $ac_cv_c_depend_opt creates dependencies (cached)])
234    C_DEPEND_OUT="$ac_cv_c_depend_out"
235    C_DEPEND_MV="$ac_cv_c_depend_mv"
236    C_DEPEND_OPT="$ac_cv_c_depend_opt"
237    C_DEPEND_PREFIX="$ac_cv_c_depend_prefix"
238    C_DO_DEPENDS="$ac_cv_c_do_depends"
239else
240   # Determine the values
241# This is needed for Mac OSX 10.5
242rm -rf conftest.dSYM
243rm -f conftest*
244dnl
245dnl Some systems (/usr/ucb/cc on Solaris) do not generate a dependency for
246dnl an include that doesn't begin in column 1
247dnl
248cat >conftest.c <<EOF
249    #include "confdefs.h"
250    int f(void) { return 0; }
251EOF
252dnl -xM1 is Solaris C compiler (no /usr/include files)
253dnl -MM is gcc (no /usr/include files)
254dnl -MMD is gcc to .d
255dnl .u is xlC (AIX) output
256for copt in "-xM1" "-c -xM1" "-xM" "-c -xM" "-MM" "-M" "-c -M"; do
257    AC_MSG_CHECKING([whether $copt option generates dependencies])
258    rm -f conftest.o conftest.u conftest.d conftest.err conftest.out
259    dnl also need to check that error output is empty
260    if $CC $CFLAGS $copt conftest.c >conftest.out 2>conftest.err && \
261        test ! -s conftest.err ; then
262        dnl Check for dependency info in conftest.out
263        if test -s conftest.u ; then
264            C_DEPEND_OUT=""
265            C_DEPEND_MV='mv $[*].u ${C_DEPEND_DIR}/$[*].dep'
266            pac_dep_file=conftest.u
267        elif test -s conftest.d ; then
268            C_DEPEND_OUT=""
269            C_DEPEND_MV='mv $[*].d ${C_DEPEND_DIR}/$[*].dep'
270            pac_dep_file=conftest.d
271        else
272            dnl C_DEPEND_OUT='>${C_DEPEND_DIR}/$[*].dep'
273            dnl This for is needed for VPATH.  Perhaps the others should match.
274            C_DEPEND_OUT='>$@'
275            C_DEPEND_MV=:
276            pac_dep_file=conftest.out
277        fi
278        if grep 'confdefs.h' $pac_dep_file >/dev/null 2>&1 ; then
279            AC_MSG_RESULT(yes)
280            C_DEPEND_OPT="$copt"
281            AC_MSG_CHECKING([whether .o file created with dependency file])
282            if test -s conftest.o ; then
283                AC_MSG_RESULT(yes)
284            else
285                AC_MSG_RESULT(no)
286                echo "Output of $copt option was" >&AC_FD_CC
287                cat $pac_dep_file >&AC_FD_CC
288            fi
289            break
290        else
291            AC_MSG_RESULT(no)
292        fi
293    else
294        echo "Error in compiling program with flags $copt" >&AC_FD_CC
295        cat conftest.out >&AC_FD_CC
296        if test -s conftest.err ; then cat conftest.err >&AC_FD_CC ; fi
297        AC_MSG_RESULT(no)
298    fi
299    copt=""
300done
301    if test -f $CONFIG_AUX_DIR/dependsrule -o \
302            -f $CONFIG_AUX_DIR/dependsrule.in; then
303        C_DO_DEPENDS="$CONFIG_AUX_DIR/dependsrule"
304    else
305        C_DO_DEPENDS="/dev/null"
306    fi
307    if test "X$copt" = "X" ; then
308        C_DEPEND_PREFIX="true"
309    else
310        C_DEPEND_PREFIX=""
311    fi
312    ac_cv_c_depend_out="$C_DEPEND_OUT"
313    ac_cv_c_depend_mv="$C_DEPEND_MV"
314    ac_cv_c_depend_opt="$C_DEPEND_OPT"
315    ac_cv_c_depend_prefix="$C_DEPEND_PREFIX"
316    ac_cv_c_do_depends="$C_DO_DEPENDS"
317fi
318])
319dnl
320dnl/*D
321dnl PAC_C_PROTOTYPES - Check that the compiler accepts ANSI prototypes. 
322dnl
323dnl Synopsis:
324dnl PAC_C_PROTOTYPES([action if true],[action if false])
325dnl
326dnl D*/
327AC_DEFUN([PAC_C_PROTOTYPES],[
328AC_CACHE_CHECK([whether $CC supports function prototypes],
329pac_cv_c_prototypes,[
330AC_TRY_COMPILE([int f(double a){return 0;}],[return 0];,
331pac_cv_c_prototypes="yes",pac_cv_c_prototypes="no")])
332if test "$pac_cv_c_prototypes" = "yes" ; then
333    ifelse([$1],,:,[$1])
334else
335    ifelse([$2],,:,[$2])
336fi
337])dnl
338dnl
339dnl/*D
340dnl PAC_FUNC_SEMCTL - Check for semctl and its argument types
341dnl
342dnl Synopsis:
343dnl PAC_FUNC_SEMCTL
344dnl
345dnl Output Effects:
346dnl Sets 'HAVE_SEMCTL' if semctl is available.
347dnl Sets 'HAVE_UNION_SEMUN' if 'union semun' is available.
348dnl Sets 'SEMCTL_NEEDS_SEMUN' if a 'union semun' type must be passed as the
349dnl fourth argument to 'semctl'.
350dnl D*/
351dnl Check for semctl and arguments
352AC_DEFUN([PAC_FUNC_SEMCTL],[
353AC_CHECK_FUNC(semctl)
354if test "$ac_cv_func_semctl" = "yes" ; then
355    AC_CACHE_CHECK([for union semun],
356    pac_cv_type_union_semun,[
357    AC_TRY_COMPILE([#include <sys/types.h>
358#include <sys/ipc.h>
359#include <sys/sem.h>],[union semun arg;arg.val=0;],
360    pac_cv_type_union_semun="yes",pac_cv_type_union_semun="no")])
361    if test "$pac_cv_type_union_semun" = "yes" ; then
362        AC_DEFINE(HAVE_UNION_SEMUN,1,[Has union semun])
363        #
364        # See if we can use an int in semctl or if we need the union
365        AC_CACHE_CHECK([whether semctl needs union semun],
366        pac_cv_func_semctl_needs_semun,[
367        AC_TRY_COMPILE([#include <sys/types.h>
368#include <sys/ipc.h>
369#include <sys/sem.h>],[
370int arg = 0; semctl( 1, 1, SETVAL, arg );],
371        pac_cv_func_semctl_needs_semun="yes",
372        pac_cv_func_semctl_needs_semun="no")
373        ])
374        if test "$pac_cv_func_semctl_needs_semun" = "yes" ; then
375            AC_DEFINE(SEMCTL_NEEDS_SEMUN,1,[Needs an explicit definition of semun])
376        fi
377    fi
378fi
379])
380dnl
381dnl/*D
382dnl PAC_C_VOLATILE - Check if C supports volatile
383dnl
384dnl Synopsis:
385dnl PAC_C_VOLATILE
386dnl
387dnl Output Effect:
388dnl Defines 'volatile' as empty if volatile is not available.
389dnl
390dnl D*/
391AC_DEFUN([PAC_C_VOLATILE],[
392AC_CACHE_CHECK([for volatile],
393pac_cv_c_volatile,[
394AC_TRY_COMPILE(,[volatile int a;],pac_cv_c_volatile="yes",
395pac_cv_c_volatile="no")])
396if test "$pac_cv_c_volatile" = "no" ; then
397    AC_DEFINE(volatile,,[if C does not support volatile])
398fi
399])dnl
400dnl
401dnl/*D
402dnl PAC_C_INLINE - Check if C supports inline
403dnl
404dnl Synopsis:
405dnl PAC_C_INLINE
406dnl
407dnl Output Effect:
408dnl Defines 'inline' as empty if inline is not available.
409dnl
410dnl D*/
411AC_DEFUN([PAC_C_INLINE],[
412AC_CACHE_CHECK([for inline],
413pac_cv_c_inline,[
414AC_TRY_COMPILE([inline int a( int b ){return b+1;}],[int a;],
415pac_cv_c_inline="yes",pac_cv_c_inline="no")])
416if test "$pac_cv_c_inline" = "no" ; then
417    AC_DEFINE(inline,,[if C does not support inline])
418fi
419])dnl
420dnl
421dnl/*D
422dnl PAC_C_CONST - Check if C supports const
423dnl
424dnl Synopsis:
425dnl PAC_C_CONST
426dnl
427dnl Output Effect:
428dnl AC_MSG_ERROR if const is not supported.
429dnl
430dnl D*/
431dnl AC_DEFUN(PAC_C_CONST,[
432dnl AC_CACHE_CHECK([for support of const in C],
433dnl pac_cv_c_const,[
434dnl AC_LANG_PUSH(C)
435dnl AC_TRY_COMPILE(,[const int a = 1; int b; b = a;],
436dnl pac_cv_c_const="yes", pac_cv_c_const="no")])
437dnl if test "$pac_cv_c_const" = "no" ; then
438dnl     AC_MSG_ERROR([C does not support const! Abort...])
439dnl fi
440dnl AC_LANG_POP(C)
441dnl ])dnl
442AC_DEFUN([PAC_C_CONST],
443[AC_CACHE_CHECK([for an ANSI C-conforming const], pac_cv_c_const,
444[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
445[[/* FIXME: Include the comments suggested by Paul. */
446#ifndef __cplusplus
447  /* Ultrix mips cc rejects this.  */
448  typedef int charset[2];
449  const charset cs = {0,0};
450  /* SunOS 4.1.1 cc rejects this.  */
451  char const *const *pcpcc;
452  char **ppc;
453  /* NEC SVR4.0.2 mips cc rejects this.  */
454  struct point {int x, y;};
455  static struct point const zero = {0,0};
456  /* AIX XL C 1.02.0.0 rejects this.
457     It does not let you subtract one const X* pointer from another in
458     an arm of an if-expression whose if-part is not a constant
459     expression */
460  const char *g = "string";
461  pcpcc = &g + (g ? g-g : 0);
462  /* HPUX 7.0 cc rejects these. */
463  ++pcpcc;
464  ppc = (char**) pcpcc;
465  pcpcc = (char const *const *) ppc;
466  { /* SCO 3.2v4 cc rejects this.  */
467    char const *s = 0 ? (char *) 0 : (char const *) 0;
468    if (s) return 0;
469  }
470  { /* Someone thinks the Sun supposedly-ANSI compiler will reject this.  */
471    int x[] = {25, 17};
472    const int *foo = &x[0];
473    ++foo;
474  }
475  { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
476    typedef const int *iptr;
477    iptr p = 0;
478    ++p;
479  }
480  { /* AIX XL C 1.02.0.0 rejects this saying
481       "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
482    struct s { int j; const int *ap[3]; };
483    struct s a;
484    struct s *b = &a;
485    b->j = 5;
486  }
487  { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
488    const int foo = 10;
489    if (!foo) return 0;
490  }
491  return !cs[0] && !zero.x;
492#endif
493]])],
494                   [pac_cv_c_const=yes],
495                   [pac_cv_c_const=no])])
496if test $pac_cv_c_const = no; then
497  AC_DEFINE(const,,
498            [Define to empty if `const' does not conform to ANSI C.])
499fi
500])dnl
501dnl
502dnl/*D
503dnl PAC_C_CPP_CONCAT - Check whether the C compiler accepts ISO CPP string
504dnl   concatenation
505dnl
506dnl Synopsis:
507dnl PAC_C_CPP_CONCAT([true-action],[false-action])
508dnl
509dnl Output Effects:
510dnl Invokes the true or false action
511dnl
512dnl D*/
513AC_DEFUN([PAC_C_CPP_CONCAT],[
514pac_pound="#"
515AC_CACHE_CHECK([whether the compiler $CC accepts $ac_pound$ac_pound for concatenation in cpp],
516pac_cv_c_cpp_concat,[
517AC_TRY_COMPILE([
518#define concat(a,b) a##b],[int concat(a,b);return ab;],
519pac_cv_cpp_concat="yes",pac_cv_cpp_concat="no")])
520if test $pac_cv_c_cpp_concat = "yes" ; then
521    ifelse([$1],,:,[$1])
522else
523    ifelse([$2],,:,[$2])
524fi
525])dnl
526dnl
527dnl/*D
528dnl PAC_FUNC_GETTIMEOFDAY - Check whether gettimeofday takes 1 or 2 arguments
529dnl
530dnl Synopsis
531dnl  PAC_IS_GETTIMEOFDAY_OK(ok_action,failure_action)
532dnl
533dnl Notes:
534dnl One version of Solaris accepted only one argument.
535dnl
536dnl D*/
537AC_DEFUN([PAC_FUNC_GETTIMEOFDAY],[
538AC_CACHE_CHECK([whether gettimeofday takes 2 arguments],
539pac_cv_func_gettimeofday,[
540AC_TRY_COMPILE([#include <sys/time.h>],[struct timeval tp;
541gettimeofday(&tp,(void*)0);return 0;],pac_cv_func_gettimeofday="yes",
542pac_cv_func_gettimeofday="no")
543])
544if test "$pac_cv_func_gettimeofday" = "yes" ; then
545     ifelse($1,,:,$1)
546else
547     ifelse($2,,:,$2)
548fi
549])
550dnl
551dnl/*D
552dnl PAC_C_RESTRICT - Check if C supports restrict
553dnl
554dnl Synopsis:
555dnl PAC_C_RESTRICT
556dnl
557dnl Output Effect:
558dnl Defines 'restrict' if some version of restrict is supported; otherwise
559dnl defines 'restrict' as empty.  This allows you to include 'restrict' in
560dnl declarations in the same way that 'AC_C_CONST' allows you to use 'const'
561dnl in declarations even when the C compiler does not support 'const'
562dnl
563dnl Note that some compilers accept restrict only with additional options.
564dnl DEC/Compaq/HP Alpha Unix (Tru64 etc.) -accept restrict_keyword
565dnl
566dnl D*/
567AC_DEFUN([PAC_C_RESTRICT],[
568AC_CACHE_CHECK([for restrict],
569pac_cv_c_restrict,[
570AC_TRY_COMPILE(,[int * restrict a;],pac_cv_c_restrict="restrict",
571pac_cv_c_restrict="no")
572if test "$pac_cv_c_restrict" = "no" ; then
573   AC_TRY_COMPILE(,[int * _Restrict a;],pac_cv_c_restrict="_Restrict",
574   pac_cv_c_restrict="no")
575fi
576if test "$pac_cv_c_restrict" = "no" ; then
577   AC_TRY_COMPILE(,[int * __restrict a;],pac_cv_c_restrict="__restrict",
578   pac_cv_c_restrict="no")
579fi
580])
581if test "$pac_cv_c_restrict" = "no" ; then
582  restrict_val=""
583elif test "$pac_cv_c_restrict" != "restrict" ; then
584  restrict_val=$pac_cv_c_restrict
585fi
586if test "$restrict_val" != "restrict" ; then
587  AC_DEFINE_UNQUOTED(restrict,$restrict_val,[if C does not support restrict])
588fi
589])dnl
590dnl
591dnl/*D
592dnl PAC_HEADER_STDARG - Check whether standard args are defined and whether
593dnl they are old style or new style
594dnl
595dnl Synopsis:
596dnl PAC_HEADER_STDARG(action if works, action if oldstyle, action if fails)
597dnl
598dnl Output Effects:
599dnl Defines HAVE_STDARG_H if the header exists.
600dnl defines
601dnl
602dnl Notes:
603dnl It isn't enough to check for stdarg.  Even gcc doesn't get it right;
604dnl on some systems, the gcc version of stdio.h loads stdarg.h `with the wrong
605dnl options` (causing it to choose the `old style` 'va_start' etc).
606dnl
607dnl The original test tried the two-arg version first; the old-style
608dnl va_start took only a single arg.
609dnl This turns out to be VERY tricky, because some compilers (e.g., Solaris)
610dnl are quite happy to accept the *wrong* number of arguments to a macro!
611dnl Instead, we try to find a clean compile version, using our special
612dnl PAC_C_TRY_COMPILE_CLEAN command.
613dnl
614dnl D*/
615AC_DEFUN([PAC_HEADER_STDARG],[
616AC_CHECK_HEADER(stdarg.h)
617dnl Sets ac_cv_header_stdarg_h
618if test "$ac_cv_header_stdarg_h" = "yes" ; then
619    dnl results are yes,oldstyle,no.
620    AC_CACHE_CHECK([whether stdarg is oldstyle],
621    pac_cv_header_stdarg_oldstyle,[
622PAC_C_TRY_COMPILE_CLEAN([#include <stdio.h>
623#include <stdarg.h>],
624[int func( int a, ... ){
625int b;
626va_list ap;
627va_start( ap );
628b = va_arg(ap, int);
629printf( "%d-%d\n", a, b );
630va_end(ap);
631fflush(stdout);
632return 0;
633}
634int main() { func( 1, 2 ); return 0;}],pac_check_compile)
635case "$pac_check_compile" in
636    0)  pac_cv_header_stdarg_oldstyle="yes"
637        ;;
638    1)  pac_cv_header_stdarg_oldstyle="may be newstyle"
639        ;;
640    2)  pac_cv_header_stdarg_oldstyle="no"   # compile failed
641        ;;
642esac
643])
644if test "$pac_cv_header_stdarg_oldstyle" = "yes" ; then
645    ifelse($2,,:,[$2])
646else
647    AC_CACHE_CHECK([whether stdarg works],
648    pac_cv_header_stdarg_works,[
649    PAC_C_TRY_COMPILE_CLEAN([
650#include <stdio.h>
651#include <stdarg.h>],[
652int func( int a, ... ){
653int b;
654va_list ap;
655va_start( ap, a );
656b = va_arg(ap, int);
657printf( "%d-%d\n", a, b );
658va_end(ap);
659fflush(stdout);
660return 0;
661}
662int main() { func( 1, 2 ); return 0;}],pac_check_compile)
663case "$pac_check_compile" in
664    0)  pac_cv_header_stdarg_works="yes"
665        ;;
666    1)  pac_cv_header_stdarg_works="yes with warnings"
667        ;;
668    2)  pac_cv_header_stdarg_works="no"
669        ;;
670esac
671])
672fi   # test on oldstyle
673if test "$pac_cv_header_stdarg_works" = "no" ; then
674    ifelse($3,,:,[$3])
675else
676    ifelse($1,,:,[$1])
677fi
678else
679    ifelse($3,,:,[$3])
680fi  # test on header
681])
682dnl/*D
683dnl PAC_C_TRY_COMPILE_CLEAN - Try to compile a program, separating success
684dnl with no warnings from success with warnings.
685dnl
686dnl Synopsis:
687dnl PAC_C_TRY_COMPILE_CLEAN(header,program,flagvar)
688dnl
689dnl Output Effect:
690dnl The 'flagvar' is set to 0 (clean), 1 (dirty but success ok), or 2
691dnl (failed).
692dnl
693dnl D*/
694AC_DEFUN([PAC_C_TRY_COMPILE_CLEAN],[
695$3=2
696dnl Get the compiler output to test against
697if test -z "$pac_TRY_COMPLILE_CLEAN" ; then
698    # This is needed for Mac OSX 10.5
699    rm -rf conftest.dSYM
700    rm -f conftest*
701    echo 'int try(void);int try(void){return 0;}' > conftest.c
702    if ${CC-cc} $CFLAGS -c conftest.c >conftest.bas 2>&1 ; then
703        if test -s conftest.bas ; then
704            pac_TRY_COMPILE_CLEAN_OUT=`cat conftest.bas`
705        fi
706        pac_TRY_COMPILE_CLEAN=1
707    else
708        AC_MSG_WARN([Could not compile simple test program!])
709        if test -s conftest.bas ; then  cat conftest.bas >> config.log ; fi
710    fi
711fi
712dnl
713dnl Create the program that we need to test with
714# This is needed for Mac OSX 10.5
715rm -rf conftest.dSYM
716rm -f conftest*
717cat >conftest.c <<EOF
718#include "confdefs.h"
719[$1]
720[$2]
721EOF
722dnl
723dnl Compile it and test
724if ${CC-cc} $CFLAGS -c conftest.c >conftest.bas 2>&1 ; then
725    dnl Success.  Is the output the same?
726    if test "$pac_TRY_COMPILE_CLEAN_OUT" = "`cat conftest.bas`" ; then
727        $3=0
728    else
729        cat conftest.c >>config.log
730        if test -s conftest.bas ; then  cat conftest.bas >> config.log ; fi
731        $3=1
732    fi
733else
734    dnl Failure.  Set flag to 2
735    cat conftest.c >>config.log
736    if test -s conftest.bas ; then cat conftest.bas >> config.log ; fi
737    $3=2
738fi
739# This is needed for Mac OSX 10.5
740rm -rf conftest.dSYM
741rm -f conftest*
742])
743dnl
744dnl/*D
745dnl PAC_PROG_C_UNALIGNED_DOUBLES - Check that the C compiler allows unaligned
746dnl doubles
747dnl
748dnl Synopsis:
749dnl   PAC_PROG_C_UNALIGNED_DOUBLES(action-if-true,action-if-false,
750dnl       action-if-unknown)
751dnl
752dnl Notes:
753dnl 'action-if-unknown' is used in the case of cross-compilation.
754dnl D*/
755AC_DEFUN([PAC_PROG_C_UNALIGNED_DOUBLES],[
756AC_CACHE_CHECK([whether C compiler allows unaligned doubles],
757pac_cv_prog_c_unaligned_doubles,[
758AC_TRY_RUN([
759void fetch_double( v )
760double *v;
761{
762*v = 1.0;
763}
764int main( argc, argv )
765int argc;
766char **argv;
767{
768int p[4];
769double *p_val;
770fetch_double( (double *)&(p[0]) );
771p_val = (double *)&(p[0]);
772if (*p_val != 1.0) return 1;
773fetch_double( (double *)&(p[1]) );
774p_val = (double *)&(p[1]);
775if (*p_val != 1.0) return 1;
776return 0;
777}
778],pac_cv_prog_c_unaligned_doubles="yes",pac_cv_prog_c_unaligned_doubles="no",
779pac_cv_prog_c_unaligned_doubles="unknown")])
780ifelse($1,,,if test "X$pac_cv_prog_c_unaligned_doubles" = "yes" ; then
781$1
782fi)
783ifelse($2,,,if test "X$pac_cv_prog_c_unaligned_doubles" = "no" ; then
784$2
785fi)
786ifelse($3,,,if test "X$pac_cv_prog_c_unaligned_doubles" = "unknown" ; then
787$3
788fi)
789])
790dnl
791dnl/*D
792dnl PAC_PROG_C_WEAK_SYMBOLS - Test whether C supports weak alias symbols.
793dnl
794dnl Synopsis
795dnl PAC_PROG_C_WEAK_SYMBOLS(action-if-true,action-if-false)
796dnl
797dnl Output Effect:
798dnl Defines one of the following if a weak symbol pragma is found:
799dnl.vb
800dnl    HAVE_PRAGMA_WEAK - #pragma weak
801dnl    HAVE_PRAGMA_HP_SEC_DEF - #pragma _HP_SECONDARY_DEF
802dnl    HAVE_PRAGMA_CRI_DUP  - #pragma _CRI duplicate x as y
803dnl.ve
804dnl May also define
805dnl.vb
806dnl    HAVE_WEAK_ATTRIBUTE
807dnl.ve
808dnl if functions can be declared as 'int foo(...) __attribute__ ((weak));'
809dnl sets the shell variable pac_cv_attr_weak to yes.
810dnl Also checks for __attribute__((weak_import)) which is supported by
811dnl Apple in Mac OSX (at least in Darwin).  Note that this provides only
812dnl weak symbols, not weak aliases
813dnl
814dnl D*/
815AC_DEFUN([PAC_PROG_C_WEAK_SYMBOLS],[
816pragma_extra_message=""
817AC_CACHE_CHECK([for type of weak symbol alias support],
818pac_cv_prog_c_weak_symbols,[
819# Test for weak symbol support...
820# We can't put # in the message because it causes autoconf to generate
821# incorrect code
822AC_TRY_LINK([
823extern int PFoo(int);
824#pragma weak PFoo = Foo
825int Foo(int a) { return a; }
826],[return PFoo(1);],has_pragma_weak=yes)
827#
828# Some systems (Linux ia64 and ecc, for example), support weak symbols
829# only within a single object file!  This tests that case.
830# Note that there is an extern int PFoo declaration before the
831# pragma.  Some compilers require this in order to make the weak symbol
832# extenally visible. 
833if test "$has_pragma_weak" = yes ; then
834    # This is needed for Mac OSX 10.5
835    rm -rf conftest.dSYM
836    rm -f conftest*
837    cat >>conftest1.c <<EOF
838extern int PFoo(int);
839#pragma weak PFoo = Foo
840int Foo(int);
841int Foo(int a) { return a; }
842EOF
843    cat >>conftest2.c <<EOF
844extern int PFoo(int);
845int main(int argc, char **argv) {
846return PFoo(0);}
847EOF
848    ac_link2='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest1.c conftest2.c $LIBS >conftest.out 2>&1'
849    if eval $ac_link2 ; then
850        # The gcc 3.4.x compiler accepts the pragma weak, but does not
851        # correctly implement it on systems where the loader doesn't
852        # support weak symbols (e.g., cygwin).  This is a bug in gcc, but it
853        # it is one that *we* have to detect.
854        # This is needed for Mac OSX 10.5
855        rm -rf conftest.dSYM
856        rm -f conftest*
857        cat >>conftest1.c <<EOF
858extern int PFoo(int);
859#pragma weak PFoo = Foo
860int Foo(int);
861int Foo(int a) { return a; }
862EOF
863    cat >>conftest2.c <<EOF
864extern int Foo(int);
865int PFoo(int a) { return a+1;}
866int main(int argc, char **argv) {
867return Foo(0);}
868EOF
869        if eval $ac_link2 ; then
870            pac_cv_prog_c_weak_symbols="pragma weak"
871        else
872            echo "$ac_link2" >> config.log
873            echo "Failed program was" >> config.log
874            cat conftest1.c >>config.log
875            cat conftest2.c >>config.log
876            if test -s conftest.out ; then cat conftest.out >> config.log ; fi
877            has_pragma_weak=0
878            pragma_extra_message="pragma weak accepted but does not work (probably creates two non-weak entries)"
879        fi
880    else
881      echo "$ac_link2" >>config.log
882      echo "Failed program was" >>config.log
883      cat conftest1.c >>config.log
884      cat conftest2.c >>config.log
885      if test -s conftest.out ; then cat conftest.out >> config.log ; fi
886      has_pragma_weak=0
887      pragma_extra_message="pragma weak does not work outside of a file"
888    fi
889    # This is needed for Mac OSX 10.5
890    rm -rf conftest.dSYM
891    rm -f conftest*
892fi
893dnl
894if test -z "$pac_cv_prog_c_weak_symbols" ; then
895    AC_TRY_LINK([
896extern int PFoo(int);
897#pragma _HP_SECONDARY_DEF Foo  PFoo
898int Foo(int a) { return a; }
899],[return PFoo(1);],pac_cv_prog_c_weak_symbols="pragma _HP_SECONDARY_DEF")
900fi
901dnl
902if test -z "$pac_cv_prog_c_weak_symbols" ; then
903    AC_TRY_LINK([
904extern int PFoo(int);
905#pragma _CRI duplicate PFoo as Foo
906int Foo(int a) { return a; }
907],[return PFoo(1);],pac_cv_prog_c_weak_symbols="pragma _CRI duplicate x as y")
908fi
909dnl
910if test -z "$pac_cv_prog_c_weak_symbols" ; then
911    pac_cv_prog_c_weak_symbols="no"
912fi
913dnl
914dnl If there is an extra explanatory message, echo it now so that it
915dnl doesn't interfere with the cache result value
916if test -n "$pragma_extra_message" ; then
917    echo $pragma_extra_message
918fi
919dnl
920])
921if test "$pac_cv_prog_c_weak_symbols" = "no" ; then
922    ifelse([$2],,:,[$2])
923else
924    case "$pac_cv_prog_c_weak_symbols" in
925        "pragma weak") AC_DEFINE(HAVE_PRAGMA_WEAK,1,[Supports weak pragma])
926        ;;
927        "pragma _HP")  AC_DEFINE(HAVE_PRAGMA_HP_SEC_DEF,1,[HP style weak pragma])
928        ;;
929        "pragma _CRI") AC_DEFINE(HAVE_PRAGMA_CRI_DUP,1,[Cray style weak pragma])
930        ;;
931    esac
932    ifelse([$1],,:,[$1])
933fi
934AC_CACHE_CHECK([whether __attribute__ ((weak)) allowed],
935pac_cv_attr_weak,[
936AC_TRY_COMPILE([int foo(int) __attribute__ ((weak));],[int a;],
937pac_cv_attr_weak=yes,pac_cv_attr_weak=no)])
938# Note that being able to compile with weak_import doesn't mean that
939# it works.
940AC_CACHE_CHECK([whether __attribute ((weak_import)) allowed],
941pac_cv_attr_weak_import,[
942AC_TRY_COMPILE([int foo(int) __attribute__ ((weak_import));],[int a;],
943pac_cv_attr_weak_import=yes,pac_cv_attr_weak_import=no)])
944])
945
946#
947# This is a replacement that checks that FAILURES are signaled as well
948# (later configure macros look for the .o file, not just success from the
949# compiler, but they should not HAVE to
950#
951dnl --- insert 2.52 compatibility here ---
952dnl 2.52 does not have AC_PROG_CC_WORKS
953ifdef([AC_PROG_CC_WORKS],,[AC_DEFUN([AC_PROG_CC_WORKS],)])
954dnl
955AC_DEFUN([PAC_PROG_CC_WORKS],
956[AC_PROG_CC_WORKS
957AC_MSG_CHECKING([whether the C compiler sets its return status correctly])
958AC_LANG_SAVE
959AC_LANG_C
960AC_TRY_COMPILE(,[int a = bzzzt;],notbroken=no,notbroken=yes)
961AC_MSG_RESULT($notbroken)
962if test "$notbroken" = "no" ; then
963    AC_MSG_ERROR([installation or configuration problem: C compiler does not
964correctly set error code when a fatal error occurs])
965fi
966])
967dnl
968dnl/*D
969dnl PAC_PROG_C_MULTIPLE_WEAK_SYMBOLS - Test whether C and the
970dnl linker allow multiple weak symbols.
971dnl
972dnl Synopsis
973dnl PAC_PROG_C_MULTIPLE_WEAK_SYMBOLS(action-if-true,action-if-false)
974dnl
975dnl
976dnl D*/
977AC_DEFUN([PAC_PROG_C_MULTIPLE_WEAK_SYMBOLS],[
978AC_CACHE_CHECK([for multiple weak symbol support],
979pac_cv_prog_c_multiple_weak_symbols,[
980# Test for multiple weak symbol support...
981#
982# This is needed for Mac OSX 10.5
983rm -rf conftest.dSYM
984rm -f conftest*
985cat >>conftest1.c <<EOF
986extern int PFoo(int);
987extern int PFoo_(int);
988extern int pfoo_(int);
989#pragma weak PFoo = Foo
990#pragma weak PFoo_ = Foo
991#pragma weak pfoo_ = Foo
992int Foo(int);
993int Foo(a) { return a; }
994EOF
995cat >>conftest2.c <<EOF
996extern int PFoo(int), PFoo_(int), pfoo_(int);
997int main() {
998return PFoo(0) + PFoo_(1) + pfoo_(2);}
999EOF
1000ac_link2='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest1.c conftest2.c $LIBS >conftest.out 2>&1'
1001if eval $ac_link2 ; then
1002    pac_cv_prog_c_multiple_weak_symbols="yes"
1003else
1004    echo "$ac_link2" >>config.log
1005    echo "Failed program was" >>config.log
1006    cat conftest1.c >>config.log
1007    cat conftest2.c >>config.log
1008    if test -s conftest.out ; then cat conftest.out >> config.log ; fi
1009fi
1010# This is needed for Mac OSX 10.5
1011rm -rf conftest.dSYM
1012rm -f conftest*
1013dnl
1014])
1015if test "$pac_cv_prog_c_multiple_weak_symbols" = "yes" ; then
1016    ifelse([$1],,:,[$1])
1017else
1018    ifelse([$2],,:,[$2])
1019fi
1020])
1021dnl
1022dnl/*D
1023dnl PAC_FUNC_CRYPT - Check that the function crypt is defined
1024dnl
1025dnl Synopsis:
1026dnl PAC_FUNC_CRYPT
1027dnl
1028dnl Output Effects:
1029dnl
1030dnl In Solaris, the crypt function is not defined in unistd unless
1031dnl _XOPEN_SOURCE is defines and _XOPEN_VERSION is 4 or greater.
1032dnl We test by looking for a missing crypt by defining our own
1033dnl incompatible one and trying to compile it.
1034dnl Defines NEED_CRYPT_PROTOTYPE if no prototype is found.
1035dnl D*/
1036AC_DEFUN([PAC_FUNC_CRYPT],[
1037AC_CACHE_CHECK([whether crypt defined in unistd.h],
1038pac_cv_func_crypt_defined,[
1039AC_TRY_COMPILE([
1040#include <unistd.h>
1041double crypt(double a){return a;}],[return 0];,
1042pac_cv_func_crypt_defined="no",pac_cv_func_crypt_defined="yes")])
1043if test "$pac_cv_func_crypt_defined" = "no" ; then
1044    # check to see if defining _XOPEN_SOURCE helps
1045    AC_CACHE_CHECK([whether crypt defined in unistd with _XOPEN_SOURCE],
1046pac_cv_func_crypt_xopen,[
1047    AC_TRY_COMPILE([
1048#define _XOPEN_SOURCE   
1049#include <unistd.h>
1050double crypt(double a){return a;}],[return 0];,
1051pac_cv_func_crypt_xopen="no",pac_cv_func_crypt_xopen="yes")])
1052fi
1053if test "$pac_cv_func_crypt_xopen" = "yes" ; then
1054    AC_DEFINE(_XOPEN_SOURCE,1,[if xopen needed for crypt])
1055elif test "$pac_cv_func_crypt_defined" = "no" ; then
1056    AC_DEFINE(NEED_CRYPT_PROTOTYPE,1,[if a prototype for crypt is needed])
1057fi
1058])dnl
1059
1060dnl
1061dnl Use the value of enable-strict to update CFLAGS
1062dnl pac_cc_strict_flags contains the strict flags.
1063dnl
1064dnl -std=c89 is used to select the C89 version of the ANSI/ISO C standard.
1065dnl As of this writing, many C compilers still accepted only this version,
1066dnl not the later C99 version.  When all compilers accept C99, this
1067dnl should be changed to the appropriate standard level.  Note that we've
1068dnl had trouble with gcc 2.95.3 accepting -std=c89 but then trying to
1069dnl compile program with a invalid set of options
1070dnl (-D __STRICT_ANSI__-trigraphs)
1071dnl
1072dnl
1073AC_DEFUN([PAC_CC_STRICT],[
1074export enable_strict_done
1075if test "$enable_strict_done" != "yes" ; then
1076    # We must know the compiler type
1077    if test -z "$GCC_OPTFLAG" ; then GCC_OPTFLAG="-O2" ; fi
1078    if test -z "CC" ; then
1079        AC_CHECK_PROGS(CC,gcc)
1080    fi
1081    pac_cc_strict_flags=""
1082    case "$1" in
1083        yes)
1084        enable_strict_done="yes"
1085        if test "$ac_cv_prog_gcc" = "yes" ; then
1086            pac_cc_strict_flags="-Wall $GCC_OPTFLAG -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wpointer-arith -Wbad-function-cast -ansi -DGCC_WALL"
1087            CFLAGS="$CFLAGS $pac_cc_strict_flags"
1088            AC_MSG_RESULT([Adding strict check arguments to CFLAGS])
1089            AC_MSG_CHECKING([whether we can add -std=c89])
1090            # See if we can add -std=c89
1091            savCFLAGS=$CFLAGS
1092            CFLAGS="$CFLAGS -std=c89"
1093            AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[int a;])],
1094                  stdc_ok=yes,
1095                  stdc_ok=no)
1096            AC_MSG_RESULT($stdc_ok)
1097            if test "$stdc_ok" != yes ; then
1098                CFLAGS="$savCFLAGS"
1099            else
1100                pac_cc_strict_flags="$pac_cc_strict_flags -std=c89"
1101            fi
1102        else
1103            AC_MSG_WARN([enable strict supported only for gcc])
1104        fi
1105        ;;
1106
1107        all)
1108        enable_strict_done="yes"
1109        if test "$ac_cv_prog_gcc" = "yes" ; then
1110            # -Wsystem-headers removed because of too many warning messages
1111            # that are unfixable by the user of this option (the warnings
1112            # often show benign but real problems)
1113            # -Wunreachable-code has a serious bug and falsely reports
1114            # labels as unreachable code.  This makes that option useless
1115            # for the MPICH2 code, for example
1116            # The next line was the original set of options; this
1117            # worked with gcc version 2.x
1118#            pac_cc_strict_flags="-Wall -Wextra $GCC_OPTFLAG -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wpointer-arith -Wbad-function-cast -ansi -DGCC_WALL -Wunused -Wshadow -Wmissing-declarations -Wunused-parameter -Wunused-value -Wno-long-long -Werror-implicit-function-declaration"
1119            pac_cc_strict_flags="-Wall -Wextra $GCC_OPTFLAG -Wstrict-prototypes -Wmissing-prototypes -DGCC_WALL -Wunused -Wshadow -Wmissing-declarations -Werror-implicit-function-declaration -Wno-long-long -Wunused-parameter -Wunused-value  -Wfloat-equal -Wdeclaration-after-statement -Wundef -Wno-endif-labels -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wsign-compare -Waggregate-return -Wold-style-definition -Wmissing-field-initializers -Wmissing-noreturn -Wmissing-format-attribute -Wno-multichar -Wno-deprecated-declarations -Wpacked -Wpadded -Wredundant-decls -Wnested-externs -Winline -Winvalid-pch -Wno-pointer-sign -Wvariadic-macros"
1120            CFLAGS="$CFLAGS $pac_cc_strict_flags"
1121            AC_MSG_CHECKING([whether we can add -std=c89])
1122            # See if we can add -std=c89
1123            savCFLAGS=$CFLAGS
1124            CFLAGS="$CFLAGS -std=c89"
1125            AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[int a;])],
1126                  stdc_ok=yes,
1127                  stdc_ok=no)
1128            AC_MSG_RESULT($stdc_ok)
1129            if test "$stdc_ok" != yes ; then
1130                CFLAGS="$savCFLAGS"
1131            else
1132                pac_cc_strict_flags="$pac_cc_strict_flags -std=c89"
1133            fi
1134        else
1135            AC_MSG_WARN([enable strict supported only for gcc])
1136        fi
1137        ;;
1138
1139        # The MPICH2 code has several modules that have duplicate
1140        # function declarations.  The resulting list of warnings is
1141        # swamped by those duplicates, rendering the output nearly
1142        # useless.  This temporary option choice is the same as
1143        # --enable-strict=all, but without that one option
1144        allbutdupdefs)
1145        enable_strict_done="yes"
1146        if test "$ac_cv_prog_gcc" = "yes" ; then
1147            # -Wsystem-headers removed because of too many warning messages
1148            # that are unfixable by the user of this option (the warnings
1149            # often show benign but real problems)
1150            # -Wunreachable-code has a serious bug and falsely reports
1151            # labels as unreachable code.  This makes that option useless
1152            # for the MPICH2 code, for example
1153            # This next line contains the options used with gcc version 2.x
1154#            pac_cc_strict_flags="-Wall -Wextra $GCC_OPTFLAG -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wpointer-arith -Wbad-function-cast -ansi -DGCC_WALL -Wunused -Wshadow -Wmissing-declarations -Wunused-parameter -Wunused-value -Wno-long-long -Werror-implicit-function-declaration"
1155            pac_cc_strict_flags="-Wall -Wextra $GCC_OPTFLAG -Wstrict-prototypes -Wmissing-prototypes -DGCC_WALL -Wunused -Wshadow -Wmissing-declarations -Werror-implicit-function-declaration -Wno-long-long -Wunused-parameter -Wunused-value  -Wfloat-equal -Wdeclaration-after-statement -Wundef -Wno-endif-labels -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wsign-compare -Waggregate-return -Wold-style-definition -Wmissing-field-initializers -Wmissing-noreturn -Wmissing-format-attribute -Wno-multichar -Wno-deprecated-declarations -Wpacked -Wpadded -Wnested-externs -Winline -Winvalid-pch -Wno-pointer-sign -Wvariadic-macros -std=c89"
1156            CFLAGS="$CFLAGS $pac_cc_strict_flags"
1157            AC_MSG_CHECKING([whether we can add -std=c89])
1158            # See if we can add -std=c89
1159            savCFLAGS=$CFLAGS
1160            CFLAGS="$CFLAGS -std=c89"
1161            AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[int a;])],
1162                  stdc_ok=yes,
1163                  stdc_ok=no)
1164            AC_MSG_RESULT($stdc_ok)
1165            if test "$stdc_ok" != yes ; then
1166                CFLAGS="$savCFLAGS"
1167            else
1168                pac_cc_strict_flags="$pac_cc_strict_flags -std=c89"
1169            fi
1170        else
1171            AC_MSG_WARN([enable strict supported only for gcc])
1172        fi
1173        ;;
1174
1175        posix)
1176        # fsync is a part of POSIX only in the real-time extensions,
1177        # apparently, so code that used include <unistd.h> and POSIX
1178        # and expects fsync to be defined is in trouble.  Because of that
1179        # we're not including the -W option to error if a function is
1180        # not prototyped.
1181        enable_strict_done="yes"
1182        if test "$ac_cv_prog_gcc" = "yes" ; then
1183            pac_cc_strict_flags="-Wall $GCC_OPTFLAG -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wpointer-arith -Wbad-function-cast -ansi -DGCC_WALL -D_POSIX_C_SOURCE=199506L"
1184            CFLAGS="$CFLAGS $pac_cc_strict_flags"
1185            AC_MSG_RESULT([Adding strict check arguments (POSIX flavor) to CFLAGS])
1186            AC_MSG_CHECKING([whether we can add -std=c89])
1187            # See if we can add -std=c89
1188            savCFLAGS=$CFLAGS
1189            CFLAGS="$CFLAGS -std=c89"
1190            AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[int a;])],
1191                  stdc_ok=yes,
1192                  stdc_ok=no)
1193            AC_MSG_RESULT($stdc_ok)
1194            if test "$stdc_ok" != yes ; then
1195                CFLAGS="$savCFLAGS"
1196            else
1197                pac_cc_strict_flags="$pac_cc_strict_flags -std=c89"
1198            fi
1199        else
1200            AC_MSG_WARN([enable strict supported only for gcc])
1201        fi
1202        ;;
1203       
1204        noopt)
1205        enable_strict_done="yes"
1206        if test "$ac_cv_prog_gcc" = "yes" ; then
1207            pac_cc_strict_flags="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wpointer-arith -Wbad-function-cast -ansi -DGCC_WALL"
1208            CFLAGS="$CFLAGS $pac_cc_strict_flags"
1209            AC_MSG_RESULT([Adding strict check arguments to CFLAGS])
1210            AC_MSG_CHECKING([whether we can add -std=c89])
1211            # See if we can add -std=c89
1212            savCFLAGS=$CFLAGS
1213            CFLAGS="$CFLAGS -std=c89"
1214            AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[int a;])],
1215                  stdc_ok=yes,
1216                  stdc_ok=no)
1217            AC_MSG_RESULT($stdc_ok)
1218            if test "$stdc_ok" != yes ; then
1219                CFLAGS="$savCFLAGS"
1220            else
1221                pac_cc_strict_flags="$pac_cc_strict_flags -std=c89"
1222            fi
1223        else
1224            AC_MSG_WARN([enable strict supported only for gcc])
1225        fi
1226        ;;
1227        no)
1228        # Accept and ignore this value
1229        :
1230        ;;
1231        *)
1232        if test -n "$1" ; then
1233            AC_MSG_WARN([Unrecognized value for enable-strict:$1])
1234        fi
1235        ;;
1236    esac
1237fi
1238])
1239
1240dnl/*D
1241dnl PAC_ARG_STRICT - Add --enable-strict to configure. 
1242dnl
1243dnl Synopsis:
1244dnl PAC_ARG_STRICT
1245dnl
1246dnl Output effects:
1247dnl Adds '--enable-strict' to the command line.  If this is enabled, then
1248dnl if no compiler has been set, set 'CC' to 'gcc'.
1249dnl If the compiler is 'gcc', 'COPTIONS' is set to include
1250dnl.vb
1251dnl     -O -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Werror=pointer-arith -DGCC_WALL -std=c89
1252dnl.ve
1253dnl This makes using a void * with pointer arithmetic an error, not a warning.
1254dnl We do this because pointer arithmetic with void * is not valid C but
1255dnl gcc accepts this unless these particular optiones are used.
1256dnl Grr. -Werror=name is a recent addition to gcc, so we can't require it yet.
1257dnl
1258dnl -std=c89 is used to select the C89 version of the ANSI/ISO C standard.
1259dnl As of this writing, many C compilers still accepted only this version,
1260dnl not the later C99 version.  When all compilers accept C99, this
1261dnl should be changed to the appropriate standard level.  Note that we've
1262dnl had trouble with gcc 2.95.3 accepting -std=c89 but then trying to
1263dnl compile program with a invalid set of options
1264dnl (-D __STRICT_ANSI__-trigraphs)
1265dnl
1266dnl If the value 'all' is given to '--enable-strict', additional warning
1267dnl options are included.  These are
1268dnl.vb
1269dnl -Wunused -Wshadow -Wmissing-declarations -Wno-long-long
1270dnl.ve
1271dnl
1272dnl If the value 'noopt' is given to '--enable-strict', no optimization
1273dnl options are set.  For some compilers (including gcc), this may
1274dnl cause some strict complication tests to be skipped (typically, these are
1275dnl tests for unused variables or variables used before they are defined).
1276dnl
1277dnl If the value 'posix' is given to '--enable-strict', POSIX is selected
1278dnl as the C dialect (including the definition for the POSIX level)
1279dnl
1280dnl If the value 'all' is given to '--enable-strict', use the "GNU" Unix
1281dnl dialect.  This permits the use of stricter checking for declarations of
1282dnl system functions (note that fsync is not defined in strict, non-real-time
1283dnl POSIX).  This level includes
1284dnl .vb
1285dnl -Werror-implicit-function-declaration
1286dnl .ve
1287dnl
1288dnl This only works where 'gcc' is available.
1289dnl In addition, it exports the variable 'enable_strict_done'. This
1290dnl ensures that subsidiary 'configure's do not add the above flags to
1291dnl 'COPTIONS' once the top level 'configure' sees '--enable-strict'.  To ensure
1292dnl this, 'COPTIONS' is also exported.
1293dnl
1294dnl Not yet available: options when using other compilers.  However,
1295dnl here are some possible choices
1296dnl Solaris cc
1297dnl  -fd -v -Xc
1298dnl -Xc is strict ANSI (some version) and does not allow "long long", for
1299dnl example
1300dnl IRIX
1301dnl  -ansi -DEBUG:trap_uninitialized=ON:varargs_interface_check=ON:verbose_runtime=ON
1302dnl
1303dnl D*/
1304AC_DEFUN([PAC_ARG_STRICT],[
1305AC_ARG_ENABLE(strict,
1306[--enable-strict  - Turn on strict compilation testing when using gcc])
1307PAC_CC_STRICT($enable_strict)
1308CFLAGS="$CFLAGS $pac_cc_strict_flags"
1309])
1310
1311dnl/*D
1312dnl PAC_ARG_CC_G - Add debugging flags for the C compiler
1313dnl
1314dnl Synopsis:
1315dnl PAC_ARG_CC_G
1316dnl
1317dnl Output Effect:
1318dnl Adds '-g' to 'COPTIONS' and exports 'COPTIONS'.  Sets and exports the
1319dnl variable 'enable_g_simple' so that subsidiary 'configure's will not
1320dnl add another '-g'.
1321dnl
1322dnl Notes:
1323dnl '--enable-g' should be used for all internal debugging modes if possible.
1324dnl Use the 'enable_val' that 'enable_g' is set to to pass particular values,
1325dnl and ignore any values that are not recognized (some other 'configure'
1326dnl may have used them.  Of course, if you need extra values, you must
1327dnl add code to extract values from 'enable_g'.
1328dnl
1329dnl For example, to look for a particular keyword, you could use
1330dnl.vb
1331dnl SaveIFS="$IFS"
1332dnl IFS=","
1333dnl for key in $enable_g ; do
1334dnl     case $key in
1335dnl         mem) # add code for memory debugging
1336dnl         ;;
1337dnl         *)   # ignore all other values
1338dnl         ;;
1339dnl     esac
1340dnl done
1341dnl IFS="$SaveIFS"
1342dnl.ve
1343dnl
1344dnl D*/
1345AC_DEFUN([PAC_ARG_CC_G],[
1346AC_ARG_ENABLE(g,
1347[--enable-g  - Turn on debugging of the package (typically adds -g to COPTIONS)])
1348export COPTIONS
1349export enable_g_simple
1350if test -n "$enable_g" -a "$enable_g" != "no" -a \
1351   "$enable_g_simple" != "done" ; then
1352    enable_g_simple="done"
1353    if test "$enable_g" = "g" -o "$enable_g" = "yes" ; then
1354        COPTIONS="$COPTIONS -g"
1355    fi
1356fi
1357])
1358dnl
1359dnl Simple version for both options
1360dnl
1361AC_DEFUN([PAC_ARG_CC_COMMON],[
1362PAC_ARG_CC_G
1363PAC_ARG_STRICT
1364])
1365dnl
1366dnl Eventually, this can be used instead of the funky Fortran stuff to
1367dnl access the command line from a C routine.
1368dnl #
1369dnl # Under IRIX (some version) __Argc and __Argv gave the argc,argv values
1370dnl #Under linux, __libc_argv and __libc_argc
1371dnl AC_MSG_CHECKING([for alternative argc,argv names])
1372dnl AC_TRY_LINK([
1373dnl extern int __Argc; extern char **__Argv;],[return __Argc;],
1374dnl alt_argv="__Argv")
1375dnl if test -z "$alt_argv" ; then
1376dnl    AC_TRY_LINK([
1377dnl extern int __libc_argc; extern char **__libc_argv;],[return __lib_argc;],
1378dnl alt_argv="__lib_argv")
1379dnl fi
1380dnl if test -z "$alt_argv" ; then
1381dnl   AC_MSG_RESULT(none found))
1382dnl else
1383dnl   AC_MSG_RESULT($alt_argv)
1384dnl fi
1385dnl
1386dnl
1387dnl Check whether we need -fno-common to correctly compile the source code.
1388dnl This is necessary if global variables are defined without values in
1389dnl gcc.  Here is the test
1390dnl conftest1.c:
1391dnl extern int a; int a;
1392dnl conftest2.c:
1393dnl extern int a; int main(int argc; char *argv[] ){ return a; }
1394dnl Make a library out of conftest1.c and try to link with it.
1395dnl If that fails, recompile it with -fno-common and see if that works.
1396dnl If so, add -fno-common to CFLAGS
1397dnl An alternative is to use, on some systems, ranlib -c to force
1398dnl the system to find common symbols.
1399dnl
1400AC_DEFUN([PAC_PROG_C_BROKEN_COMMON],[
1401AC_CACHE_CHECK([whether global variables handled properly],
1402ac_cv_prog_cc_globals_work,[
1403AC_REQUIRE([AC_PROG_RANLIB])
1404ac_cv_prog_cc_globals_work=no
1405rm -f libconftest.a
1406echo 'extern int a; int a;' > conftest1.c
1407echo 'extern int a; int main( ){ return a; }' > conftest2.c
1408if ${CC-cc} $CFLAGS -c conftest1.c >conftest.out 2>&1 ; then
1409    if ${AR-ar} cr libconftest.a conftest1.o >/dev/null 2>&1 ; then
1410        if ${RANLIB-:} libconftest.a >/dev/null 2>&1 ; then
1411            if ${CC-cc} $CFLAGS -o conftest conftest2.c $LDFLAGS libconftest.a >>conftest.out 2>&1 ; then
1412                # Success!  C works
1413                ac_cv_prog_cc_globals_work=yes
1414            else
1415                echo "Error linking program with uninitialized global" >&AC_FD_CC
1416                echo "Programs were:" >&AC_FD_CC
1417                echo "conftest1.c:" >&AC_FD_CC
1418                cat conftest1.c >&AC_FD_CC
1419                echo "conftest2.c:" >&AC_FD_CC
1420                cat conftest2.c >&AC_FD_CC
1421                echo "and link line was:" >&AC_FD_CC
1422                echo "${CC-cc} $CFLAGS -o conftest conftest2.c $LDFLAGS libconftest.a" >&AC_FD_CC
1423                echo "with output:" >&AC_FD_CC
1424                cat conftest.out >&AC_FD_CC
1425
1426                # Failure!  Do we need -fno-common?
1427                ${CC-cc} $CFLAGS -fno-common -c conftest1.c >> conftest.out 2>&1
1428                rm -f libconftest.a
1429                ${AR-ar} cr libconftest.a conftest1.o
1430                ${RANLIB-:} libconftest.a
1431                if ${CC-cc} $CFLAGS -o conftest conftest2.c $LDFLAGS libconftest.a >> conftest.out 2>&1 ; then
1432                    ac_cv_prog_cc_globals_work="needs -fno-common"
1433                    CFLAGS="$CFLAGS -fno-common"
1434                elif test -n "$RANLIB" ; then
1435                    # Try again, with ranlib changed to ranlib -c
1436                    # (send output to /dev/null incase this ranlib
1437                    # doesn't know -c)
1438                    ${RANLIB} -c libconftest.a >/dev/null 2>&1
1439                    if ${CC-cc} $CFLAGS -o conftest conftest2.c $LDFLAGS libconftest.a >> conftest.out 2>&1 ; then
1440                        RANLIB="$RANLIB -c"
1441                    #else
1442                    #   # That didn't work
1443                    #   :
1444                    fi
1445                #else
1446                #    :
1447                fi
1448            fi
1449        fi
1450    fi
1451fi
1452# This is needed for Mac OSX 10.5
1453rm -rf conftest.dSYM
1454rm -f conftest* libconftest*])
1455if test "$ac_cv_prog_cc_globals_work" = no ; then
1456    AC_MSG_WARN([Common symbols not supported on this system!])
1457fi
1458])
1459dnl
1460dnl
1461dnl Return the structure alignment in pac_cv_c_struct_align
1462dnl Possible values include
1463dnl     packed - no padding or alignment, any item may begin on any byte
1464dnl     largest - extent of a structure is a multiple of the largest item;
1465dnl               items are aligned with their size
1466dnl     four - structs padded to a multiple of four
1467dnl     two  - like four, but to a multiple of two
1468dnl     eight - If objects containing 8-byte items are padded to a multiple
1469dnl             of eight
1470dnl     largestor4 - like largest, except that for items of size > 4, align
1471dnl                  on 4-byte boundaries.  E.g., align on the
1472dnl                  min(4,max(size of items)).
1473dnl     largestorword - (should be named largestorqword, with qword meaning
1474dnl                     quad-word): Like largestor4, but with a special case
1475dnl                     for 16-byte items (this is the 16-byte aligned
1476dnl                     quad-word-load special case).
1477dnl
1478dnl In addition, a "Could not determine alignment" and a
1479dnl "Multiple cases:" return is possible. 
1480dnl
1481AC_DEFUN([PAC_C_STRUCT_ALIGNMENT],[
1482AC_CACHE_CHECK([for C struct alignment],pac_cv_c_struct_align,[
1483AC_TRY_RUN([
1484#include <stdio.h>
1485#ifdef DEBUG_STRUCT_ALIGNMENT
1486#define DBG(a,b,c) printf( "type %s, size = %d, extent = %d\n", a, b, c )
1487#define CHECK(cond,flag) if (cond) { flag = 0; \
1488    printf( "Setting %s to false because of %s\n", #flag, #cond ); }
1489#else
1490#define DBG(a,b,c)
1491#define CHECK(cond,flag) if (cond) { flag = 0; }
1492#endif
1493
1494int main( int argc, char *argv[] )
1495{
1496    FILE *cf;
1497    int is_packed  = 1;
1498    int is_two     = 1;
1499    int is_four    = 1;
1500    int is_eight   = 1;
1501    int is_largest = 1;
1502    int is_largestorword = 1;
1503    int is_largestor4 = 1;
1504    int numCases;
1505
1506    /* We've seen PowerPC systems where the alignment may
1507       be largest for some items but not for double + int */
1508    struct { char a; int b; } char_int;
1509    struct { short a; int b; } short_int;
1510    struct { char a; short b; } char_short;
1511    struct { char a; long b; } char_long;
1512    struct { char a; float b; } char_float;
1513    struct { char a; double b; } char_double;
1514    struct { char a; int b; char c; } char_int_char;
1515    struct { char a; short b; char c; } char_short_char;
1516#ifdef HAVE_LONG_DOUBLE
1517    struct { char a; long double b; } char_long_double;
1518#endif
1519    int size, extent;
1520
1521    size = sizeof(char) + sizeof(int);
1522    extent = sizeof(char_int);
1523    if (size != extent) is_packed = 0;
1524    CHECK((extent % sizeof(int)) != 0, is_largest);
1525    CHECK((extent % sizeof(int)) != 0, is_largestor4);
1526    CHECK((extent % sizeof(int)) != 0, is_largestorword);
1527    if ( (extent % 2) != 0) is_two = 0;
1528    if ( (extent % 4) != 0) is_four = 0;
1529    if (sizeof(int) == 8 && (extent % 8) != 0) is_eight = 0;
1530    DBG("char_int",size,extent);
1531
1532    size = sizeof(short) + sizeof(int);
1533    extent = sizeof(short_int);
1534    if (size != extent) is_packed = 0;
1535    CHECK((extent % sizeof(int)) != 0, is_largest);
1536    CHECK((extent % sizeof(int)) != 0, is_largestor4);
1537    CHECK((extent % sizeof(int)) != 0, is_largestorword);
1538    if ( (extent % 2) != 0) is_two = 0;
1539    if ( (size == 6) && (extent == 8) ) is_two = 0;
1540    if ( (extent % 4) != 0) is_four = 0;
1541    if (sizeof(int) == 8 && (extent % 8) != 0) is_eight = 0;
1542    DBG("short_int",size,extent);
1543
1544    size = sizeof(char) + sizeof(short);
1545    extent = sizeof(char_short);
1546    if (size != extent) is_packed = 0;
1547    CHECK((extent % sizeof(short)) != 0,is_largest);
1548    CHECK((extent % sizeof(short)) != 0,is_largestor4);
1549    CHECK((extent % sizeof(short)) != 0,is_largestorword);
1550    if ( (extent % 2) != 0) is_two = 0;
1551    if (sizeof(short) == 4 && (extent % 4) != 0) is_four = 0;
1552    if (sizeof(short) == 8 && (extent % 8) != 0) is_eight = 0;
1553    DBG("char_short",size,extent);
1554
1555    size = sizeof(char) + sizeof(long);
1556    extent = sizeof(char_long);
1557    if (size != extent) is_packed = 0;
1558    CHECK((extent % sizeof(long)) != 0,is_largest);
1559    CHECK((extent % 4) != 0,is_largestor4);
1560    CHECK((extent % sizeof(long)) != 0,is_largestorword);
1561    if ( (extent % 2) != 0) is_two = 0;
1562    if ( (extent % 4) != 0) is_four = 0;
1563    if (sizeof(long) == 8 && (extent % 8) != 0) is_eight = 0;
1564    DBG("char_long",size,extent);
1565
1566    size = sizeof(char) + sizeof(float);
1567    extent = sizeof(char_float);
1568    if (size != extent) is_packed = 0;
1569    CHECK((extent % sizeof(float)) != 0,is_largest);
1570    CHECK((extent % sizeof(float)) != 0,is_largestor4);
1571    CHECK((extent % sizeof(float)) != 0,is_largestorword);
1572    if ( (extent % 2) != 0) is_two = 0;
1573    if ( (extent % 4) != 0) is_four = 0;
1574    if (sizeof(float) == 8 && (extent % 8) != 0) is_eight = 0;
1575    DBG("char_float",size,extent);
1576
1577    size = sizeof(char) + sizeof(double);
1578    extent = sizeof(char_double);
1579    if (size != extent) is_packed = 0;
1580    CHECK((extent % sizeof(double)) != 0,is_largest);
1581    CHECK((extent % 4) != 0,is_largestor4);
1582    CHECK((extent % sizeof(int)) != 0,is_largestorword);
1583    if ( (extent % 2) != 0) is_two = 0;
1584    if ( (extent % 4) != 0) is_four = 0;
1585    if (sizeof(double) == 8 && (extent % 8) != 0) is_eight = 0;
1586    DBG("char_double",size,extent);
1587
1588#ifdef HAVE_LONG_DOUBLE
1589    size = sizeof(char) + sizeof(long double);
1590    extent = sizeof(char_long_double);
1591    if (size != extent) is_packed = 0;
1592    CHECK((extent % sizeof(long double)) != 0,is_largest);
1593    CHECK((extent % 4) != 0,is_largestor4);
1594    CHECK((extent % 16) == 0,is_largestor4);
1595    CHECK((extent % sizeof(long double)) != 0,is_largestorword);
1596    /* This case only applies to largestorword if long doubles are 16 bytes */
1597    if (sizeof(long double) != 16) is_largestorword = 0;
1598    if ( (extent % 2) != 0) is_two = 0;
1599    if ( (extent % 4) != 0) is_four = 0;
1600    if (sizeof(long double) >= 8 && (extent % 8) != 0) is_eight = 0;
1601    DBG("char_long-double",size,extent);
1602#else
1603    /* The special case of largestorword only applies if long double
1604       available */
1605    is_largestorword=0;
1606#endif
1607
1608    /* char int char helps separate largest from 4/8 aligned */
1609    size = sizeof(char) + sizeof(int) + sizeof(char);
1610    extent = sizeof(char_int_char);
1611    if (size != extent) is_packed = 0;
1612    CHECK((extent % sizeof(int)) != 0,is_largest);
1613    CHECK((extent % sizeof(int)) != 0,is_largestor4);
1614    CHECK((extent % sizeof(int)) != 0,is_largestorword);
1615    if ( (extent % 2) != 0) is_two = 0;
1616    if ( (extent % 4) != 0) is_four = 0;
1617    if (sizeof(int) == 8 && (extent % 8) != 0) is_eight = 0;
1618    DBG("char_int_char",size,extent);
1619
1620    /* char short char helps separate largest from 4/8 aligned */
1621    size = sizeof(char) + sizeof(short) + sizeof(char);
1622    extent = sizeof(char_short_char);
1623    if (size != extent) is_packed = 0;
1624    CHECK((extent % sizeof(short)) != 0,is_largest);
1625    CHECK((extent % sizeof(short)) != 0,is_largestor4);
1626    CHECK((extent % sizeof(short)) != 0,is_largestorword);
1627    if ( (extent % 2) != 0) is_two = 0;
1628    if (sizeof(short) == 4 && (extent % 4) != 0) is_four = 0;
1629    CHECK((extent == 6) && (size == 4),is_four);
1630    if (sizeof(short) == 8 && (extent % 8) != 0) is_eight = 0;
1631    DBG("char_short_char",size,extent);
1632
1633    /* If aligned mod 8, it will be aligned mod 4 */
1634    if (is_eight) { is_four = 0; is_two = 0; }
1635
1636    if (is_four) is_two = 0;
1637
1638    /* largest superceeds eight */
1639    if (is_largest) is_eight = 0;
1640
1641    /* Tabulate the results */
1642    cf = fopen( "ctest.out", "w" );
1643    numCases = is_packed + is_largest + is_largestorword + is_largestor4 +
1644        is_two + is_four + is_eight;
1645    if (numCases == 0) {
1646        fprintf( cf, "Could not determine alignment\n" );
1647    }
1648    else {
1649        if (numCases != 1) {
1650            fprintf( cf, "Multiple cases:\n" );
1651        }
1652        if (is_packed) fprintf( cf, "packed\n" );
1653        if (is_largest) fprintf( cf, "largest\n" );
1654        if (is_largestorword) fprintf( cf, "largestorword\n" );
1655        if (is_largestor4) fprintf( cf, "largestor4\n" );
1656        if (is_two) fprintf( cf, "two\n" );
1657        if (is_four) fprintf( cf, "four\n" );
1658        if (is_eight) fprintf( cf, "eight\n" );
1659    }
1660    fclose( cf );
1661    return 0;
1662}],
1663pac_cv_c_struct_align=`cat ctest.out`
1664,pac_cv_c_struct_align="unknown",pac_cv_c_struct_align="$CROSS_ALIGN_STRUCT")
1665rm -f ctest.out
1666])
1667if test -z "$pac_cv_c_struct_align" ; then
1668    pac_cv_c_struct_align="unknown"
1669fi
1670])
1671dnl
1672dnl
1673dnl Return the integer structure alignment in pac_cv_c_max_integer_align
1674dnl Possible values include
1675dnl     packed
1676dnl     two
1677dnl     four
1678dnl     eight
1679dnl
1680dnl In addition, a "Could not determine alignment" and a "error!"
1681dnl return is possible. 
1682AC_DEFUN([PAC_C_MAX_INTEGER_ALIGN],[
1683AC_CACHE_CHECK([for max C struct integer alignment],
1684pac_cv_c_max_integer_align,[
1685AC_TRY_RUN([
1686#include <stdio.h>
1687#define DBG(a,b,c)
1688int main( int argc, char *argv[] )
1689{
1690    FILE *cf;
1691    int is_packed  = 1;
1692    int is_two     = 1;
1693    int is_four    = 1;
1694    int is_eight   = 1;
1695    struct { char a; int b; } char_int;
1696    struct { char a; short b; } char_short;
1697    struct { char a; long b; } char_long;
1698    struct { char a; int b; char c; } char_int_char;
1699    struct { char a; short b; char c; } char_short_char;
1700#ifdef HAVE_LONG_LONG_INT
1701    struct { long long int a; char b; } lli_c;
1702    struct { char a; long long int b; } c_lli;
1703#endif
1704    int size, extent, extent2;
1705
1706    /* assume max integer alignment isn't 8 if we don't have
1707     * an eight-byte value :)
1708     */
1709#ifdef HAVE_LONG_LONG_INT
1710    if (sizeof(int) < 8 && sizeof(long) < 8 && sizeof(long long int) < 8)
1711        is_eight = 0;
1712#else
1713    if (sizeof(int) < 8 && sizeof(long) < 8) is_eight = 0;
1714#endif
1715
1716    size = sizeof(char) + sizeof(int);
1717    extent = sizeof(char_int);
1718    if (size != extent) is_packed = 0;
1719    if ( (extent % 2) != 0) is_two = 0;
1720    if ( (extent % 4) != 0) is_four = 0;
1721    if (sizeof(int) == 8 && (extent % 8) != 0) is_eight = 0;
1722    DBG("char_int",size,extent);
1723
1724    size = sizeof(char) + sizeof(short);
1725    extent = sizeof(char_short);
1726    if (size != extent) is_packed = 0;
1727    if ( (extent % 2) != 0) is_two = 0;
1728    if (sizeof(short) == 4 && (extent % 4) != 0) is_four = 0;
1729    if (sizeof(short) == 8 && (extent % 8) != 0) is_eight = 0;
1730    DBG("char_short",size,extent);
1731
1732    size = sizeof(char) + sizeof(long);
1733    extent = sizeof(char_long);
1734    if (size != extent) is_packed = 0;
1735    if ( (extent % 2) != 0) is_two = 0;
1736    if ( (extent % 4) != 0) is_four = 0;
1737    if (sizeof(long) == 8 && (extent % 8) != 0) is_eight = 0;
1738    DBG("char_long",size,extent);
1739
1740#ifdef HAVE_LONG_LONG_INT
1741    size = sizeof(char) + sizeof(long long int);
1742    extent = sizeof(lli_c);
1743    extent2 = sizeof(c_lli);
1744    if (size != extent) is_packed = 0;
1745    if ( (extent % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
1746    if ( (extent % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
1747    if (sizeof(long long int) >= 8 && (extent % 8) != 0 && (extent2 % 8) != 0)
1748        is_eight = 0;
1749#endif
1750
1751    size = sizeof(char) + sizeof(int) + sizeof(char);
1752    extent = sizeof(char_int_char);
1753    if (size != extent) is_packed = 0;
1754    if ( (extent % 2) != 0) is_two = 0;
1755    if ( (extent % 4) != 0) is_four = 0;
1756    if (sizeof(int) == 8 && (extent % 8) != 0) is_eight = 0;
1757    DBG("char_int_char",size,extent);
1758
1759    size = sizeof(char) + sizeof(short) + sizeof(char);
1760    extent = sizeof(char_short_char);
1761    if (size != extent) is_packed = 0;
1762    if ( (extent % 2) != 0) is_two = 0;
1763    if (sizeof(short) == 4 && (extent % 4) != 0) is_four = 0;
1764    if (sizeof(short) == 8 && (extent % 8) != 0) is_eight = 0;
1765    DBG("char_short_char",size,extent);
1766
1767    /* If aligned mod 8, it will be aligned mod 4 */
1768    if (is_eight) { is_four = 0; is_two = 0; }
1769
1770    if (is_four) is_two = 0;
1771
1772    /* Tabulate the results */
1773    cf = fopen( "ctest.out", "w" );
1774    if (is_packed + is_two + is_four + is_eight == 0) {
1775        fprintf( cf, "Could not determine alignment\n" );
1776    }
1777    else {
1778        if (is_packed + is_two + is_four + is_eight != 1) {
1779            fprintf( cf, "error!\n" );
1780        }
1781        else {
1782            if (is_packed) fprintf( cf, "packed\n" );
1783            if (is_two) fprintf( cf, "two\n" );
1784            if (is_four) fprintf( cf, "four\n" );
1785            if (is_eight) fprintf( cf, "eight\n" );
1786        }
1787    }
1788    fclose( cf );
1789    return 0;
1790}],
1791pac_cv_c_max_integer_align=`cat ctest.out`,
1792pac_cv_c_max_integer_align="unknown",
1793pac_cv_c_max_integer_align="$CROSS_ALIGN_STRUCT_INT")
1794rm -f ctest.out
1795])
1796if test -z "$pac_cv_c_max_integer_align" ; then
1797    pac_cv_c_max_integer_align="unknown"
1798fi
1799])
1800dnl
1801dnl
1802dnl Return the floating point structure alignment in
1803dnl pac_cv_c_max_fp_align.
1804dnl
1805dnl Possible values include:
1806dnl     packed
1807dnl     two
1808dnl     four
1809dnl     eight
1810dnl     sixteen
1811dnl
1812dnl In addition, a "Could not determine alignment" and a "error!"
1813dnl return is possible. 
1814AC_DEFUN([PAC_C_MAX_FP_ALIGN],[
1815AC_CACHE_CHECK([for max C struct floating point alignment],
1816pac_cv_c_max_fp_align,[
1817AC_TRY_RUN([
1818#include <stdio.h>
1819#define DBG(a,b,c)
1820int main( int argc, char *argv[] )
1821{
1822    FILE *cf;
1823    int is_packed  = 1;
1824    int is_two     = 1;
1825    int is_four    = 1;
1826    int is_eight   = 1;
1827    int is_sixteen = 1;
1828    struct { char a; float b; } char_float;
1829    struct { float b; char a; } float_char;
1830    struct { char a; double b; } char_double;
1831    struct { double b; char a; } double_char;
1832#ifdef HAVE_LONG_DOUBLE
1833    struct { char a; long double b; } char_long_double;
1834    struct { long double b; char a; } long_double_char;
1835    struct { long double a; int b; char c; } long_double_int_char;
1836#endif
1837    int size, extent1, extent2;
1838
1839    size = sizeof(char) + sizeof(float);
1840    extent1 = sizeof(char_float);
1841    extent2 = sizeof(float_char);
1842    if (size != extent1) is_packed = 0;
1843    if ( (extent1 % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
1844    if ( (extent1 % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
1845    if (sizeof(float) == 8 && (extent1 % 8) != 0 && (extent2 % 8) != 0)
1846        is_eight = 0;
1847    DBG("char_float",size,extent1);
1848
1849    size = sizeof(char) + sizeof(double);
1850    extent1 = sizeof(char_double);
1851    extent2 = sizeof(double_char);
1852    if (size != extent1) is_packed = 0;
1853    if ( (extent1 % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
1854    if ( (extent1 % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
1855    if (sizeof(double) == 8 && (extent1 % 8) != 0 && (extent2 % 8) != 0)
1856        is_eight = 0;
1857    DBG("char_double",size,extent1);
1858
1859#ifdef HAVE_LONG_DOUBLE
1860    size = sizeof(char) + sizeof(long double);
1861    extent1 = sizeof(char_long_double);
1862    extent2 = sizeof(long_double_char);
1863    if (size != extent1) is_packed = 0;
1864    if ( (extent1 % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
1865    if ( (extent1 % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
1866    if (sizeof(long double) >= 8 && (extent1 % 8) != 0 && (extent2 % 8) != 0)
1867        is_eight = 0;
1868    if (sizeof(long double) > 8 && (extent1 % 16) != 0
1869        && (extent2 % 16) != 0) is_sixteen = 0;
1870    DBG("char_long-double",size,extent1);
1871
1872    extent1 = sizeof(long_double_int_char);
1873    if ( (extent1 % 2) != 0) is_two = 0;
1874    if ( (extent1 % 4) != 0) is_four = 0;
1875    if (sizeof(long double) >= 8 && (extent1 % 8) != 0) is_eight = 0;
1876    if (sizeof(long double) > 8 && (extent1 % 16) != 0) is_sixteen = 0;
1877#else
1878    is_sixteen = 0;
1879#endif
1880
1881    if (is_sixteen) { is_eight = 0; is_four = 0; is_two = 0; }
1882
1883    if (is_eight) { is_four = 0; is_two = 0; }
1884
1885    if (is_four) is_two = 0;
1886
1887    /* Tabulate the results */
1888    cf = fopen( "ctest.out", "w" );
1889    if (is_packed + is_two + is_four + is_eight + is_sixteen == 0) {
1890        fprintf( cf, "Could not determine alignment\n" );
1891    }
1892    else {
1893        if (is_packed + is_two + is_four + is_eight + is_sixteen != 1) {
1894            fprintf( cf, "error!\n" );
1895        }
1896        else {
1897            if (is_packed) fprintf( cf, "packed\n" );
1898            if (is_two) fprintf( cf, "two\n" );
1899            if (is_four) fprintf( cf, "four\n" );
1900            if (is_eight) fprintf( cf, "eight\n" );
1901            if (is_sixteen) fprintf( cf, "sixteen\n" );
1902        }
1903    }
1904    fclose( cf );
1905    return 0;
1906}],
1907pac_cv_c_max_fp_align=`cat ctest.out`,
1908pac_cv_c_max_fp_align="unknown",
1909pac_cv_c_max_fp_align="$CROSS_ALIGN_STRUCT_FP")
1910rm -f ctest.out
1911])
1912if test -z "$pac_cv_c_max_fp_align" ; then
1913    pac_cv_c_max_fp_align="unknown"
1914fi
1915])
1916dnl
1917dnl
1918dnl Return the floating point structure alignment in
1919dnl pac_cv_c_max_double_fp_align.
1920dnl
1921dnl Possible values include:
1922dnl     packed
1923dnl     two
1924dnl     four
1925dnl     eight
1926dnl
1927dnl In addition, a "Could not determine alignment" and a "error!"
1928dnl return is possible. 
1929AC_DEFUN([PAC_C_MAX_DOUBLE_FP_ALIGN],[
1930AC_CACHE_CHECK([for max C struct alignment of structs with doubles],
1931pac_cv_c_max_double_fp_align,[
1932AC_TRY_RUN([
1933#include <stdio.h>
1934#define DBG(a,b,c)
1935int main( int argc, char *argv[] )
1936{
1937    FILE *cf;
1938    int is_packed  = 1;
1939    int is_two     = 1;
1940    int is_four    = 1;
1941    int is_eight   = 1;
1942    struct { char a; float b; } char_float;
1943    struct { float b; char a; } float_char;
1944    struct { char a; double b; } char_double;
1945    struct { double b; char a; } double_char;
1946    int size, extent1, extent2;
1947
1948    size = sizeof(char) + sizeof(float);
1949    extent1 = sizeof(char_float);
1950    extent2 = sizeof(float_char);
1951    if (size != extent1) is_packed = 0;
1952    if ( (extent1 % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
1953    if ( (extent1 % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
1954    if (sizeof(float) == 8 && (extent1 % 8) != 0 && (extent2 % 8) != 0)
1955        is_eight = 0;
1956    DBG("char_float",size,extent1);
1957
1958    size = sizeof(char) + sizeof(double);
1959    extent1 = sizeof(char_double);
1960    extent2 = sizeof(double_char);
1961    if (size != extent1) is_packed = 0;
1962    if ( (extent1 % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
1963    if ( (extent1 % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
1964    if (sizeof(double) == 8 && (extent1 % 8) != 0 && (extent2 % 8) != 0)
1965        is_eight = 0;
1966    DBG("char_double",size,extent1);
1967
1968    if (is_eight) { is_four = 0; is_two = 0; }
1969
1970    if (is_four) is_two = 0;
1971
1972    /* Tabulate the results */
1973    cf = fopen( "ctest.out", "w" );
1974    if (is_packed + is_two + is_four + is_eight == 0) {
1975        fprintf( cf, "Could not determine alignment\n" );
1976    }
1977    else {
1978        if (is_packed + is_two + is_four + is_eight != 1) {
1979            fprintf( cf, "error!\n" );
1980        }
1981        else {
1982            if (is_packed) fprintf( cf, "packed\n" );
1983            if (is_two) fprintf( cf, "two\n" );
1984            if (is_four) fprintf( cf, "four\n" );
1985            if (is_eight) fprintf( cf, "eight\n" );
1986        }
1987    }
1988    fclose( cf );
1989    return 0;
1990}],
1991pac_cv_c_max_double_fp_align=`cat ctest.out`,
1992pac_cv_c_max_double_fp_align="unknown",
1993pac_cv_c_max_double_fp_align="$CROSS_ALIGN_STRUCT_DOUBLE_FP")
1994rm -f ctest.out
1995])
1996if test -z "$pac_cv_c_max_double_fp_align" ; then
1997    pac_cv_c_max_double_fp_align="unknown"
1998fi
1999])
2000AC_DEFUN([PAC_C_MAX_LONGDOUBLE_FP_ALIGN],[
2001AC_CACHE_CHECK([for max C struct floating point alignment with long doubles],
2002pac_cv_c_max_longdouble_fp_align,[
2003AC_TRY_RUN([
2004#include <stdio.h>
2005#define DBG(a,b,c)
2006int main( int argc, char *argv[] )
2007{
2008    FILE *cf;
2009    int is_packed  = 1;
2010    int is_two     = 1;
2011    int is_four    = 1;
2012    int is_eight   = 1;
2013    int is_sixteen = 1;
2014    struct { char a; long double b; } char_long_double;
2015    struct { long double b; char a; } long_double_char;
2016    struct { long double a; int b; char c; } long_double_int_char;
2017    int size, extent1, extent2;
2018
2019    size = sizeof(char) + sizeof(long double);
2020    extent1 = sizeof(char_long_double);
2021    extent2 = sizeof(long_double_char);
2022    if (size != extent1) is_packed = 0;
2023    if ( (extent1 % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
2024    if ( (extent1 % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
2025    if (sizeof(long double) >= 8 && (extent1 % 8) != 0 && (extent2 % 8) != 0)
2026        is_eight = 0;
2027    if (sizeof(long double) > 8 && (extent1 % 16) != 0
2028        && (extent2 % 16) != 0) is_sixteen = 0;
2029    DBG("char_long-double",size,extent1);
2030
2031    extent1 = sizeof(long_double_int_char);
2032    if ( (extent1 % 2) != 0) is_two = 0;
2033    if ( (extent1 % 4) != 0) is_four = 0;
2034    if (sizeof(long double) >= 8 && (extent1 % 8) != 0) is_eight = 0;
2035    if (sizeof(long double) > 8 && (extent1 % 16) != 0) is_sixteen = 0;
2036
2037    if (is_sixteen) { is_eight = 0; is_four = 0; is_two = 0; }
2038
2039    if (is_eight) { is_four = 0; is_two = 0; }
2040
2041    if (is_four) is_two = 0;
2042
2043    /* Tabulate the results */
2044    cf = fopen( "ctest.out", "w" );
2045    if (is_packed + is_two + is_four + is_eight + is_sixteen == 0) {
2046        fprintf( cf, "Could not determine alignment\n" );
2047    }
2048    else {
2049        if (is_packed + is_two + is_four + is_eight + is_sixteen != 1) {
2050            fprintf( cf, "error!\n" );
2051        }
2052        else {
2053            if (is_packed) fprintf( cf, "packed\n" );
2054            if (is_two) fprintf( cf, "two\n" );
2055            if (is_four) fprintf( cf, "four\n" );
2056            if (is_eight) fprintf( cf, "eight\n" );
2057            if (is_sixteen) fprintf( cf, "sixteen\n" );
2058        }
2059    }
2060    fclose( cf );
2061    return 0;
2062}],
2063pac_cv_c_max_longdouble_fp_align=`cat ctest.out`,
2064pac_cv_c_max_longdouble_fp_align="unknown",
2065pac_cv_c_max_longdouble_fp_align="$CROSS_ALIGN_STRUCT_LONGDOUBLE_FP")
2066rm -f ctest.out
2067])
2068if test -z "$pac_cv_c_max_longdouble_fp_align" ; then
2069    pac_cv_c_max_longdouble_fp_align="unknown"
2070fi
2071])
2072dnl
2073dnl Other tests assume that there is potentially a maximum alignment
2074dnl and that if there is no maximum alignment, or a type is smaller than
2075dnl that value, then we align on the size of the value, with the exception
2076dnl of the "position-based alignment" rules we test for separately.
2077dnl
2078dnl It turns out that these assumptions have fallen short in at least one
2079dnl case, on MacBook Pros, where doubles are aligned on 4-byte boundaries
2080dnl even when long doubles are aligned on 16-byte boundaries. So this test
2081dnl is here specifically to handle this case.
2082dnl
2083dnl Puts result in pac_cv_c_double_alignment_exception.
2084dnl
2085dnl Possible values currently include no and four.
2086dnl
2087AC_DEFUN([PAC_C_DOUBLE_ALIGNMENT_EXCEPTION],[
2088AC_CACHE_CHECK([if double alignment breaks rules, find actual alignment],
2089pac_cv_c_double_alignment_exception,[
2090AC_TRY_RUN([
2091#include <stdio.h>
2092#define DBG(a,b,c)
2093int main( int argc, char *argv[] )
2094{
2095    FILE *cf;
2096    struct { char a; double b; } char_double;
2097    struct { double b; char a; } double_char;
2098    int extent1, extent2, align_4 = 0;
2099
2100    extent1 = sizeof(char_double);
2101    extent2 = sizeof(double_char);
2102
2103    /* we're interested in the largest value, will let separate test
2104     * deal with position-based issues.
2105     */
2106    if (extent1 < extent2) extent1 = extent2;
2107    if ((sizeof(double) == 8) && (extent1 % 8) != 0) {
2108       if (extent1 % 4 == 0) {
2109#ifdef HAVE_MAX_FP_ALIGNMENT
2110          if (HAVE_MAX_FP_ALIGNMENT >= 8) align_4 = 1;
2111#else
2112          align_4 = 1;
2113#endif
2114       }
2115    }
2116
2117    cf = fopen( "ctest.out", "w" );
2118
2119    if (align_4) fprintf( cf, "four\n" );
2120    else fprintf( cf, "no\n" );
2121
2122    fclose( cf );
2123    return 0;
2124}],
2125pac_cv_c_double_alignment_exception=`cat ctest.out`,
2126pac_cv_c_double_alignment_exception="unknown",
2127pac_cv_c_double_alignment_exception="$CROSS_ALIGN_DOUBLE_EXCEPTION")
2128rm -f ctest.out
2129])
2130if test -z "$pac_cv_c_double_alignment_exception" ; then
2131    pac_cv_c_double_alignment_exception="unknown"
2132fi
2133])
2134dnl
2135dnl
2136dnl Test for odd struct alignment rule that only applies max.
2137dnl padding when double value is at front of type.
2138dnl Puts result in pac_cv_c_double_pos_align.
2139dnl
2140dnl Search for "Power alignment mode" for more details.
2141dnl
2142dnl Possible values include yes, no, and unknown.
2143dnl
2144AC_DEFUN([PAC_C_DOUBLE_POS_ALIGN],[
2145AC_CACHE_CHECK([if alignment of structs with doubles is based on position],
2146pac_cv_c_double_pos_align,[
2147AC_TRY_RUN([
2148#include <stdio.h>
2149#define DBG(a,b,c)
2150int main( int argc, char *argv[] )
2151{
2152    FILE *cf;
2153    int padding_varies_by_pos = 0;
2154    struct { char a; double b; } char_double;
2155    struct { double b; char a; } double_char;
2156    int extent1, extent2;
2157
2158    extent1 = sizeof(char_double);
2159    extent2 = sizeof(double_char);
2160    if (extent1 != extent2) padding_varies_by_pos = 1;
2161
2162    cf = fopen( "ctest.out", "w" );
2163    if (padding_varies_by_pos) fprintf( cf, "yes\n" );
2164    else fprintf( cf, "no\n" );
2165
2166    fclose( cf );
2167    return 0;
2168}],
2169pac_cv_c_double_pos_align=`cat ctest.out`,
2170pac_cv_c_double_pos_align="unknown",
2171pac_cv_c_double_pos_align="$CROSS_ALIGN_DOUBLE_POS")
2172rm -f ctest.out
2173])
2174if test -z "$pac_cv_c_double_pos_align" ; then
2175    pac_cv_c_double_pos_align="unknown"
2176fi
2177])
2178dnl
2179dnl
2180dnl Test for odd struct alignment rule that only applies max.
2181dnl padding when long long int value is at front of type.
2182dnl Puts result in pac_cv_c_llint_pos_align.
2183dnl
2184dnl Search for "Power alignment mode" for more details.
2185dnl
2186dnl Possible values include yes, no, and unknown.
2187dnl
2188AC_DEFUN([PAC_C_LLINT_POS_ALIGN],[
2189AC_CACHE_CHECK([if alignment of structs with long long ints is based on position],
2190pac_cv_c_llint_pos_align,[
2191AC_TRY_RUN([
2192#include <stdio.h>
2193#define DBG(a,b,c)
2194int main( int argc, char *argv[] )
2195{
2196    FILE *cf;
2197    int padding_varies_by_pos = 0;
2198#ifdef HAVE_LONG_LONG_INT
2199    struct { char a; long long int b; } char_llint;
2200    struct { long long int b; char a; } llint_char;
2201    int extent1, extent2;
2202
2203    extent1 = sizeof(char_llint);
2204    extent2 = sizeof(llint_char);
2205    if (extent1 != extent2) padding_varies_by_pos = 1;
2206#endif
2207
2208    cf = fopen( "ctest.out", "w" );
2209    if (padding_varies_by_pos) fprintf( cf, "yes\n" );
2210    else fprintf( cf, "no\n" );
2211
2212    fclose( cf );
2213    return 0;
2214}],
2215pac_cv_c_llint_pos_align=`cat ctest.out`,
2216pac_cv_c_llint_pos_align="unknown",
2217pac_cv_c_llint_pos_align="$CROSS_ALIGN_LLINT_POS")
2218rm -f ctest.out
2219])
2220if test -z "$pac_cv_c_llint_pos_align" ; then
2221    pac_cv_c_llint_pos_align="unknown"
2222fi
2223])
2224
2225dnl
2226dnl
2227dnl/*D
2228dnl PAC_FUNC_NEEDS_DECL - Set NEEDS_<funcname>_DECL if a declaration is needed
2229dnl
2230dnl Synopsis:
2231dnl PAC_FUNC_NEEDS_DECL(headerfiles,funcname)
2232dnl
2233dnl Output Effect:
2234dnl Sets 'NEEDS_<funcname>_DECL' if 'funcname' is not declared by the
2235dnl headerfiles.
2236dnl
2237dnl Approach:
2238dnl Try to compile a program with the function, but passed with an incorrect
2239dnl calling sequence.  If the compilation fails, then the declaration
2240dnl is provided within the header files.  If the compilation succeeds,
2241dnl the declaration is required.
2242dnl
2243dnl We use a 'double' as the first argument to try and catch varargs
2244dnl routines that may use an int or pointer as the first argument.
2245dnl
2246dnl There is one difficulty - if the compiler has been instructed to
2247dnl fail on implicitly defined functions, then this test will always
2248dnl fail.
2249dnl
2250dnl D*/
2251AC_DEFUN([PAC_FUNC_NEEDS_DECL],[
2252AC_CACHE_CHECK([whether $2 needs a declaration],
2253pac_cv_func_decl_$2,[
2254AC_TRY_COMPILE([$1
2255int $2(double, int, double, const char *);],[int a=$2(1.0,27,1.0,"foo");],
2256pac_cv_func_decl_$2=yes,pac_cv_func_decl_$2=no)])
2257if test "$pac_cv_func_decl_$2" = "yes" ; then
2258changequote(<<,>>)dnl
2259define(<<PAC_FUNC_NAME>>, translit(NEEDS_$2_DECL, [a-z *], [A-Z__]))dnl
2260changequote([, ])dnl
2261    AC_DEFINE_UNQUOTED(PAC_FUNC_NAME,1,[Define if $2 needs a declaration])
2262undefine([PAC_FUNC_NAME])
2263fi
2264])dnl
2265dnl
2266dnl /*D
2267dnl PAC_CHECK_SIZEOF_DERIVED - Get the size of a user-defined type,
2268dnl such as a struct
2269dnl
2270dnl PAC_CHECK_SIZEOF_DERIVED(shortname,definition,defaultsize)
2271dnl Like AC_CHECK_SIZEOF, but handles arbitrary types.
2272dnl Unlike AC_CHECK_SIZEOF, does not define SIZEOF_xxx (because
2273dnl autoheader can''t handle this case)
2274dnl D*/
2275AC_DEFUN([PAC_CHECK_SIZEOF_DERIVED],[
2276changequote(<<,>>)dnl
2277define(<<AC_TYPE_NAME>>,translit(sizeof_$1,[a-z *], [A-Z_P]))dnl
2278define(<<AC_CV_NAME>>,translit(pac_cv_sizeof_$1,[ *], [_p]))dnl
2279changequote([,])dnl
2280rm -f conftestval
2281AC_MSG_CHECKING([for size of $1])
2282AC_CACHE_VAL(AC_CV_NAME,
2283[AC_TRY_RUN([#include <stdio.h>
2284main()
2285{
2286  $2 a;
2287  FILE *f=fopen("conftestval", "w");
2288  if (!f) exit(1);
2289  fprintf(f, "%d\n", sizeof(a));
2290  exit(0);
2291}],AC_CV_NAME=`cat conftestval`,AC_CV_NAME=0,ifelse([$3],,,AC_CV_NAME=$3))])
2292AC_MSG_RESULT($AC_CV_NAME)
2293dnl AC_DEFINE_UNQUOTED(AC_TYPE_NAME,$AC_CV_NAME)
2294undefine([AC_TYPE_NAME])undefine([AC_CV_NAME])
2295])
2296dnl
2297dnl /*D
2298dnl PAC_CHECK_SIZEOF_2TYPES - Get the size of a pair of types
2299dnl
2300dnl PAC_CHECK_SIZEOF_2TYPES(shortname,type1,type2,defaultsize)
2301dnl Like AC_CHECK_SIZEOF, but handles pairs of types.
2302dnl Unlike AC_CHECK_SIZEOF, does not define SIZEOF_xxx (because
2303dnl autoheader can''t handle this case)
2304dnl D*/
2305AC_DEFUN([PAC_CHECK_SIZEOF_2TYPES],[
2306changequote(<<,>>)dnl
2307define(<<AC_TYPE_NAME>>,translit(sizeof_$1,[a-z *], [A-Z_P]))dnl
2308define(<<AC_CV_NAME>>,translit(pac_cv_sizeof_$1,[ *], [_p]))dnl
2309changequote([,])dnl
2310rm -f conftestval
2311AC_MSG_CHECKING([for size of $1])
2312AC_CACHE_VAL(AC_CV_NAME,
2313[AC_TRY_RUN([#include <stdio.h>
2314main()
2315{
2316  $2 a;
2317  $3 b;
2318  FILE *f=fopen("conftestval", "w");
2319  if (!f) return 1; /* avoid exit */
2320  fprintf(f, "%d\n", (int)(sizeof(a) + sizeof(b)));
2321  return 0;
2322}],AC_CV_NAME=`cat conftestval`,AC_CV_NAME=0,ifelse([$4],,,AC_CV_NAME=$4))])
2323if test "X$AC_CV_NAME" = "X" ; then
2324    # We have a problem.  The test returned a zero status, but no output,
2325    # or we're cross-compiling (or think we are) and have no value for
2326    # this object
2327    :
2328fi
2329rm -f conftestval
2330AC_MSG_RESULT($AC_CV_NAME)
2331dnl AC_DEFINE_UNQUOTED(AC_TYPE_NAME,$AC_CV_NAME)
2332undefine([AC_TYPE_NAME])undefine([AC_CV_NAME])
2333])
2334
2335dnl
2336dnl PAC_C_GNU_ATTRIBUTE - See if the GCC __attribute__ specifier is allow.
2337dnl Use the following
2338dnl #ifndef HAVE_GCC_ATTRIBUTE
2339dnl #define __attribute__(a)
2340dnl #endif
2341dnl If *not*, define __attribute__(a) as null
2342dnl
2343dnl We start by requiring Gcc.  Some other compilers accept __attribute__
2344dnl but generate warning messages, or have different interpretations
2345dnl (which seems to make __attribute__ just as bad as #pragma)
2346dnl For example, the Intel icc compiler accepts __attribute__ and
2347dnl __attribute__((pure)) but generates warnings for __attribute__((format...))
2348dnl
2349AC_DEFUN([PAC_C_GNU_ATTRIBUTE],[
2350AC_REQUIRE([AC_PROG_CC_GNU])
2351if test "$ac_cv_prog_gcc" = "yes" ; then
2352    AC_CACHE_CHECK([whether __attribute__ allowed],
2353pac_cv_gnu_attr_pure,[
2354AC_TRY_COMPILE([int foo(int) __attribute__ ((pure));],[int a;],
2355pac_cv_gnu_attr_pure=yes,pac_cv_gnu_attr_pure=no)])
2356AC_CACHE_CHECK([whether __attribute__((format)) allowed],
2357pac_cv_gnu_attr_format,[
2358AC_TRY_COMPILE([int foo(char *,...) __attribute__ ((format(printf,1,2)));],[int a;],
2359pac_cv_gnu_attr_format=yes,pac_cv_gnu_attr_format=no)])
2360    if test "$pac_cv_gnu_attr_pure" = "yes" -a "$pac_cv_gnu_attr_format" = "yes" ; then
2361        AC_DEFINE(HAVE_GCC_ATTRIBUTE,1,[Define if GNU __attribute__ is supported])
2362    fi
2363fi
2364])
2365dnl
2366dnl Check for a broken install (fails to preserve file modification times,
2367dnl thus breaking libraries.
2368dnl
2369dnl Create a library, install it, and then try to link against it.
2370AC_DEFUN([PAC_PROG_INSTALL_BREAKS_LIBS],[
2371AC_CACHE_CHECK([whether install breaks libraries],
2372ac_cv_prog_install_breaks_libs,[
2373AC_REQUIRE([AC_PROG_RANLIB])
2374AC_REQUIRE([AC_PROG_INSTALL])
2375AC_REQUIRE([AC_PROG_CC])
2376ac_cv_prog_install_breaks_libs=yes
2377# This is needed for Mac OSX 10.5
2378rm -rf conftest.dSYM
2379rm -f libconftest* conftest*
2380echo 'int foo(int);int foo(int a){return a;}' > conftest1.c
2381echo 'extern int foo(int); int main( int argc, char **argv){ return foo(0); }' > conftest2.c
2382if ${CC-cc} $CFLAGS -c conftest1.c >conftest.out 2>&1 ; then
2383    if ${AR-ar} cr libconftest.a conftest1.o >/dev/null 2>&1 ; then
2384        if ${RANLIB-:} libconftest.a >/dev/null 2>&1 ; then
2385            # Anything less than sleep 10, and Mac OS/X (Darwin)
2386            # will claim that install works because ranlib won't complain
2387            sleep 10
2388            libinstall="$INSTALL_DATA"
2389            eval "libinstall=\"$libinstall\""
2390            if ${libinstall} libconftest.a libconftest1.a  >/dev/null 2>&1 ; then
2391                if ${CC-cc} $CFLAGS -o conftest conftest2.c $LDFLAGS libconftest1.a >>conftest.out 2>&1 && test -x conftest ; then
2392                    # Success!  Install works
2393                    ac_cv_prog_install_breaks_libs=no
2394                else
2395                    # Failure!  Does install -p work?   
2396                    rm -f libconftest1.a
2397                    if ${libinstall} -p libconftest.a libconftest1.a >/dev/null 2>&1 ; then
2398                        if ${CC-cc} $CFLAGS -o conftest conftest2.c $LDFLAGS libconftest1.a >>conftest.out 2>&1 && test -x conftest ; then
2399                        # Success!  Install works
2400                            ac_cv_prog_install_breaks_libs="no, with -p"
2401                        fi
2402                    fi
2403                fi
2404            fi
2405        fi
2406    fi
2407fi
2408# This is needed for Mac OSX 10.5
2409rm -rf conftest.dSYM
2410rm -f conftest* libconftest*])
2411
2412if test -z "$RANLIB_AFTER_INSTALL" ; then
2413    RANLIB_AFTER_INSTALL=no
2414fi
2415case "$ac_cv_prog_install_breaks_libs" in
2416        yes)
2417            RANLIB_AFTER_INSTALL=yes
2418        ;;
2419        "no, with -p")
2420            INSTALL_DATA="$INSTALL_DATA -p"
2421        ;;
2422        *)
2423        # Do nothing
2424        :
2425        ;;
2426esac
2427AC_SUBST(RANLIB_AFTER_INSTALL)
2428])
2429
2430#
2431# determine if the compiler defines a symbol containing the function name
2432# Inspired by checks within the src/mpid/globus/configure.in file in MPICH2
2433#
2434# These tests check not only that the compiler defines some symbol, such
2435# as __FUNCTION__, but that the symbol correctly names the function.
2436#
2437# Defines
2438#   HAVE__FUNC__      (if __func__ defined)
2439#   HAVE_CAP__FUNC__  (if __FUNC__ defined)
2440#   HAVE__FUNCTION__  (if __FUNCTION__ defined)
2441#
2442AC_DEFUN([PAC_CC_FUNCTION_NAME_SYMBOL],[
2443AC_CACHE_CHECK([whether the compiler defines __func__],
2444pac_cv_have__func__,[
2445tmp_am_cross=no
2446AC_RUN_IFELSE([
2447#include <string.h>
2448int foo(void);
2449int foo(void)
2450{
2451    return (strcmp(__func__, "foo") == 0);
2452}
2453int main(int argc, char ** argv)
2454{
2455    return (foo() ? 0 : 1);
2456}
2457], pac_cv_have__func__=yes, pac_cv_have__func__=no,tmp_am_cross=yes)
2458if test "$tmp_am_cross" = yes ; then
2459    AC_LINK_IFELSE([
2460#include <string.h>
2461int foo(void);
2462int foo(void)
2463{
2464    return (strcmp(__func__, "foo") == 0);
2465}
2466int main(int argc, char ** argv)
2467{
2468    return (foo() ? 0 : 1);
2469}
2470], pac_cv_have__func__=yes, pac_cv_have__func__=no)
2471fi
2472])
2473
2474if test "$pac_cv_have__func__" = "yes" ; then
2475    AC_DEFINE(HAVE__FUNC__,,[define if the compiler defines __func__])
2476fi
2477
2478AC_CACHE_CHECK([whether the compiler defines __FUNC__],
2479pac_cv_have_cap__func__,[
2480tmp_am_cross=no
2481AC_RUN_IFELSE([
2482#include <string.h>
2483int foo(void);
2484int foo(void)
2485{
2486    return (strcmp(__FUNC__, "foo") == 0);
2487}
2488int main(int argc, char ** argv)
2489{
2490    return (foo() ? 0 : 1);
2491}
2492], pac_cv_have_cap__func__=yes, pac_cv_have_cap__func__=no,tmp_am_cross=yes)
2493if test "$tmp_am_cross" = yes ; then
2494    AC_LINK_IFELSE([
2495#include <string.h>
2496int foo(void);
2497int foo(void)
2498{
2499    return (strcmp(__FUNC__, "foo") == 0);
2500}
2501int main(int argc, char ** argv)
2502{
2503    return (foo() ? 0 : 1);
2504}
2505], pac_cv_have__func__=yes, pac_cv_have__func__=no)
2506fi
2507])
2508
2509if test "$pac_cv_have_cap__func__" = "yes" ; then
2510    AC_DEFINE(HAVE_CAP__FUNC__,,[define if the compiler defines __FUNC__])
2511fi
2512
2513AC_CACHE_CHECK([whether the compiler sets __FUNCTION__],
2514pac_cv_have__function__,[
2515tmp_am_cross=no
2516AC_RUN_IFELSE([
2517#include <string.h>
2518int foo(void);
2519int foo(void)
2520{
2521    return (strcmp(__FUNCTION__, "foo") == 0);
2522}
2523int main(int argc, char ** argv)
2524{
2525    return (foo() ? 0 : 1);
2526}
2527], pac_cv_have__function__=yes, pac_cv_have__function__=no,tmp_am_cross=yes)
2528if test "$tmp_am_cross" = yes ; then
2529    AC_LINK_IFELSE([
2530#include <string.h>
2531int foo(void);
2532int foo(void)
2533{
2534    return (strcmp(__FUNCTION__, "foo") == 0);
2535}
2536int main(int argc, char ** argv)
2537{
2538    return (foo() ? 0 : 1);
2539}
2540], pac_cv_have__func__=yes, pac_cv_have__func__=no)
2541fi
2542])
2543
2544if test "$pac_cv_have__function__" = "yes" ; then
2545    AC_DEFINE(HAVE__FUNCTION__,,[define if the compiler defines __FUNCTION__])
2546fi
2547
2548])
Note: See TracBrowser for help on using the browser.