AMPI #952: update ROMIO to MPICH2-1.4.1p1
[charm.git] / src / libs / ck-libs / ampi / romio / confdb / aclocal_cc.m4
blob58ed3d1548d37e0d91dd7d69877d760c8061bc6d
1 dnl AC_PROG_CC_GNU
2 ifdef([AC_PROG_CC_GNU],,[AC_DEFUN([AC_PROG_CC_GNU],)])
4 dnl PAC_PROG_CC - reprioritize the C compiler search order
5 AC_DEFUN([PAC_PROG_CC],[
6         PAC_PUSH_FLAG([CFLAGS])
7         AC_PROG_CC([gcc icc pgcc xlc xlC pathcc cc])
8         PAC_POP_FLAG([CFLAGS])
9 ])
10 dnl
11 dnl/*D
12 dnl PAC_C_CHECK_COMPILER_OPTION - Check that a compiler option is accepted
13 dnl without warning messages
14 dnl
15 dnl Synopsis:
16 dnl PAC_C_CHECK_COMPILER_OPTION(optionname,action-if-ok,action-if-fail)
17 dnl
18 dnl Output Effects:
19 dnl
20 dnl If no actions are specified, a working value is added to 'COPTIONS'
21 dnl
22 dnl Notes:
23 dnl This is now careful to check that the output is different, since 
24 dnl some compilers are noisy.
25 dnl 
26 dnl We are extra careful to prototype the functions in case compiler options
27 dnl that complain about poor code are in effect.
28 dnl
29 dnl Because this is a long script, we have ensured that you can pass a 
30 dnl variable containing the option name as the first argument.
31 dnl
32 dnl D*/
33 AC_DEFUN([PAC_C_CHECK_COMPILER_OPTION],[
34 AC_MSG_CHECKING([whether C compiler accepts option $1])
35 pac_opt="$1"
36 AC_LANG_PUSH([C])
37 CFLAGS_orig="$CFLAGS"
38 CFLAGS_opt="$pac_opt $CFLAGS"
39 pac_result="unknown"
41 AC_LANG_CONFTEST([AC_LANG_PROGRAM()])
42 CFLAGS="$CFLAGS_orig"
43 rm -f pac_test1.log
44 PAC_LINK_IFELSE_LOG([pac_test1.log], [], [
45     CFLAGS="$CFLAGS_opt"
46     rm -f pac_test2.log
47     PAC_LINK_IFELSE_LOG([pac_test2.log], [], [
48         PAC_RUNLOG_IFELSE([diff -b pac_test1.log pac_test2.log],
49                           [pac_result=yes],[pac_result=no])
50     ],[
51         pac_result=no
52     ])
53 ], [
54     pac_result=no
56 AC_MSG_RESULT([$pac_result])
57 dnl Delete the conftest created by AC_LANG_CONFTEST.
58 rm -f conftest.$ac_ext
60 # gcc 4.2.4 on 32-bit does not complain about the -Wno-type-limits option 
61 # even though it doesn't support it.  However, when another warning is 
62 # triggered, it gives an error that the option is not recognized.  So we 
63 # need to test with a conftest file that will generate warnings.
64
65 # add an extra switch, pac_c_check_compiler_option_invalidprototest, to
66 # disable this test just in case some new compiler does not like it.
68 # Linking with a program with an invalid prototype to ensure a compiler warning.
70 if test "$pac_result" = "yes" \
71      -a "$pac_c_check_compiler_option_prototest" != "no" ; then
72     AC_MSG_CHECKING([whether C compiler option $1 works with an invalid prototype program])
73     AC_LINK_IFELSE([
74         AC_LANG_SOURCE([void main(){ return 0; }])
75     ],[pac_result=yes],[pac_result=no])
76     AC_MSG_RESULT([$pac_result])
79 if test "$pac_result" = "yes" ; then
80     AC_MSG_CHECKING([whether routines compiled with $pac_opt can be linked with ones compiled without $pac_opt])
81     pac_result=unknown
82     CFLAGS="$CFLAGS_orig"
83     rm -f pac_test3.log
84     PAC_COMPILE_IFELSE_LOG([pac_test3.log], [
85         AC_LANG_SOURCE([
86             int foo(void);
87             int foo(void){return 0;}
88         ])
89     ],[
90         PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT])
91         saved_LIBS="$LIBS"
92         LIBS="pac_conftest.$OBJEXT $LIBS"
94         rm -f pac_test4.log
95         PAC_LINK_IFELSE_LOG([pac_test4.log], [AC_LANG_PROGRAM()], [
96             CFLAGS="$CFLAGS_opt"
97             rm -f pac_test5.log
98             PAC_LINK_IFELSE_LOG([pac_test5.log], [AC_LANG_PROGRAM()], [
99                 PAC_RUNLOG_IFELSE([diff -b pac_test4.log pac_test5.log],
100                                   [pac_result=yes], [pac_result=no])
101             ],[
102                 pac_result=no
103             ])
104         ],[
105             pac_result=no
106         ])
107         LIBS="$saved_LIBS"
108         rm -f pac_conftest.$OBJEXT
109     ],[
110         pac_result=no
111     ])
112     AC_MSG_RESULT([$pac_result])
113     rm -f pac_test3.log pac_test4.log pac_test5.log
115 rm -f pac_test1.log pac_test2.log
117 dnl Restore CFLAGS before 2nd/3rd argument commands are executed,
118 dnl as 2nd/3rd argument command could be modifying CFLAGS.
119 CFLAGS="$CFLAGS_orig"
120 if test "$pac_result" = "yes" ; then
121      ifelse([$2],[],[COPTIONS="$COPTIONS $1"],[$2])
122 else
123      ifelse([$3],[],[:],[$3])
125 AC_LANG_POP([C])
128 dnl/*D
129 dnl PAC_C_OPTIMIZATION - Determine C options for producing optimized code
131 dnl Synopsis
132 dnl PAC_C_OPTIMIZATION([action if found])
134 dnl Output Effect:
135 dnl Adds options to 'COPTIONS' if no other action is specified
136 dnl 
137 dnl Notes:
138 dnl This is a temporary standin for compiler optimization.
139 dnl It should try to match known systems to known compilers (checking, of
140 dnl course), and then falling back to some common defaults.
141 dnl Note that many compilers will complain about -g and aggressive
142 dnl optimization.  
143 dnl D*/
144 AC_DEFUN([PAC_C_OPTIMIZATION],[
145     for copt in "-O4 -Ofast" "-Ofast" "-fast" "-O3" "-xO3" "-O" ; do
146         PAC_C_CHECK_COMPILER_OPTION($copt,found_opt=yes,found_opt=no)
147         if test "$found_opt" = "yes" ; then
148             ifelse($1,,COPTIONS="$COPTIONS $copt",$1)
149             break
150         fi
151     done
152     if test "$ac_cv_prog_gcc" = "yes" ; then
153         for copt in "-fomit-frame-pointer" "-finline-functions" \
154                  "-funroll-loops" ; do
155             PAC_C_CHECK_COMPILER_OPTION($copt,found_opt=yes,found_opt=no)
156             if test "$found_opt" = "yes" ; then
157                 ifelse($1,,COPTIONS="$COPTIONS $copt",$1)
158                 # no break because we're trying to add them all
159             fi
160         done
161         # We could also look for architecture-specific gcc options
162     fi
166 dnl/*D
167 dnl PAC_PROG_C_UNALIGNED_DOUBLES - Check that the C compiler allows unaligned
168 dnl doubles
170 dnl Synopsis:
171 dnl   PAC_PROG_C_UNALIGNED_DOUBLES(action-if-true,action-if-false,
172 dnl       action-if-unknown)
174 dnl Notes:
175 dnl 'action-if-unknown' is used in the case of cross-compilation.
176 dnl D*/
177 AC_DEFUN([PAC_PROG_C_UNALIGNED_DOUBLES],[
178 AC_CACHE_CHECK([whether C compiler allows unaligned doubles],
179 pac_cv_prog_c_unaligned_doubles,[
180 AC_TRY_RUN([
181 void fetch_double( v )
182 double *v;
184 *v = 1.0;
186 int main( argc, argv )
187 int argc;
188 char **argv;
190 int p[4];
191 double *p_val;
192 fetch_double( (double *)&(p[0]) );
193 p_val = (double *)&(p[0]);
194 if (*p_val != 1.0) return 1;
195 fetch_double( (double *)&(p[1]) );
196 p_val = (double *)&(p[1]);
197 if (*p_val != 1.0) return 1;
198 return 0;
200 ],pac_cv_prog_c_unaligned_doubles="yes",pac_cv_prog_c_unaligned_doubles="no",
201 pac_cv_prog_c_unaligned_doubles="unknown")])
202 ifelse($1,,,if test "X$pac_cv_prog_c_unaligned_doubles" = "yes" ; then 
205 ifelse($2,,,if test "X$pac_cv_prog_c_unaligned_doubles" = "no" ; then 
208 ifelse($3,,,if test "X$pac_cv_prog_c_unaligned_doubles" = "unknown" ; then 
213 dnl/*D 
214 dnl PAC_PROG_C_WEAK_SYMBOLS - Test whether C supports weak alias symbols.
216 dnl Synopsis
217 dnl PAC_PROG_C_WEAK_SYMBOLS(action-if-true,action-if-false)
219 dnl Output Effect:
220 dnl Defines one of the following if a weak symbol pragma is found:
221 dnl.vb
222 dnl    HAVE_PRAGMA_WEAK - #pragma weak
223 dnl    HAVE_PRAGMA_HP_SEC_DEF - #pragma _HP_SECONDARY_DEF
224 dnl    HAVE_PRAGMA_CRI_DUP  - #pragma _CRI duplicate x as y
225 dnl.ve
226 dnl May also define
227 dnl.vb
228 dnl    HAVE_WEAK_ATTRIBUTE
229 dnl.ve
230 dnl if functions can be declared as 'int foo(...) __attribute__ ((weak));'
231 dnl sets the shell variable pac_cv_attr_weak to yes.
232 dnl Also checks for __attribute__((weak_import)) which is supported by
233 dnl Apple in Mac OSX (at least in Darwin).  Note that this provides only
234 dnl weak symbols, not weak aliases
235 dnl 
236 dnl D*/
237 AC_DEFUN([PAC_PROG_C_WEAK_SYMBOLS],[
238 pragma_extra_message=""
239 AC_CACHE_CHECK([for type of weak symbol alias support],
240 pac_cv_prog_c_weak_symbols,[
241 # Test for weak symbol support...
242 # We can't put # in the message because it causes autoconf to generate
243 # incorrect code
244 AC_TRY_LINK([
245 extern int PFoo(int);
246 #pragma weak PFoo = Foo
247 int Foo(int a) { return a; }
248 ],[return PFoo(1);],has_pragma_weak=yes)
250 # Some systems (Linux ia64 and ecc, for example), support weak symbols
251 # only within a single object file!  This tests that case.
252 # Note that there is an extern int PFoo declaration before the
253 # pragma.  Some compilers require this in order to make the weak symbol
254 # extenally visible.  
255 if test "$has_pragma_weak" = yes ; then
256     PAC_COMPLINK_IFELSE([
257         AC_LANG_SOURCE([
258 extern int PFoo(int);
259 #pragma weak PFoo = Foo
260 int Foo(int);
261 int Foo(int a) { return a; }
262         ])
263     ],[
264         AC_LANG_SOURCE([
265 extern int PFoo(int);
266 int main(int argc, char **argv) {
267 return PFoo(0);}
268         ])
269     ],[
270         PAC_COMPLINK_IFELSE([
271             AC_LANG_SOURCE([
272 extern int PFoo(int);
273 #pragma weak PFoo = Foo
274 int Foo(int);
275 int Foo(int a) { return a; }
276             ])
277         ],[
278             AC_LANG_SOURCE([
279 extern int Foo(int);
280 int PFoo(int a) { return a+1;}
281 int main(int argc, char **argv) {
282 return Foo(0);}
283             ])
284         ],[
285             pac_cv_prog_c_weak_symbols="pragma weak"
286         ],[
287             has_pragma_weak=0
288             pragma_extra_message="pragma weak accepted but does not work (probably creates two non-weak entries)"
289         ])
290     ],[
291         has_pragma_weak=0
292         pragma_extra_message="pragma weak accepted but does not work (probably creates two non-weak entries)"
293     ])
296 if test -z "$pac_cv_prog_c_weak_symbols" ; then 
297     AC_TRY_LINK([
298 extern int PFoo(int);
299 #pragma _HP_SECONDARY_DEF Foo  PFoo
300 int Foo(int a) { return a; }
301 ],[return PFoo(1);],pac_cv_prog_c_weak_symbols="pragma _HP_SECONDARY_DEF")
304 if test -z "$pac_cv_prog_c_weak_symbols" ; then
305     AC_TRY_LINK([
306 extern int PFoo(int);
307 #pragma _CRI duplicate PFoo as Foo
308 int Foo(int a) { return a; }
309 ],[return PFoo(1);],pac_cv_prog_c_weak_symbols="pragma _CRI duplicate x as y")
312 if test -z "$pac_cv_prog_c_weak_symbols" ; then
313     pac_cv_prog_c_weak_symbols="no"
316 dnl If there is an extra explanatory message, echo it now so that it
317 dnl doesn't interfere with the cache result value
318 if test -n "$pragma_extra_message" ; then
319     echo $pragma_extra_message
323 if test "$pac_cv_prog_c_weak_symbols" = "no" ; then
324     ifelse([$2],,:,[$2])
325 else
326     case "$pac_cv_prog_c_weak_symbols" in
327         "pragma weak") AC_DEFINE(HAVE_PRAGMA_WEAK,1,[Supports weak pragma])
328         ;;
329         "pragma _HP")  AC_DEFINE(HAVE_PRAGMA_HP_SEC_DEF,1,[HP style weak pragma])
330         ;;
331         "pragma _CRI") AC_DEFINE(HAVE_PRAGMA_CRI_DUP,1,[Cray style weak pragma])
332         ;;
333     esac
334     ifelse([$1],,:,[$1])
336 AC_CACHE_CHECK([whether __attribute__ ((weak)) allowed],
337 pac_cv_attr_weak,[
338 AC_TRY_COMPILE([int foo(int) __attribute__ ((weak));],[int a;],
339 pac_cv_attr_weak=yes,pac_cv_attr_weak=no)])
340 # Note that being able to compile with weak_import doesn't mean that
341 # it works.
342 AC_CACHE_CHECK([whether __attribute__ ((weak_import)) allowed],
343 pac_cv_attr_weak_import,[
344 AC_TRY_COMPILE([int foo(int) __attribute__ ((weak_import));],[int a;],
345 pac_cv_attr_weak_import=yes,pac_cv_attr_weak_import=no)])
346 # Check if the alias option for weak attributes is allowed
347 AC_CACHE_CHECK([whether __attribute__((weak,alias(...))) allowed],
348 pac_cv_attr_weak_alias,[
349 AC_TRY_COMPILE([int foo(int) __attribute__((weak,alias("__foo")));],[int a;],
350 pac_cv_attr_weak_alias=yes,pac_cv_attr_weak_alias=no)])
354 # This is a replacement that checks that FAILURES are signaled as well
355 # (later configure macros look for the .o file, not just success from the
356 # compiler, but they should not HAVE to
358 dnl --- insert 2.52 compatibility here ---
359 dnl 2.52 does not have AC_PROG_CC_WORKS
360 ifdef([AC_PROG_CC_WORKS],,[AC_DEFUN([AC_PROG_CC_WORKS],)])
362 AC_DEFUN([PAC_PROG_CC_WORKS],
363 [AC_PROG_CC_WORKS
364 AC_MSG_CHECKING([whether the C compiler sets its return status correctly])
365 AC_LANG_SAVE
366 AC_LANG_C
367 AC_TRY_COMPILE(,[int a = bzzzt;],notbroken=no,notbroken=yes)
368 AC_MSG_RESULT($notbroken)
369 if test "$notbroken" = "no" ; then
370     AC_MSG_ERROR([installation or configuration problem: C compiler does not
371 correctly set error code when a fatal error occurs])
375 dnl/*D 
376 dnl PAC_PROG_C_MULTIPLE_WEAK_SYMBOLS - Test whether C and the
377 dnl linker allow multiple weak symbols.
379 dnl Synopsis
380 dnl PAC_PROG_C_MULTIPLE_WEAK_SYMBOLS(action-if-true,action-if-false)
382 dnl 
383 dnl D*/
384 AC_DEFUN([PAC_PROG_C_MULTIPLE_WEAK_SYMBOLS],[
385 AC_CACHE_CHECK([for multiple weak symbol support],
386 pac_cv_prog_c_multiple_weak_symbols,[
387 # Test for multiple weak symbol support...
388 PAC_COMPLINK_IFELSE([
389     AC_LANG_SOURCE([
390 extern int PFoo(int);
391 extern int PFoo_(int);
392 extern int pfoo_(int);
393 #pragma weak PFoo = Foo
394 #pragma weak PFoo_ = Foo
395 #pragma weak pfoo_ = Foo
396 int Foo(int);
397 int Foo(a) { return a; }
398     ])
400     AC_LANG_SOURCE([
401 extern int PFoo(int), PFoo_(int), pfoo_(int);
402 int main() {
403 return PFoo(0) + PFoo_(1) + pfoo_(2);}
404     ])
406     pac_cv_prog_c_multiple_weak_symbols="yes"
410 if test "$pac_cv_prog_c_multiple_weak_symbols" = "yes" ; then
411     ifelse([$1],,:,[$1])
412 else
413     ifelse([$2],,:,[$2])
417 dnl Use the value of enable-strict to update CFLAGS
418 dnl pac_cc_strict_flags contains the strict flags.
420 dnl -std=c89 is used to select the C89 version of the ANSI/ISO C standard.
421 dnl As of this writing, many C compilers still accepted only this version,
422 dnl not the later C99 version. When all compilers accept C99, this 
423 dnl should be changed to the appropriate standard level.  Note that we've
424 dnl had trouble with gcc 2.95.3 accepting -std=c89 but then trying to 
425 dnl compile program with a invalid set of options 
426 dnl (-D __STRICT_ANSI__-trigraphs)
427 AC_DEFUN([PAC_CC_STRICT],[
428 export enable_strict_done
429 if test "$enable_strict_done" != "yes" ; then
431     # Some comments on strict warning options.
432     # These were added to reduce warnings:
433     #   -Wno-missing-field-initializers  -- We want to allow a struct to be 
434     #       initialized to zero using "struct x y = {0};" and not require 
435     #       each field to be initialized individually.
436     #   -Wno-unused-parameter -- For portability, some parameters go unused
437     #       when we have different implementations of functions for 
438     #       different platforms
439     #   -Wno-unused-label -- We add fn_exit: and fn_fail: on all functions, 
440     #       but fn_fail may not be used if the function doesn't return an 
441     #       error.
442     #   -Wno-sign-compare -- read() and write() return bytes read/written
443     #       as a signed value, but we often compare this to size_t (or
444     #       msg_sz_t) variables.
445     #   -Wno-format-zero-length -- this warning is irritating and useless, since
446     #                              a zero-length format string is very well defined
447     #   -Wno-type-limits -- There are places where we compare an unsigned to 
448     #       a constant that happens to be zero e.g., if x is unsigned and 
449     #       MIN_VAL is zero, we'd like to do "MPIU_Assert(x >= MIN_VAL);".
450     #       Note this option is not supported by gcc 4.2.  This needs to be added 
451     #       after most other warning flags, so that we catch a gcc bug on 32-bit 
452     #       that doesn't give a warning that this is unsupported, unless another
453     #       warning is triggered, and then if gives an error.
454     # These were removed to reduce warnings:
455     #   -Wcast-qual -- Sometimes we need to cast "volatile char*" to 
456     #       "char*", e.g., for memcpy.
457     #   -Wpadded -- We catch struct padding with asserts when we need to
458     #   -Wredundant-decls -- Having redundant declarations is benign and the 
459     #       code already has some.
460     #   -Waggregate-return -- This seems to be a performance-related warning
461     #       aggregate return values are legal in ANSI C, but they may be returned
462     #       in memory rather than through a register.  We do use aggregate return
463     #       values, but they are structs of a single basic type (used to enforce
464     #       type checking for relative vs. absolute ptrs), and with optimization
465     #       the aggregate value is converted to a scalar.
466     #   -Wdeclaration-after-statement -- This is a C89
467     #       requirement. When compiling with C99, this should be
468     #       disabled.
469     # the embedded newlines in this string are safe because we evaluate each
470     # argument in the for-loop below and append them to the CFLAGS with a space
471     # as the separator instead
472     pac_common_strict_flags="
473         -Wall
474         -Wextra
475         -Wno-missing-field-initializers
476         -Wstrict-prototypes
477         -Wmissing-prototypes
478         -DGCC_WALL
479         -Wno-unused-parameter
480         -Wno-unused-label
481         -Wshadow
482         -Wmissing-declarations
483         -Wno-long-long
484         -Wfloat-equal
485         -Wundef
486         -Wno-endif-labels
487         -Wpointer-arith
488         -Wbad-function-cast
489         -Wcast-align
490         -Wwrite-strings
491         -Wno-sign-compare
492         -Wold-style-definition
493         -Wno-multichar
494         -Wno-deprecated-declarations
495         -Wpacked
496         -Wnested-externs
497         -Winvalid-pch
498         -Wno-pointer-sign
499         -Wvariadic-macros
500         -Wno-format-zero-length
501         -Wno-type-limits
502     "
504     enable_c89=yes
505     enable_c99=no
506     enable_posix=yes
507     enable_opt=yes
508     flags="`echo $1 | sed -e 's/:/ /g' -e 's/,/ /g'`"
509     for flag in ${flags}; do
510         case "$flag" in
511              c89)
512                 enable_strict_done="yes"
513                 enable_c89=yes
514                 ;;
515              c99)
516                 enable_strict_done="yes"
517                 enable_c99=yes
518                 ;;
519              posix)
520                 enable_strict_done="yes"
521                 enable_posix=yes
522                 ;;
523              noposix)
524                 enable_strict_done="yes"
525                 enable_posix=no
526                 ;;
527              opt)
528                 enable_strict_done="yes"
529                 enable_opt=yes
530                 ;;
531              noopt)
532                 enable_strict_done="yes"
533                 enable_opt=no
534                 ;;
535              all|yes)
536                 enable_strict_done="yes"
537                 enable_c89=yes
538                 enable_posix=yes
539                 enable_opt=yes
540                 ;;
541              no)
542                 # Accept and ignore this value
543                 :
544                 ;;
545              *)
546                 if test -n "$flag" ; then
547                    AC_MSG_WARN([Unrecognized value for enable-strict:$flag])
548                 fi
549                 ;;
550         esac
551     done
553     pac_cc_strict_flags=""
554     if test "${enable_strict_done}" = "yes" ; then
555        if test "${enable_opt}" = "yes" ; then
556           pac_cc_strict_flags="-O2"
557        fi
558        pac_cc_strict_flags="$pac_cc_strict_flags $pac_common_strict_flags"
559        if test "${enable_posix}" = "yes" ; then
560           PAC_APPEND_FLAG([-D_POSIX_C_SOURCE=199506L],[pac_cc_strict_flags])
561        fi
562        # We only allow one of strict-C99 or strict-C89 to be
563        # enabled. If C99 is enabled, we automatically disable C89.
564        if test "${enable_c99}" = "yes" ; then
565           PAC_APPEND_FLAG([-std=c99],[pac_cc_strict_flags])
566        elif test "${enable_c89}" = "yes" ; then
567           PAC_APPEND_FLAG([-std=c89],[pac_cc_strict_flags])
568           PAC_APPEND_FLAG([-Wdeclaration-after-statement],[pac_cc_strict_flags])
569        fi
570     fi
572     # See if the above options work with the compiler
573     accepted_flags=""
574     for flag in $pac_cc_strict_flags ; do
575         PAC_PUSH_FLAG([CFLAGS])
576         CFLAGS="$CFLAGS $accepted_flags"
577         PAC_C_CHECK_COMPILER_OPTION([$flag],[accepted_flags="$accepted_flags $flag"],)
578         PAC_POP_FLAG([CFLAGS])
579     done
580     pac_cc_strict_flags=$accepted_flags
584 dnl/*D
585 dnl PAC_ARG_STRICT - Add --enable-strict to configure.  
587 dnl Synopsis:
588 dnl PAC_ARG_STRICT
589 dnl 
590 dnl Output effects:
591 dnl Adds '--enable-strict' to the command line.
593 dnl D*/
594 AC_DEFUN([PAC_ARG_STRICT],[
595 AC_ARG_ENABLE(strict,
596         AC_HELP_STRING([--enable-strict], [Turn on strict compilation testing]))
597 PAC_CC_STRICT($enable_strict)
598 CFLAGS="$CFLAGS $pac_cc_strict_flags"
599 export CFLAGS
602 dnl Return the integer structure alignment in pac_cv_c_max_integer_align
603 dnl Possible values include
604 dnl     packed
605 dnl     two
606 dnl     four
607 dnl     eight
609 dnl In addition, a "Could not determine alignment" and a "error!"
610 dnl return is possible.  
611 AC_DEFUN([PAC_C_MAX_INTEGER_ALIGN],[
612 AC_CACHE_CHECK([for max C struct integer alignment],
613 pac_cv_c_max_integer_align,[
614 AC_TRY_RUN([
615 #include <stdio.h>
616 #define DBG(a,b,c)
617 int main( int argc, char *argv[] )
619     FILE *cf;
620     int is_packed  = 1;
621     int is_two     = 1;
622     int is_four    = 1;
623     int is_eight   = 1;
624     struct { char a; int b; } char_int;
625     struct { char a; short b; } char_short;
626     struct { char a; long b; } char_long;
627     struct { char a; int b; char c; } char_int_char;
628     struct { char a; short b; char c; } char_short_char;
629 #ifdef HAVE_LONG_LONG_INT
630     struct { long long int a; char b; } lli_c;
631     struct { char a; long long int b; } c_lli;
632 #endif
633     int size, extent, extent2;
635     /* assume max integer alignment isn't 8 if we don't have
636      * an eight-byte value :)
637      */
638 #ifdef HAVE_LONG_LONG_INT
639     if (sizeof(int) < 8 && sizeof(long) < 8 && sizeof(long long int) < 8)
640         is_eight = 0;
641 #else
642     if (sizeof(int) < 8 && sizeof(long) < 8) is_eight = 0;
643 #endif
645     size = sizeof(char) + sizeof(int);
646     extent = sizeof(char_int);
647     if (size != extent) is_packed = 0;
648     if ( (extent % 2) != 0) is_two = 0;
649     if ( (extent % 4) != 0) is_four = 0;
650     if (sizeof(int) == 8 && (extent % 8) != 0) is_eight = 0;
651     DBG("char_int",size,extent);
653     size = sizeof(char) + sizeof(short);
654     extent = sizeof(char_short);
655     if (size != extent) is_packed = 0;
656     if ( (extent % 2) != 0) is_two = 0;
657     if (sizeof(short) == 4 && (extent % 4) != 0) is_four = 0;
658     if (sizeof(short) == 8 && (extent % 8) != 0) is_eight = 0;
659     DBG("char_short",size,extent);
661     size = sizeof(char) + sizeof(long);
662     extent = sizeof(char_long);
663     if (size != extent) is_packed = 0;
664     if ( (extent % 2) != 0) is_two = 0;
665     if ( (extent % 4) != 0) is_four = 0;
666     if (sizeof(long) == 8 && (extent % 8) != 0) is_eight = 0;
667     DBG("char_long",size,extent);
669 #ifdef HAVE_LONG_LONG_INT
670     size = sizeof(char) + sizeof(long long int);
671     extent = sizeof(lli_c);
672     extent2 = sizeof(c_lli);
673     if (size != extent) is_packed = 0;
674     if ( (extent % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
675     if ( (extent % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
676     if (sizeof(long long int) >= 8 && (extent % 8) != 0 && (extent2 % 8) != 0)
677         is_eight = 0;
678 #endif
680     size = sizeof(char) + sizeof(int) + sizeof(char);
681     extent = sizeof(char_int_char);
682     if (size != extent) is_packed = 0;
683     if ( (extent % 2) != 0) is_two = 0;
684     if ( (extent % 4) != 0) is_four = 0;
685     if (sizeof(int) == 8 && (extent % 8) != 0) is_eight = 0;
686     DBG("char_int_char",size,extent);
688     size = sizeof(char) + sizeof(short) + sizeof(char);
689     extent = sizeof(char_short_char);
690     if (size != extent) is_packed = 0;
691     if ( (extent % 2) != 0) is_two = 0;
692     if (sizeof(short) == 4 && (extent % 4) != 0) is_four = 0;
693     if (sizeof(short) == 8 && (extent % 8) != 0) is_eight = 0;
694     DBG("char_short_char",size,extent);
696     /* If aligned mod 8, it will be aligned mod 4 */
697     if (is_eight) { is_four = 0; is_two = 0; }
699     if (is_four) is_two = 0;
701     /* Tabulate the results */
702     cf = fopen( "ctest.out", "w" );
703     if (is_packed + is_two + is_four + is_eight == 0) {
704         fprintf( cf, "Could not determine alignment\n" );
705     }
706     else {
707         if (is_packed + is_two + is_four + is_eight != 1) {
708             fprintf( cf, "error!\n" );
709         }
710         else {
711             if (is_packed) fprintf( cf, "packed\n" );
712             if (is_two) fprintf( cf, "two\n" );
713             if (is_four) fprintf( cf, "four\n" );
714             if (is_eight) fprintf( cf, "eight\n" );
715         }
716     }
717     fclose( cf );
718     return 0;
720 pac_cv_c_max_integer_align=`cat ctest.out`,
721 pac_cv_c_max_integer_align="unknown",
722 pac_cv_c_max_integer_align="$CROSS_ALIGN_STRUCT_INT")
723 rm -f ctest.out
725 if test -z "$pac_cv_c_max_integer_align" ; then
726     pac_cv_c_max_integer_align="unknown"
730 dnl Return the floating point structure alignment in
731 dnl pac_cv_c_max_fp_align.
733 dnl Possible values include:
734 dnl     packed
735 dnl     two
736 dnl     four
737 dnl     eight
738 dnl     sixteen
740 dnl In addition, a "Could not determine alignment" and a "error!"
741 dnl return is possible.  
742 AC_DEFUN([PAC_C_MAX_FP_ALIGN],[
743 AC_CACHE_CHECK([for max C struct floating point alignment],
744 pac_cv_c_max_fp_align,[
745 AC_TRY_RUN([
746 #include <stdio.h>
747 #define DBG(a,b,c)
748 int main( int argc, char *argv[] )
750     FILE *cf;
751     int is_packed  = 1;
752     int is_two     = 1;
753     int is_four    = 1;
754     int is_eight   = 1;
755     int is_sixteen = 1;
756     struct { char a; float b; } char_float;
757     struct { float b; char a; } float_char;
758     struct { char a; double b; } char_double;
759     struct { double b; char a; } double_char;
760 #ifdef HAVE_LONG_DOUBLE
761     struct { char a; long double b; } char_long_double;
762     struct { long double b; char a; } long_double_char;
763     struct { long double a; int b; char c; } long_double_int_char;
764 #endif
765     int size, extent1, extent2;
767     size = sizeof(char) + sizeof(float);
768     extent1 = sizeof(char_float);
769     extent2 = sizeof(float_char);
770     if (size != extent1) is_packed = 0;
771     if ( (extent1 % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
772     if ( (extent1 % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
773     if (sizeof(float) == 8 && (extent1 % 8) != 0 && (extent2 % 8) != 0)
774         is_eight = 0;
775     DBG("char_float",size,extent1);
777     size = sizeof(char) + sizeof(double);
778     extent1 = sizeof(char_double);
779     extent2 = sizeof(double_char);
780     if (size != extent1) is_packed = 0;
781     if ( (extent1 % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
782     if ( (extent1 % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
783     if (sizeof(double) == 8 && (extent1 % 8) != 0 && (extent2 % 8) != 0)
784         is_eight = 0;
785     DBG("char_double",size,extent1);
787 #ifdef HAVE_LONG_DOUBLE
788     size = sizeof(char) + sizeof(long double);
789     extent1 = sizeof(char_long_double);
790     extent2 = sizeof(long_double_char);
791     if (size != extent1) is_packed = 0;
792     if ( (extent1 % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
793     if ( (extent1 % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
794     if (sizeof(long double) >= 8 && (extent1 % 8) != 0 && (extent2 % 8) != 0)
795         is_eight = 0;
796     if (sizeof(long double) > 8 && (extent1 % 16) != 0
797         && (extent2 % 16) != 0) is_sixteen = 0;
798     DBG("char_long-double",size,extent1);
800     extent1 = sizeof(long_double_int_char);
801     if ( (extent1 % 2) != 0) is_two = 0;
802     if ( (extent1 % 4) != 0) is_four = 0;
803     if (sizeof(long double) >= 8 && (extent1 % 8) != 0) is_eight = 0;
804     if (sizeof(long double) > 8 && (extent1 % 16) != 0) is_sixteen = 0;
805 #else
806     is_sixteen = 0;
807 #endif
809     if (is_sixteen) { is_eight = 0; is_four = 0; is_two = 0; }
811     if (is_eight) { is_four = 0; is_two = 0; }
813     if (is_four) is_two = 0;
815     /* Tabulate the results */
816     cf = fopen( "ctest.out", "w" );
817     if (is_packed + is_two + is_four + is_eight + is_sixteen == 0) {
818         fprintf( cf, "Could not determine alignment\n" );
819     }
820     else {
821         if (is_packed + is_two + is_four + is_eight + is_sixteen != 1) {
822             fprintf( cf, "error!\n" );
823         }
824         else {
825             if (is_packed) fprintf( cf, "packed\n" );
826             if (is_two) fprintf( cf, "two\n" );
827             if (is_four) fprintf( cf, "four\n" );
828             if (is_eight) fprintf( cf, "eight\n" );
829             if (is_sixteen) fprintf( cf, "sixteen\n" );
830         }
831     }
832     fclose( cf );
833     return 0;
835 pac_cv_c_max_fp_align=`cat ctest.out`,
836 pac_cv_c_max_fp_align="unknown",
837 pac_cv_c_max_fp_align="$CROSS_ALIGN_STRUCT_FP")
838 rm -f ctest.out
840 if test -z "$pac_cv_c_max_fp_align" ; then
841     pac_cv_c_max_fp_align="unknown"
845 dnl Return the floating point structure alignment in
846 dnl pac_cv_c_max_double_fp_align.
848 dnl Possible values include:
849 dnl     packed
850 dnl     two
851 dnl     four
852 dnl     eight
854 dnl In addition, a "Could not determine alignment" and a "error!"
855 dnl return is possible.  
856 AC_DEFUN([PAC_C_MAX_DOUBLE_FP_ALIGN],[
857 AC_CACHE_CHECK([for max C struct alignment of structs with doubles],
858 pac_cv_c_max_double_fp_align,[
859 AC_TRY_RUN([
860 #include <stdio.h>
861 #define DBG(a,b,c)
862 int main( int argc, char *argv[] )
864     FILE *cf;
865     int is_packed  = 1;
866     int is_two     = 1;
867     int is_four    = 1;
868     int is_eight   = 1;
869     struct { char a; float b; } char_float;
870     struct { float b; char a; } float_char;
871     struct { char a; double b; } char_double;
872     struct { double b; char a; } double_char;
873     int size, extent1, extent2;
875     size = sizeof(char) + sizeof(float);
876     extent1 = sizeof(char_float);
877     extent2 = sizeof(float_char);
878     if (size != extent1) is_packed = 0;
879     if ( (extent1 % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
880     if ( (extent1 % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
881     if (sizeof(float) == 8 && (extent1 % 8) != 0 && (extent2 % 8) != 0)
882         is_eight = 0;
883     DBG("char_float",size,extent1);
885     size = sizeof(char) + sizeof(double);
886     extent1 = sizeof(char_double);
887     extent2 = sizeof(double_char);
888     if (size != extent1) is_packed = 0;
889     if ( (extent1 % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
890     if ( (extent1 % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
891     if (sizeof(double) == 8 && (extent1 % 8) != 0 && (extent2 % 8) != 0)
892         is_eight = 0;
893     DBG("char_double",size,extent1);
895     if (is_eight) { is_four = 0; is_two = 0; }
897     if (is_four) is_two = 0;
899     /* Tabulate the results */
900     cf = fopen( "ctest.out", "w" );
901     if (is_packed + is_two + is_four + is_eight == 0) {
902         fprintf( cf, "Could not determine alignment\n" );
903     }
904     else {
905         if (is_packed + is_two + is_four + is_eight != 1) {
906             fprintf( cf, "error!\n" );
907         }
908         else {
909             if (is_packed) fprintf( cf, "packed\n" );
910             if (is_two) fprintf( cf, "two\n" );
911             if (is_four) fprintf( cf, "four\n" );
912             if (is_eight) fprintf( cf, "eight\n" );
913         }
914     }
915     fclose( cf );
916     return 0;
918 pac_cv_c_max_double_fp_align=`cat ctest.out`,
919 pac_cv_c_max_double_fp_align="unknown",
920 pac_cv_c_max_double_fp_align="$CROSS_ALIGN_STRUCT_DOUBLE_FP")
921 rm -f ctest.out
923 if test -z "$pac_cv_c_max_double_fp_align" ; then
924     pac_cv_c_max_double_fp_align="unknown"
927 AC_DEFUN([PAC_C_MAX_LONGDOUBLE_FP_ALIGN],[
928 AC_CACHE_CHECK([for max C struct floating point alignment with long doubles],
929 pac_cv_c_max_longdouble_fp_align,[
930 AC_TRY_RUN([
931 #include <stdio.h>
932 #define DBG(a,b,c)
933 int main( int argc, char *argv[] )
935     FILE *cf;
936     int is_packed  = 1;
937     int is_two     = 1;
938     int is_four    = 1;
939     int is_eight   = 1;
940     int is_sixteen = 1;
941     struct { char a; long double b; } char_long_double;
942     struct { long double b; char a; } long_double_char;
943     struct { long double a; int b; char c; } long_double_int_char;
944     int size, extent1, extent2;
946     size = sizeof(char) + sizeof(long double);
947     extent1 = sizeof(char_long_double);
948     extent2 = sizeof(long_double_char);
949     if (size != extent1) is_packed = 0;
950     if ( (extent1 % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
951     if ( (extent1 % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
952     if (sizeof(long double) >= 8 && (extent1 % 8) != 0 && (extent2 % 8) != 0)
953         is_eight = 0;
954     if (sizeof(long double) > 8 && (extent1 % 16) != 0
955         && (extent2 % 16) != 0) is_sixteen = 0;
956     DBG("char_long-double",size,extent1);
958     extent1 = sizeof(long_double_int_char);
959     if ( (extent1 % 2) != 0) is_two = 0;
960     if ( (extent1 % 4) != 0) is_four = 0;
961     if (sizeof(long double) >= 8 && (extent1 % 8) != 0) is_eight = 0;
962     if (sizeof(long double) > 8 && (extent1 % 16) != 0) is_sixteen = 0;
964     if (is_sixteen) { is_eight = 0; is_four = 0; is_two = 0; }
966     if (is_eight) { is_four = 0; is_two = 0; }
968     if (is_four) is_two = 0;
970     /* Tabulate the results */
971     cf = fopen( "ctest.out", "w" );
972     if (is_packed + is_two + is_four + is_eight + is_sixteen == 0) {
973         fprintf( cf, "Could not determine alignment\n" );
974     }
975     else {
976         if (is_packed + is_two + is_four + is_eight + is_sixteen != 1) {
977             fprintf( cf, "error!\n" );
978         }
979         else {
980             if (is_packed) fprintf( cf, "packed\n" );
981             if (is_two) fprintf( cf, "two\n" );
982             if (is_four) fprintf( cf, "four\n" );
983             if (is_eight) fprintf( cf, "eight\n" );
984             if (is_sixteen) fprintf( cf, "sixteen\n" );
985         }
986     }
987     fclose( cf );
988     return 0;
990 pac_cv_c_max_longdouble_fp_align=`cat ctest.out`,
991 pac_cv_c_max_longdouble_fp_align="unknown",
992 pac_cv_c_max_longdouble_fp_align="$CROSS_ALIGN_STRUCT_LONGDOUBLE_FP")
993 rm -f ctest.out
995 if test -z "$pac_cv_c_max_longdouble_fp_align" ; then
996     pac_cv_c_max_longdouble_fp_align="unknown"
1000 dnl Other tests assume that there is potentially a maximum alignment
1001 dnl and that if there is no maximum alignment, or a type is smaller than
1002 dnl that value, then we align on the size of the value, with the exception
1003 dnl of the "position-based alignment" rules we test for separately.
1005 dnl It turns out that these assumptions have fallen short in at least one
1006 dnl case, on MacBook Pros, where doubles are aligned on 4-byte boundaries
1007 dnl even when long doubles are aligned on 16-byte boundaries. So this test
1008 dnl is here specifically to handle this case.
1010 dnl Puts result in pac_cv_c_double_alignment_exception.
1012 dnl Possible values currently include no and four.
1014 AC_DEFUN([PAC_C_DOUBLE_ALIGNMENT_EXCEPTION],[
1015 AC_CACHE_CHECK([if double alignment breaks rules, find actual alignment],
1016 pac_cv_c_double_alignment_exception,[
1017 AC_TRY_RUN([
1018 #include <stdio.h>
1019 #define DBG(a,b,c)
1020 int main( int argc, char *argv[] )
1022     FILE *cf;
1023     struct { char a; double b; } char_double;
1024     struct { double b; char a; } double_char;
1025     int extent1, extent2, align_4 = 0;
1027     extent1 = sizeof(char_double);
1028     extent2 = sizeof(double_char);
1030     /* we're interested in the largest value, will let separate test
1031      * deal with position-based issues.
1032      */
1033     if (extent1 < extent2) extent1 = extent2;
1034     if ((sizeof(double) == 8) && (extent1 % 8) != 0) {
1035        if (extent1 % 4 == 0) {
1036 #ifdef HAVE_MAX_FP_ALIGNMENT
1037           if (HAVE_MAX_FP_ALIGNMENT >= 8) align_4 = 1;
1038 #else
1039           align_4 = 1;
1040 #endif
1041        }
1042     }
1044     cf = fopen( "ctest.out", "w" );
1046     if (align_4) fprintf( cf, "four\n" );
1047     else fprintf( cf, "no\n" );
1049     fclose( cf );
1050     return 0;
1052 pac_cv_c_double_alignment_exception=`cat ctest.out`,
1053 pac_cv_c_double_alignment_exception="unknown",
1054 pac_cv_c_double_alignment_exception="$CROSS_ALIGN_DOUBLE_EXCEPTION")
1055 rm -f ctest.out
1057 if test -z "$pac_cv_c_double_alignment_exception" ; then
1058     pac_cv_c_double_alignment_exception="unknown"
1062 dnl Test for odd struct alignment rule that only applies max.
1063 dnl padding when double value is at front of type.
1064 dnl Puts result in pac_cv_c_double_pos_align.
1066 dnl Search for "Power alignment mode" for more details.
1068 dnl Possible values include yes, no, and unknown.
1070 AC_DEFUN([PAC_C_DOUBLE_POS_ALIGN],[
1071 AC_CACHE_CHECK([if alignment of structs with doubles is based on position],
1072 pac_cv_c_double_pos_align,[
1073 AC_TRY_RUN([
1074 #include <stdio.h>
1075 #define DBG(a,b,c)
1076 int main( int argc, char *argv[] )
1078     FILE *cf;
1079     int padding_varies_by_pos = 0;
1080     struct { char a; double b; } char_double;
1081     struct { double b; char a; } double_char;
1082     int extent1, extent2;
1084     extent1 = sizeof(char_double);
1085     extent2 = sizeof(double_char);
1086     if (extent1 != extent2) padding_varies_by_pos = 1;
1088     cf = fopen( "ctest.out", "w" );
1089     if (padding_varies_by_pos) fprintf( cf, "yes\n" );
1090     else fprintf( cf, "no\n" );
1092     fclose( cf );
1093     return 0;
1095 pac_cv_c_double_pos_align=`cat ctest.out`,
1096 pac_cv_c_double_pos_align="unknown",
1097 pac_cv_c_double_pos_align="$CROSS_ALIGN_DOUBLE_POS")
1098 rm -f ctest.out
1100 if test -z "$pac_cv_c_double_pos_align" ; then
1101     pac_cv_c_double_pos_align="unknown"
1105 dnl Test for odd struct alignment rule that only applies max.
1106 dnl padding when long long int value is at front of type.
1107 dnl Puts result in pac_cv_c_llint_pos_align.
1109 dnl Search for "Power alignment mode" for more details.
1111 dnl Possible values include yes, no, and unknown.
1113 AC_DEFUN([PAC_C_LLINT_POS_ALIGN],[
1114 AC_CACHE_CHECK([if alignment of structs with long long ints is based on position],
1115 pac_cv_c_llint_pos_align,[
1116 AC_TRY_RUN([
1117 #include <stdio.h>
1118 #define DBG(a,b,c)
1119 int main( int argc, char *argv[] )
1121     FILE *cf;
1122     int padding_varies_by_pos = 0;
1123 #ifdef HAVE_LONG_LONG_INT
1124     struct { char a; long long int b; } char_llint;
1125     struct { long long int b; char a; } llint_char;
1126     int extent1, extent2;
1128     extent1 = sizeof(char_llint);
1129     extent2 = sizeof(llint_char);
1130     if (extent1 != extent2) padding_varies_by_pos = 1;
1131 #endif
1133     cf = fopen( "ctest.out", "w" );
1134     if (padding_varies_by_pos) fprintf( cf, "yes\n" );
1135     else fprintf( cf, "no\n" );
1137     fclose( cf );
1138     return 0;
1140 pac_cv_c_llint_pos_align=`cat ctest.out`,
1141 pac_cv_c_llint_pos_align="unknown",
1142 pac_cv_c_llint_pos_align="$CROSS_ALIGN_LLINT_POS")
1143 rm -f ctest.out
1145 if test -z "$pac_cv_c_llint_pos_align" ; then
1146     pac_cv_c_llint_pos_align="unknown"
1150 dnl/*D
1151 dnl PAC_FUNC_NEEDS_DECL - Set NEEDS_<funcname>_DECL if a declaration is needed
1153 dnl Synopsis:
1154 dnl PAC_FUNC_NEEDS_DECL(headerfiles,funcname)
1156 dnl Output Effect:
1157 dnl Sets 'NEEDS_<funcname>_DECL' if 'funcname' is not declared by the 
1158 dnl headerfiles.
1160 dnl Approach:
1161 dnl Try to compile a program with the function, but passed with an incorrect
1162 dnl calling sequence.  If the compilation fails, then the declaration
1163 dnl is provided within the header files.  If the compilation succeeds,
1164 dnl the declaration is required.
1166 dnl We use a 'double' as the first argument to try and catch varargs
1167 dnl routines that may use an int or pointer as the first argument.
1169 dnl There is one difficulty - if the compiler has been instructed to
1170 dnl fail on implicitly defined functions, then this test will always
1171 dnl fail.
1172 dnl 
1173 dnl D*/
1174 AC_DEFUN([PAC_FUNC_NEEDS_DECL],[
1175 AC_CACHE_CHECK([whether $2 needs a declaration],
1176 pac_cv_func_decl_$2,[
1177 AC_TRY_COMPILE([$1
1178 int $2(double, int, double, const char *);],[int a=$2(1.0,27,1.0,"foo");],
1179 pac_cv_func_decl_$2=yes,pac_cv_func_decl_$2=no)])
1180 if test "$pac_cv_func_decl_$2" = "yes" ; then
1181 changequote(<<,>>)dnl
1182 define(<<PAC_FUNC_NAME>>, translit(NEEDS_$2_DECL, [a-z *], [A-Z__]))dnl
1183 changequote([, ])dnl
1184     AC_DEFINE_UNQUOTED(PAC_FUNC_NAME,1,[Define if $2 needs a declaration])
1185 undefine([PAC_FUNC_NAME])
1189 dnl PAC_C_GNU_ATTRIBUTE - See if the GCC __attribute__ specifier is allow.
1190 dnl Use the following
1191 dnl #ifndef HAVE_GCC_ATTRIBUTE
1192 dnl #define __attribute__(a)
1193 dnl #endif
1194 dnl If *not*, define __attribute__(a) as null
1196 dnl We start by requiring Gcc.  Some other compilers accept __attribute__
1197 dnl but generate warning messages, or have different interpretations 
1198 dnl (which seems to make __attribute__ just as bad as #pragma) 
1199 dnl For example, the Intel icc compiler accepts __attribute__ and
1200 dnl __attribute__((pure)) but generates warnings for __attribute__((format...))
1202 AC_DEFUN([PAC_C_GNU_ATTRIBUTE],[
1203 AC_REQUIRE([AC_PROG_CC_GNU])
1204 if test "$ac_cv_prog_gcc" = "yes" ; then
1205     AC_CACHE_CHECK([whether __attribute__ allowed],
1206 pac_cv_gnu_attr_pure,[
1207 AC_TRY_COMPILE([int foo(int) __attribute__ ((pure));],[int a;],
1208 pac_cv_gnu_attr_pure=yes,pac_cv_gnu_attr_pure=no)])
1209 AC_CACHE_CHECK([whether __attribute__((format)) allowed],
1210 pac_cv_gnu_attr_format,[
1211 AC_TRY_COMPILE([int foo(char *,...) __attribute__ ((format(printf,1,2)));],[int a;],
1212 pac_cv_gnu_attr_format=yes,pac_cv_gnu_attr_format=no)])
1213     if test "$pac_cv_gnu_attr_pure" = "yes" -a "$pac_cv_gnu_attr_format" = "yes" ; then
1214         AC_DEFINE(HAVE_GCC_ATTRIBUTE,1,[Define if GNU __attribute__ is supported])
1215     fi
1219 dnl Check for a broken install (fails to preserve file modification times,
1220 dnl thus breaking libraries.
1222 dnl Create a library, install it, and then try to link against it.
1223 AC_DEFUN([PAC_PROG_INSTALL_BREAKS_LIBS],[
1224 AC_CACHE_CHECK([whether install breaks libraries],
1225 ac_cv_prog_install_breaks_libs,[
1226 AC_REQUIRE([AC_PROG_RANLIB])
1227 AC_REQUIRE([AC_PROG_INSTALL])
1228 AC_REQUIRE([AC_PROG_CC])
1229 ac_cv_prog_install_breaks_libs=yes
1231 AC_COMPILE_IFELSE([
1232     AC_LANG_SOURCE([ int foo(int); int foo(int a){return a;} ])
1234     if ${AR-ar} ${AR_FLAGS-cr} libconftest.a conftest.$OBJEXT >/dev/null 2>&1 ; then
1235         if ${RANLIB-:} libconftest.a >/dev/null 2>&1 ; then
1236             # Anything less than sleep 10, and Mac OS/X (Darwin) 
1237             # will claim that install works because ranlib won't complain
1238             sleep 10
1239             libinstall="$INSTALL_DATA"
1240             eval "libinstall=\"$libinstall\""
1241             if ${libinstall} libconftest.a libconftest1.a >/dev/null 2>&1 ; then
1242                 saved_LIBS="$LIBS"
1243                 LIBS="libconftest1.a"
1244                 AC_LINK_IFELSE([
1245                     AC_LANG_SOURCE([
1246 extern int foo(int);
1247 int main(int argc, char **argv){ return foo(0); }
1248                     ])
1249                 ],[
1250                     # Success!  Install works
1251                     ac_cv_prog_install_breaks_libs=no
1252                 ],[
1253                     # Failure!  Does install -p work?        
1254                     rm -f libconftest1.a
1255                     if ${libinstall} -p libconftest.a libconftest1.a >/dev/null 2>&1 ; then
1256                         AC_LINK_IFELSE([],[
1257                             # Success!  Install works
1258                             ac_cv_prog_install_breaks_libs="no, with -p"
1259                         ])
1260                     fi
1261                 ])
1262                 LIBS="$saved_LIBS"
1263             fi
1264         fi
1265     fi
1267 rm -f libconftest*.a
1268 ]) dnl Endof ac_cache_check
1270 if test -z "$RANLIB_AFTER_INSTALL" ; then
1271     RANLIB_AFTER_INSTALL=no
1273 case "$ac_cv_prog_install_breaks_libs" in
1274     yes)
1275         RANLIB_AFTER_INSTALL=yes
1276     ;;
1277     "no, with -p")
1278         INSTALL_DATA="$INSTALL_DATA -p"
1279     ;;
1280     *)
1281     # Do nothing
1282     :
1283     ;;
1284 esac
1285 AC_SUBST(RANLIB_AFTER_INSTALL)
1289 # determine if the compiler defines a symbol containing the function name
1290 # Inspired by checks within the src/mpid/globus/configure.in file in MPICH2
1292 # These tests check not only that the compiler defines some symbol, such
1293 # as __FUNCTION__, but that the symbol correctly names the function.
1295 # Defines 
1296 #   HAVE__FUNC__      (if __func__ defined)
1297 #   HAVE_CAP__FUNC__  (if __FUNC__ defined)
1298 #   HAVE__FUNCTION__  (if __FUNCTION__ defined)
1300 AC_DEFUN([PAC_CC_FUNCTION_NAME_SYMBOL],[
1301 AC_CACHE_CHECK([whether the compiler defines __func__],
1302 pac_cv_have__func__,[
1303 tmp_am_cross=no
1304 AC_RUN_IFELSE([
1305 AC_LANG_SOURCE([
1306 #include <string.h>
1307 int foo(void);
1308 int foo(void)
1310     return (strcmp(__func__, "foo") == 0);
1312 int main(int argc, char ** argv)
1314     return (foo() ? 0 : 1);
1317 ], pac_cv_have__func__=yes, pac_cv_have__func__=no,tmp_am_cross=yes)
1318 if test "$tmp_am_cross" = yes ; then
1319     AC_LINK_IFELSE([
1320     AC_LANG_SOURCE([
1321 #include <string.h>
1322 int foo(void);
1323 int foo(void)
1325     return (strcmp(__func__, "foo") == 0);
1327 int main(int argc, char ** argv)
1329     return (foo() ? 0 : 1);
1331     ])
1332 ], pac_cv_have__func__=yes, pac_cv_have__func__=no)
1336 if test "$pac_cv_have__func__" = "yes" ; then
1337     AC_DEFINE(HAVE__FUNC__,,[define if the compiler defines __func__])
1340 AC_CACHE_CHECK([whether the compiler defines __FUNC__],
1341 pac_cv_have_cap__func__,[
1342 tmp_am_cross=no
1343 AC_RUN_IFELSE([
1344 AC_LANG_SOURCE([
1345 #include <string.h>
1346 int foo(void);
1347 int foo(void)
1349     return (strcmp(__FUNC__, "foo") == 0);
1351 int main(int argc, char ** argv)
1353     return (foo() ? 0 : 1);
1356 ], pac_cv_have_cap__func__=yes, pac_cv_have_cap__func__=no,tmp_am_cross=yes)
1357 if test "$tmp_am_cross" = yes ; then
1358     AC_LINK_IFELSE([
1359     AC_LANG_SOURCE([
1360 #include <string.h>
1361 int foo(void);
1362 int foo(void)
1364     return (strcmp(__FUNC__, "foo") == 0);
1366 int main(int argc, char ** argv)
1368     return (foo() ? 0 : 1);
1370     ])
1371 ], pac_cv_have__func__=yes, pac_cv_have__func__=no)
1375 if test "$pac_cv_have_cap__func__" = "yes" ; then
1376     AC_DEFINE(HAVE_CAP__FUNC__,,[define if the compiler defines __FUNC__])
1379 AC_CACHE_CHECK([whether the compiler sets __FUNCTION__],
1380 pac_cv_have__function__,[
1381 tmp_am_cross=no
1382 AC_RUN_IFELSE([
1383 AC_LANG_SOURCE([
1384 #include <string.h>
1385 int foo(void);
1386 int foo(void)
1388     return (strcmp(__FUNCTION__, "foo") == 0);
1390 int main(int argc, char ** argv)
1392     return (foo() ? 0 : 1);
1395 ], pac_cv_have__function__=yes, pac_cv_have__function__=no,tmp_am_cross=yes)
1396 if test "$tmp_am_cross" = yes ; then
1397     AC_LINK_IFELSE([
1398     AC_LANG_SOURCE([
1399 #include <string.h>
1400 int foo(void);
1401 int foo(void)
1403     return (strcmp(__FUNCTION__, "foo") == 0);
1405 int main(int argc, char ** argv)
1407     return (foo() ? 0 : 1);
1409     ])
1410 ], pac_cv_have__func__=yes, pac_cv_have__func__=no)
1414 if test "$pac_cv_have__function__" = "yes" ; then
1415     AC_DEFINE(HAVE__FUNCTION__,,[define if the compiler defines __FUNCTION__])
1421 dnl Check structure alignment
1422 AC_DEFUN([PAC_STRUCT_ALIGNMENT],[
1423         # Initialize alignment checks
1424         is_packed=1
1425         is_two=1
1426         is_four=1
1427         is_eight=1
1428         is_largest=1
1430         # See if long double exists
1431         AC_TRY_COMPILE(,[long double a;],have_long_double=yes,have_long_double=no)
1433         # Get sizes of regular types
1434         AC_CHECK_SIZEOF(char)
1435         AC_CHECK_SIZEOF(int)
1436         AC_CHECK_SIZEOF(short)
1437         AC_CHECK_SIZEOF(long)
1438         AC_CHECK_SIZEOF(float)
1439         AC_CHECK_SIZEOF(double)
1440         AC_CHECK_SIZEOF(long double)
1442         # char_int comparison
1443         AC_CHECK_SIZEOF(char_int, 0, [typedef struct { char a; int b; } char_int; ])
1444         size=`expr $ac_cv_sizeof_char + $ac_cv_sizeof_int`
1445         extent=$ac_cv_sizeof_char_int
1446         if test "$size" != "$extent" ; then is_packed=0 ; fi
1447         if test "`expr $extent % $ac_cv_sizeof_int`" != "0" ; then is_largest=0 ; fi
1448         if test "`expr $extent % 2`" != "0" ; then is_two=0 ; fi
1449         if test "`expr $extent % 4`" != "0" ; then is_four=0 ; fi
1450         if test "$ac_cv_sizeof_int" = "8" -a "`expr $extent % 8`" != "0" ; then
1451            is_eight=0
1452         fi
1454         # char_short comparison
1455         AC_CHECK_SIZEOF(char_short, 0, [typedef struct { char a; short b; } char_short; ])
1456         size=`expr $ac_cv_sizeof_char + $ac_cv_sizeof_short`
1457         extent=$ac_cv_sizeof_char_short
1458         if test "$size" != "$extent" ; then is_packed=0 ; fi
1459         if test "`expr $extent % $ac_cv_sizeof_short`" != "0" ; then is_largest=0 ; fi
1460         if test "`expr $extent % 2`" != "0" ; then is_two=0 ; fi
1461         if test "$ac_cv_sizeof_short" = "4" -a "`expr $extent % 4`" != "0" ; then
1462            is_four=0
1463         fi
1464         if test "$ac_cv_sizeof_short" = "8" -a "`expr $extent % 8`" != "0" ; then
1465            is_eight=0
1466         fi
1468         # char_long comparison
1469         AC_CHECK_SIZEOF(char_long, 0, [typedef struct { char a; long b; } char_long; ])
1470         size=`expr $ac_cv_sizeof_char + $ac_cv_sizeof_long`
1471         extent=$ac_cv_sizeof_char_long
1472         if test "$size" != "$extent" ; then is_packed=0 ; fi
1473         if test "`expr $extent % $ac_cv_sizeof_long`" != "0" ; then is_largest=0 ; fi
1474         if test "`expr $extent % 2`" != "0" ; then is_two=0 ; fi
1475         if test "`expr $extent % 4`" != "0" ; then is_four=0 ; fi
1476         if test "$ac_cv_sizeof_long" = "8" -a "`expr $extent % 8`" != "0" ; then
1477            is_eight=0
1478         fi
1480         # char_float comparison
1481         AC_CHECK_SIZEOF(char_float, 0, [typedef struct { char a; float b; } char_float; ])
1482         size=`expr $ac_cv_sizeof_char + $ac_cv_sizeof_float`
1483         extent=$ac_cv_sizeof_char_float
1484         if test "$size" != "$extent" ; then is_packed=0 ; fi
1485         if test "`expr $extent % $ac_cv_sizeof_float`" != "0" ; then is_largest=0 ; fi
1486         if test "`expr $extent % 2`" != "0" ; then is_two=0 ; fi
1487         if test "`expr $extent % 4`" != "0" ; then is_four=0 ; fi
1488         if test "$ac_cv_sizeof_float" = "8" -a "`expr $extent % 8`" != "0" ; then
1489            is_eight=0
1490         fi
1492         # char_double comparison
1493         AC_CHECK_SIZEOF(char_double, 0, [typedef struct { char a; double b; } char_double; ])
1494         size=`expr $ac_cv_sizeof_char + $ac_cv_sizeof_double`
1495         extent=$ac_cv_sizeof_char_double
1496         if test "$size" != "$extent" ; then is_packed=0 ; fi
1497         if test "`expr $extent % $ac_cv_sizeof_double`" != "0" ; then is_largest=0 ; fi
1498         if test "`expr $extent % 2`" != "0" ; then is_two=0 ; fi
1499         if test "`expr $extent % 4`" != "0" ; then is_four=0 ; fi
1500         if test "$ac_cv_sizeof_double" = "8" -a "`expr $extent % 8`" != "0" ; then
1501            is_eight=0
1502         fi
1504         # char_long_double comparison
1505         if test "$have_long_double" = "yes"; then
1506         AC_CHECK_SIZEOF(char_long_double, 0, [
1507                                        typedef struct {
1508                                                char a;
1509                                                long double b;
1510                                        } char_long_double;
1511                                        ])
1512         size=`expr $ac_cv_sizeof_char + $ac_cv_sizeof_long_double`
1513         extent=$ac_cv_sizeof_char_long_double
1514         if test "$size" != "$extent" ; then is_packed=0 ; fi
1515         if test "`expr $extent % $ac_cv_sizeof_long_double`" != "0" ; then is_largest=0 ; fi
1516         if test "`expr $extent % 2`" != "0" ; then is_two=0 ; fi
1517         if test "`expr $extent % 4`" != "0" ; then is_four=0 ; fi
1518         if test "$ac_cv_sizeof_long_double" = "8" -a "`expr $extent % 8`" != "0" ; then
1519            is_eight=0
1520         fi
1521         fi
1523         # char_int_char comparison
1524         AC_CHECK_SIZEOF(char_int_char, 0, [
1525                                        typedef struct {
1526                                                char a;
1527                                                int b;
1528                                                char c;
1529                                        } char_int_char;
1530                                        ])
1531         size=`expr $ac_cv_sizeof_char + $ac_cv_sizeof_int + $ac_cv_sizeof_char`
1532         extent=$ac_cv_sizeof_char_int_char
1533         if test "$size" != "$extent" ; then is_packed=0 ; fi
1534         if test "`expr $extent % $ac_cv_sizeof_int`" != "0" ; then is_largest=0 ; fi
1535         if test "`expr $extent % 2`" != "0" ; then is_two=0 ; fi
1536         if test "`expr $extent % 4`" != "0" ; then is_four=0 ; fi
1537         if test "$ac_cv_sizeof_int" = "8" -a "`expr $extent % 8`" != "0" ; then
1538            is_eight=0
1539         fi
1541         # char_short_char comparison
1542         AC_CHECK_SIZEOF(char_short_char, 0, [
1543                                        typedef struct {
1544                                                char a;
1545                                                short b;
1546                                                char c;
1547                                        } char_short_char;
1548                                        ])
1549         size=`expr $ac_cv_sizeof_char + $ac_cv_sizeof_short + $ac_cv_sizeof_char`
1550         extent=$ac_cv_sizeof_char_short_char
1551         if test "$size" != "$extent" ; then is_packed=0 ; fi
1552         if test "`expr $extent % $ac_cv_sizeof_short`" != "0" ; then is_largest=0 ; fi
1553         if test "`expr $extent % 2`" != "0" ; then is_two=0 ; fi
1554         if test "$ac_cv_sizeof_short" = "4" -a "`expr $extent % 4`" != "0" ; then
1555            is_four=0
1556         fi
1557         if test "$ac_cv_sizeof_short" = "8" -a "`expr $extent % 8`" != "0" ; then
1558            is_eight=0
1559         fi
1561         # If aligned mod 8, it will be aligned mod 4
1562         if test $is_eight = 1 ; then is_four=0 ; is_two=0 ; fi
1563         if test $is_four = 1 ; then is_two=0 ; fi
1565         # Largest supersedes 8
1566         if test $is_largest = 1 ; then is_eight=0 ; fi
1568         # Find the alignment
1569         if test "`expr $is_packed + $is_largest + $is_two + $is_four + $is_eight`" = "0" ; then
1570            pac_cv_struct_alignment="unknown"
1571         elif test "`expr $is_packed + $is_largest + $is_two + $is_four + $is_eight`" != "1" ; then
1572            pac_cv_struct_alignment="unknown"
1573         elif test $is_packed = 1 ; then
1574            pac_cv_struct_alignment="packed"
1575         elif test $is_largest = 1 ; then
1576            pac_cv_struct_alignment="largest"
1577         elif test $is_two = 1 ; then
1578            pac_cv_struct_alignment="two"
1579         elif test $is_four = 1 ; then
1580            pac_cv_struct_alignment="four"
1581         elif test $is_eight = 1 ; then
1582            pac_cv_struct_alignment="eight"
1583         fi
1586 dnl PAC_C_MACRO_VA_ARGS
1588 dnl will AC_DEFINE([HAVE_MACRO_VA_ARGS]) if the compiler supports C99 variable
1589 dnl length argument lists in macros (#define foo(...) bar(__VA_ARGS__))
1590 AC_DEFUN([PAC_C_MACRO_VA_ARGS],[
1591     AC_MSG_CHECKING([for variable argument list macro functionality])
1592     AC_LINK_IFELSE([AC_LANG_PROGRAM([
1593         #include <stdio.h>
1594         #define conftest_va_arg_macro(...) printf(__VA_ARGS__)
1595     ],
1596     [conftest_va_arg_macro("a test %d", 3);])],
1597     [AC_DEFINE([HAVE_MACRO_VA_ARGS],[1],[Define if C99-style variable argument list macro functionality])
1598      AC_MSG_RESULT([yes])],
1599     [AC_MSG_RESULT([no])])
1600 ])dnl