1dnl AC_PROG_CC_GNU
2ifdef([AC_PROG_CC_GNU],,[AC_DEFUN([AC_PROG_CC_GNU],)])
3
4dnl PAC_PROG_CC - reprioritize the C compiler search order
5AC_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])
10dnl
11dnl/*D
12dnl PAC_C_CHECK_COMPILER_OPTION - Check that a compiler option is accepted
13dnl without warning messages
14dnl
15dnl Synopsis:
16dnl PAC_C_CHECK_COMPILER_OPTION(optionname,action-if-ok,action-if-fail)
17dnl
18dnl Output Effects:
19dnl
20dnl If no actions are specified, a working value is added to 'COPTIONS'
21dnl
22dnl Notes:
23dnl This is now careful to check that the output is different, since
24dnl some compilers are noisy.
25dnl
26dnl We are extra careful to prototype the functions in case compiler options
27dnl that complain about poor code are in effect.
28dnl
29dnl Because this is a long script, we have ensured that you can pass a
30dnl variable containing the option name as the first argument.
31dnl
32dnl D*/
33AC_DEFUN([PAC_C_CHECK_COMPILER_OPTION],[
34AC_MSG_CHECKING([whether C compiler accepts option $1])
35pac_opt="$1"
36AC_LANG_PUSH([C])
37CFLAGS_orig="$CFLAGS"
38CFLAGS_opt="$pac_opt $CFLAGS"
39pac_result="unknown"
40
41AC_LANG_CONFTEST([AC_LANG_PROGRAM()])
42CFLAGS="$CFLAGS_orig"
43rm -f pac_test1.log
44PAC_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
55])
56AC_MSG_RESULT([$pac_result])
57dnl Delete the conftest created by AC_LANG_CONFTEST.
58rm -f conftest.$ac_ext
59
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_prototest, to
66# disable this test just in case some new compiler does not like it.
67#
68# Linking with a program with an invalid prototype to ensure a compiler warning.
69
70if 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])
77fi
78#
79if 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"
93
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
114fi
115rm -f pac_test1.log pac_test2.log
116
117dnl Restore CFLAGS before 2nd/3rd argument commands are executed,
118dnl as 2nd/3rd argument command could be modifying CFLAGS.
119CFLAGS="$CFLAGS_orig"
120if test "$pac_result" = "yes" ; then
121     ifelse([$2],[],[COPTIONS="$COPTIONS $1"],[$2])
122else
123     ifelse([$3],[],[:],[$3])
124fi
125AC_LANG_POP([C])
126])
127dnl
128dnl/*D
129dnl PAC_C_OPTIMIZATION - Determine C options for producing optimized code
130dnl
131dnl Synopsis
132dnl PAC_C_OPTIMIZATION([action if found])
133dnl
134dnl Output Effect:
135dnl Adds options to 'COPTIONS' if no other action is specified
136dnl
137dnl Notes:
138dnl This is a temporary standin for compiler optimization.
139dnl It should try to match known systems to known compilers (checking, of
140dnl course), and then falling back to some common defaults.
141dnl Note that many compilers will complain about -g and aggressive
142dnl optimization.
143dnl D*/
144AC_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
163
164])
165
166dnl/*D
167dnl PAC_PROG_C_UNALIGNED_DOUBLES - Check that the C compiler allows unaligned
168dnl doubles
169dnl
170dnl Synopsis:
171dnl   PAC_PROG_C_UNALIGNED_DOUBLES(action-if-true,action-if-false,
172dnl       action-if-unknown)
173dnl
174dnl Notes:
175dnl 'action-if-unknown' is used in the case of cross-compilation.
176dnl D*/
177AC_DEFUN([PAC_PROG_C_UNALIGNED_DOUBLES],[
178AC_CACHE_CHECK([whether C compiler allows unaligned doubles],
179pac_cv_prog_c_unaligned_doubles,[
180AC_TRY_RUN([
181void fetch_double( v )
182double *v;
183{
184*v = 1.0;
185}
186int main( argc, argv )
187int argc;
188char **argv;
189{
190int p[4];
191double *p_val;
192fetch_double( (double *)&(p[0]) );
193p_val = (double *)&(p[0]);
194if (*p_val != 1.0) return 1;
195fetch_double( (double *)&(p[1]) );
196p_val = (double *)&(p[1]);
197if (*p_val != 1.0) return 1;
198return 0;
199}
200],pac_cv_prog_c_unaligned_doubles="yes",pac_cv_prog_c_unaligned_doubles="no",
201pac_cv_prog_c_unaligned_doubles="unknown")])
202ifelse($1,,,if test "X$pac_cv_prog_c_unaligned_doubles" = "yes" ; then
203$1
204fi)
205ifelse($2,,,if test "X$pac_cv_prog_c_unaligned_doubles" = "no" ; then
206$2
207fi)
208ifelse($3,,,if test "X$pac_cv_prog_c_unaligned_doubles" = "unknown" ; then
209$3
210fi)
211])
212
213dnl/*D
214dnl PAC_PROG_C_WEAK_SYMBOLS - Test whether C supports weak alias symbols.
215dnl
216dnl Synopsis
217dnl PAC_PROG_C_WEAK_SYMBOLS(action-if-true,action-if-false)
218dnl
219dnl Output Effect:
220dnl Defines one of the following if a weak symbol pragma is found:
221dnl.vb
222dnl    HAVE_PRAGMA_WEAK - #pragma weak
223dnl    HAVE_PRAGMA_HP_SEC_DEF - #pragma _HP_SECONDARY_DEF
224dnl    HAVE_PRAGMA_CRI_DUP  - #pragma _CRI duplicate x as y
225dnl.ve
226dnl May also define
227dnl.vb
228dnl    HAVE_WEAK_ATTRIBUTE
229dnl.ve
230dnl if functions can be declared as 'int foo(...) __attribute__ ((weak));'
231dnl sets the shell variable pac_cv_attr_weak to yes.
232dnl Also checks for __attribute__((weak_import)) which is supported by
233dnl Apple in Mac OSX (at least in Darwin).  Note that this provides only
234dnl weak symbols, not weak aliases
235dnl
236dnl D*/
237AC_DEFUN([PAC_PROG_C_WEAK_SYMBOLS],[
238pragma_extra_message=""
239AC_CACHE_CHECK([for type of weak symbol alias support],
240pac_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
244AC_TRY_LINK([
245extern int PFoo(int);
246#pragma weak PFoo = Foo
247int Foo(int a) { return a; }
248],[return PFoo(1);],has_pragma_weak=yes)
249#
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.
255if test "$has_pragma_weak" = yes ; then
256    PAC_COMPLINK_IFELSE([
257        AC_LANG_SOURCE([
258extern int PFoo(int);
259#pragma weak PFoo = Foo
260int Foo(int);
261int Foo(int a) { return a; }
262        ])
263    ],[
264        AC_LANG_SOURCE([
265extern int PFoo(int);
266int main(int argc, char **argv) {
267return PFoo(0);}
268        ])
269    ],[
270        PAC_COMPLINK_IFELSE([
271            AC_LANG_SOURCE([
272extern int PFoo(int);
273#pragma weak PFoo = Foo
274int Foo(int);
275int Foo(int a) { return a; }
276            ])
277        ],[
278            AC_LANG_SOURCE([
279extern int Foo(int);
280int PFoo(int a) { return a+1;}
281int main(int argc, char **argv) {
282return 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    ])
294fi
295dnl
296if test -z "$pac_cv_prog_c_weak_symbols" ; then
297    AC_TRY_LINK([
298extern int PFoo(int);
299#pragma _HP_SECONDARY_DEF Foo  PFoo
300int Foo(int a) { return a; }
301],[return PFoo(1);],pac_cv_prog_c_weak_symbols="pragma _HP_SECONDARY_DEF")
302fi
303dnl
304if test -z "$pac_cv_prog_c_weak_symbols" ; then
305    AC_TRY_LINK([
306extern int PFoo(int);
307#pragma _CRI duplicate PFoo as Foo
308int Foo(int a) { return a; }
309],[return PFoo(1);],pac_cv_prog_c_weak_symbols="pragma _CRI duplicate x as y")
310fi
311dnl
312if test -z "$pac_cv_prog_c_weak_symbols" ; then
313    pac_cv_prog_c_weak_symbols="no"
314fi
315dnl
316dnl If there is an extra explanatory message, echo it now so that it
317dnl doesn't interfere with the cache result value
318if test -n "$pragma_extra_message" ; then
319    echo $pragma_extra_message
320fi
321dnl
322])
323if test "$pac_cv_prog_c_weak_symbols" = "no" ; then
324    ifelse([$2],,:,[$2])
325else
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])
335fi
336AC_CACHE_CHECK([whether __attribute__ ((weak)) allowed],
337pac_cv_attr_weak,[
338AC_TRY_COMPILE([int foo(int) __attribute__ ((weak));],[int a;],
339pac_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.
342AC_CACHE_CHECK([whether __attribute__ ((weak_import)) allowed],
343pac_cv_attr_weak_import,[
344AC_TRY_COMPILE([int foo(int) __attribute__ ((weak_import));],[int a;],
345pac_cv_attr_weak_import=yes,pac_cv_attr_weak_import=no)])
346# Check if the alias option for weak attributes is allowed
347AC_CACHE_CHECK([whether __attribute__((weak,alias(...))) allowed],
348pac_cv_attr_weak_alias,[
349AC_TRY_COMPILE([int foo(int) __attribute__((weak,alias("__foo")));],[int a;],
350pac_cv_attr_weak_alias=yes,pac_cv_attr_weak_alias=no)])
351])
352
353#
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
357#
358dnl --- insert 2.52 compatibility here ---
359dnl 2.52 does not have AC_PROG_CC_WORKS
360ifdef([AC_PROG_CC_WORKS],,[AC_DEFUN([AC_PROG_CC_WORKS],)])
361dnl
362AC_DEFUN([PAC_PROG_CC_WORKS],
363[AC_PROG_CC_WORKS
364AC_MSG_CHECKING([whether the C compiler sets its return status correctly])
365AC_LANG_SAVE
366AC_LANG_C
367AC_TRY_COMPILE(,[int a = bzzzt;],notbroken=no,notbroken=yes)
368AC_MSG_RESULT($notbroken)
369if test "$notbroken" = "no" ; then
370    AC_MSG_ERROR([installation or configuration problem: C compiler does not
371correctly set error code when a fatal error occurs])
372fi
373])
374
375dnl/*D
376dnl PAC_PROG_C_MULTIPLE_WEAK_SYMBOLS - Test whether C and the
377dnl linker allow multiple weak symbols.
378dnl
379dnl Synopsis
380dnl PAC_PROG_C_MULTIPLE_WEAK_SYMBOLS(action-if-true,action-if-false)
381dnl
382dnl
383dnl D*/
384AC_DEFUN([PAC_PROG_C_MULTIPLE_WEAK_SYMBOLS],[
385AC_CACHE_CHECK([for multiple weak symbol support],
386pac_cv_prog_c_multiple_weak_symbols,[
387# Test for multiple weak symbol support...
388PAC_COMPLINK_IFELSE([
389    AC_LANG_SOURCE([
390extern int PFoo(int);
391extern int PFoo_(int);
392extern int pfoo_(int);
393#pragma weak PFoo = Foo
394#pragma weak PFoo_ = Foo
395#pragma weak pfoo_ = Foo
396int Foo(int);
397int Foo(a) { return a; }
398    ])
399],[
400    AC_LANG_SOURCE([
401extern int PFoo(int), PFoo_(int), pfoo_(int);
402int main() {
403return PFoo(0) + PFoo_(1) + pfoo_(2);}
404    ])
405],[
406    pac_cv_prog_c_multiple_weak_symbols="yes"
407])
408dnl
409])
410if test "$pac_cv_prog_c_multiple_weak_symbols" = "yes" ; then
411    ifelse([$1],,:,[$1])
412else
413    ifelse([$2],,:,[$2])
414fi
415])
416
417dnl Use the value of enable-strict to update CFLAGS
418dnl pac_cc_strict_flags contains the strict flags.
419dnl
420dnl -std=c89 is used to select the C89 version of the ANSI/ISO C standard.
421dnl As of this writing, many C compilers still accepted only this version,
422dnl not the later C99 version. When all compilers accept C99, this
423dnl should be changed to the appropriate standard level.  Note that we've
424dnl had trouble with gcc 2.95.3 accepting -std=c89 but then trying to
425dnl compile program with a invalid set of options
426dnl (-D __STRICT_ANSI__-trigraphs)
427AC_DEFUN([PAC_CC_STRICT],[
428export enable_strict_done
429if test "$enable_strict_done" != "yes" ; then
430
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    #   -Wfloat-equal -- There are places in hwloc that set a float var to 0, then
470    #       compare it to 0 later to see if it was updated.  Also when using strtod()
471    #       one needs to compare the return value with 0 to see whether a conversion
472    #       was performed.
473    # the embedded newlines in this string are safe because we evaluate each
474    # argument in the for-loop below and append them to the CFLAGS with a space
475    # as the separator instead
476    pac_common_strict_flags="
477        -Wall
478        -Wextra
479        -Wno-missing-field-initializers
480        -Wstrict-prototypes
481        -Wmissing-prototypes
482        -DGCC_WALL
483        -Wno-unused-parameter
484        -Wno-unused-label
485        -Wshadow
486        -Wmissing-declarations
487        -Wno-long-long
488        -Wundef
489        -Wno-endif-labels
490        -Wpointer-arith
491        -Wbad-function-cast
492        -Wcast-align
493        -Wwrite-strings
494        -Wno-sign-compare
495        -Wold-style-definition
496        -Wno-multichar
497        -Wno-deprecated-declarations
498        -Wpacked
499        -Wnested-externs
500        -Winvalid-pch
501        -Wno-pointer-sign
502        -Wvariadic-macros
503        -Wno-format-zero-length
504	-Wno-type-limits
505    "
506
507    enable_c89=yes
508    enable_c99=no
509    enable_posix=2001
510    enable_opt=yes
511    flags="`echo $1 | sed -e 's/:/ /g' -e 's/,/ /g'`"
512    for flag in ${flags}; do
513        case "$flag" in
514	     c89)
515		enable_strict_done="yes"
516		enable_c89=yes
517		;;
518	     c99)
519		enable_strict_done="yes"
520		enable_c99=yes
521		;;
522	     posix1995)
523		enable_strict_done="yes"
524		enable_posix=1995
525		;;
526	     posix|posix2001)
527		enable_strict_done="yes"
528		enable_posix=2001
529		;;
530	     posix2008)
531		enable_strict_done="yes"
532		enable_posix=2008
533		;;
534	     noposix)
535		enable_strict_done="yes"
536		enable_posix=no
537		;;
538	     opt)
539		enable_strict_done="yes"
540		enable_opt=yes
541		;;
542	     noopt)
543		enable_strict_done="yes"
544		enable_opt=no
545		;;
546	     all|yes)
547		enable_strict_done="yes"
548		enable_c89=yes
549		enable_posix=2001
550		enable_opt=yes
551	        ;;
552	     no)
553		# Accept and ignore this value
554		:
555		;;
556	     *)
557		if test -n "$flag" ; then
558		   AC_MSG_WARN([Unrecognized value for enable-strict:$flag])
559		fi
560		;;
561	esac
562    done
563
564    pac_cc_strict_flags=""
565    if test "${enable_strict_done}" = "yes" ; then
566       if test "${enable_opt}" = "yes" ; then
567       	  pac_cc_strict_flags="-O2"
568       fi
569       pac_cc_strict_flags="$pac_cc_strict_flags $pac_common_strict_flags"
570       case "$enable_posix" in
571            no)   : ;;
572            1995) PAC_APPEND_FLAG([-D_POSIX_C_SOURCE=199506L],[pac_cc_strict_flags]) ;;
573            2001) PAC_APPEND_FLAG([-D_POSIX_C_SOURCE=200112L],[pac_cc_strict_flags]) ;;
574            2008) PAC_APPEND_FLAG([-D_POSIX_C_SOURCE=200809L],[pac_cc_strict_flags]) ;;
575            *)    AC_MSG_ERROR([internal error, unexpected POSIX version: '$enable_posix']) ;;
576       esac
577       # We only allow one of strict-C99 or strict-C89 to be
578       # enabled. If C99 is enabled, we automatically disable C89.
579       if test "${enable_c99}" = "yes" ; then
580       	  PAC_APPEND_FLAG([-std=c99],[pac_cc_strict_flags])
581       elif test "${enable_c89}" = "yes" ; then
582       	  PAC_APPEND_FLAG([-std=c89],[pac_cc_strict_flags])
583       	  PAC_APPEND_FLAG([-Wdeclaration-after-statement],[pac_cc_strict_flags])
584       fi
585    fi
586
587    # See if the above options work with the compiler
588    accepted_flags=""
589    for flag in $pac_cc_strict_flags ; do
590        PAC_PUSH_FLAG([CFLAGS])
591	CFLAGS="$CFLAGS $accepted_flags"
592        PAC_C_CHECK_COMPILER_OPTION([$flag],[accepted_flags="$accepted_flags $flag"],)
593        PAC_POP_FLAG([CFLAGS])
594    done
595    pac_cc_strict_flags=$accepted_flags
596fi
597])
598
599dnl/*D
600dnl PAC_ARG_STRICT - Add --enable-strict to configure.
601dnl
602dnl Synopsis:
603dnl PAC_ARG_STRICT
604dnl
605dnl Output effects:
606dnl Adds '--enable-strict' to the command line.
607dnl
608dnl D*/
609AC_DEFUN([PAC_ARG_STRICT],[
610AC_ARG_ENABLE(strict,
611	AC_HELP_STRING([--enable-strict], [Turn on strict compilation testing]))
612PAC_CC_STRICT($enable_strict)
613CFLAGS="$CFLAGS $pac_cc_strict_flags"
614export CFLAGS
615])
616
617dnl Return the integer structure alignment in pac_cv_c_max_integer_align
618dnl Possible values include
619dnl	packed
620dnl	two
621dnl	four
622dnl	eight
623dnl
624dnl In addition, a "Could not determine alignment" and a "error!"
625dnl return is possible.
626AC_DEFUN([PAC_C_MAX_INTEGER_ALIGN],[
627AC_CACHE_CHECK([for max C struct integer alignment],
628pac_cv_c_max_integer_align,[
629AC_TRY_RUN([
630#include <stdio.h>
631#define DBG(a,b,c)
632int main( int argc, char *argv[] )
633{
634    FILE *cf;
635    int is_packed  = 1;
636    int is_two     = 1;
637    int is_four    = 1;
638    int is_eight   = 1;
639    struct { char a; int b; } char_int;
640    struct { char a; short b; } char_short;
641    struct { char a; long b; } char_long;
642    struct { char a; int b; char c; } char_int_char;
643    struct { char a; short b; char c; } char_short_char;
644#ifdef HAVE_LONG_LONG_INT
645    struct { long long int a; char b; } lli_c;
646    struct { char a; long long int b; } c_lli;
647#endif
648    int size, extent, extent2;
649
650    /* assume max integer alignment isn't 8 if we don't have
651     * an eight-byte value :)
652     */
653#ifdef HAVE_LONG_LONG_INT
654    if (sizeof(int) < 8 && sizeof(long) < 8 && sizeof(long long int) < 8)
655	is_eight = 0;
656#else
657    if (sizeof(int) < 8 && sizeof(long) < 8) is_eight = 0;
658#endif
659
660    size = sizeof(char) + sizeof(int);
661    extent = sizeof(char_int);
662    if (size != extent) is_packed = 0;
663    if ( (extent % 2) != 0) is_two = 0;
664    if ( (extent % 4) != 0) is_four = 0;
665    if (sizeof(int) == 8 && (extent % 8) != 0) is_eight = 0;
666    DBG("char_int",size,extent);
667
668    size = sizeof(char) + sizeof(short);
669    extent = sizeof(char_short);
670    if (size != extent) is_packed = 0;
671    if ( (extent % 2) != 0) is_two = 0;
672    if (sizeof(short) == 4 && (extent % 4) != 0) is_four = 0;
673    if (sizeof(short) == 8 && (extent % 8) != 0) is_eight = 0;
674    DBG("char_short",size,extent);
675
676    size = sizeof(char) + sizeof(long);
677    extent = sizeof(char_long);
678    if (size != extent) is_packed = 0;
679    if ( (extent % 2) != 0) is_two = 0;
680    if ( (extent % 4) != 0) is_four = 0;
681    if (sizeof(long) == 8 && (extent % 8) != 0) is_eight = 0;
682    DBG("char_long",size,extent);
683
684#ifdef HAVE_LONG_LONG_INT
685    size = sizeof(char) + sizeof(long long int);
686    extent = sizeof(lli_c);
687    extent2 = sizeof(c_lli);
688    if (size != extent) is_packed = 0;
689    if ( (extent % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
690    if ( (extent % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
691    if (sizeof(long long int) >= 8 && (extent % 8) != 0 && (extent2 % 8) != 0)
692	is_eight = 0;
693#endif
694
695    size = sizeof(char) + sizeof(int) + sizeof(char);
696    extent = sizeof(char_int_char);
697    if (size != extent) is_packed = 0;
698    if ( (extent % 2) != 0) is_two = 0;
699    if ( (extent % 4) != 0) is_four = 0;
700    if (sizeof(int) == 8 && (extent % 8) != 0) is_eight = 0;
701    DBG("char_int_char",size,extent);
702
703    size = sizeof(char) + sizeof(short) + sizeof(char);
704    extent = sizeof(char_short_char);
705    if (size != extent) is_packed = 0;
706    if ( (extent % 2) != 0) is_two = 0;
707    if (sizeof(short) == 4 && (extent % 4) != 0) is_four = 0;
708    if (sizeof(short) == 8 && (extent % 8) != 0) is_eight = 0;
709    DBG("char_short_char",size,extent);
710
711    /* If aligned mod 8, it will be aligned mod 4 */
712    if (is_eight) { is_four = 0; is_two = 0; }
713
714    if (is_four) is_two = 0;
715
716    /* Tabulate the results */
717    cf = fopen( "ctest.out", "w" );
718    if (is_packed + is_two + is_four + is_eight == 0) {
719	fprintf( cf, "Could not determine alignment\n" );
720    }
721    else {
722	if (is_packed + is_two + is_four + is_eight != 1) {
723	    fprintf( cf, "error!\n" );
724	}
725	else {
726	    if (is_packed) fprintf( cf, "packed\n" );
727	    if (is_two) fprintf( cf, "two\n" );
728	    if (is_four) fprintf( cf, "four\n" );
729	    if (is_eight) fprintf( cf, "eight\n" );
730	}
731    }
732    fclose( cf );
733    return 0;
734}],
735pac_cv_c_max_integer_align=`cat ctest.out`,
736pac_cv_c_max_integer_align="unknown",
737pac_cv_c_max_integer_align="$CROSS_ALIGN_STRUCT_INT")
738rm -f ctest.out
739])
740if test -z "$pac_cv_c_max_integer_align" ; then
741    pac_cv_c_max_integer_align="unknown"
742fi
743])
744
745dnl Return the floating point structure alignment in
746dnl pac_cv_c_max_fp_align.
747dnl
748dnl Possible values include:
749dnl	packed
750dnl	two
751dnl	four
752dnl	eight
753dnl     sixteen
754dnl
755dnl In addition, a "Could not determine alignment" and a "error!"
756dnl return is possible.
757AC_DEFUN([PAC_C_MAX_FP_ALIGN],[
758AC_CACHE_CHECK([for max C struct floating point alignment],
759pac_cv_c_max_fp_align,[
760AC_TRY_RUN([
761#include <stdio.h>
762#define DBG(a,b,c)
763int main( int argc, char *argv[] )
764{
765    FILE *cf;
766    int is_packed  = 1;
767    int is_two     = 1;
768    int is_four    = 1;
769    int is_eight   = 1;
770    int is_sixteen = 1;
771    struct { char a; float b; } char_float;
772    struct { float b; char a; } float_char;
773    struct { char a; double b; } char_double;
774    struct { double b; char a; } double_char;
775#ifdef HAVE_LONG_DOUBLE
776    struct { char a; long double b; } char_long_double;
777    struct { long double b; char a; } long_double_char;
778    struct { long double a; int b; char c; } long_double_int_char;
779#endif
780    int size, extent1, extent2;
781
782    size = sizeof(char) + sizeof(float);
783    extent1 = sizeof(char_float);
784    extent2 = sizeof(float_char);
785    if (size != extent1) is_packed = 0;
786    if ( (extent1 % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
787    if ( (extent1 % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
788    if (sizeof(float) == 8 && (extent1 % 8) != 0 && (extent2 % 8) != 0)
789	is_eight = 0;
790    DBG("char_float",size,extent1);
791
792    size = sizeof(char) + sizeof(double);
793    extent1 = sizeof(char_double);
794    extent2 = sizeof(double_char);
795    if (size != extent1) is_packed = 0;
796    if ( (extent1 % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
797    if ( (extent1 % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
798    if (sizeof(double) == 8 && (extent1 % 8) != 0 && (extent2 % 8) != 0)
799	is_eight = 0;
800    DBG("char_double",size,extent1);
801
802#ifdef HAVE_LONG_DOUBLE
803    size = sizeof(char) + sizeof(long double);
804    extent1 = sizeof(char_long_double);
805    extent2 = sizeof(long_double_char);
806    if (size != extent1) is_packed = 0;
807    if ( (extent1 % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
808    if ( (extent1 % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
809    if (sizeof(long double) >= 8 && (extent1 % 8) != 0 && (extent2 % 8) != 0)
810	is_eight = 0;
811    if (sizeof(long double) > 8 && (extent1 % 16) != 0
812	&& (extent2 % 16) != 0) is_sixteen = 0;
813    DBG("char_long-double",size,extent1);
814
815    extent1 = sizeof(long_double_int_char);
816    if ( (extent1 % 2) != 0) is_two = 0;
817    if ( (extent1 % 4) != 0) is_four = 0;
818    if (sizeof(long double) >= 8 && (extent1 % 8) != 0)	is_eight = 0;
819    if (sizeof(long double) > 8 && (extent1 % 16) != 0) is_sixteen = 0;
820#else
821    is_sixteen = 0;
822#endif
823
824    if (is_sixteen) { is_eight = 0; is_four = 0; is_two = 0; }
825
826    if (is_eight) { is_four = 0; is_two = 0; }
827
828    if (is_four) is_two = 0;
829
830    /* Tabulate the results */
831    cf = fopen( "ctest.out", "w" );
832    if (is_packed + is_two + is_four + is_eight + is_sixteen == 0) {
833	fprintf( cf, "Could not determine alignment\n" );
834    }
835    else {
836	if (is_packed + is_two + is_four + is_eight + is_sixteen != 1) {
837	    fprintf( cf, "error!\n" );
838	}
839	else {
840	    if (is_packed) fprintf( cf, "packed\n" );
841	    if (is_two) fprintf( cf, "two\n" );
842	    if (is_four) fprintf( cf, "four\n" );
843	    if (is_eight) fprintf( cf, "eight\n" );
844	    if (is_sixteen) fprintf( cf, "sixteen\n" );
845	}
846    }
847    fclose( cf );
848    return 0;
849}],
850pac_cv_c_max_fp_align=`cat ctest.out`,
851pac_cv_c_max_fp_align="unknown",
852pac_cv_c_max_fp_align="$CROSS_ALIGN_STRUCT_FP")
853rm -f ctest.out
854])
855if test -z "$pac_cv_c_max_fp_align" ; then
856    pac_cv_c_max_fp_align="unknown"
857fi
858])
859
860dnl Return the floating point structure alignment in
861dnl pac_cv_c_max_double_fp_align.
862dnl
863dnl Possible values include:
864dnl	packed
865dnl	two
866dnl	four
867dnl	eight
868dnl
869dnl In addition, a "Could not determine alignment" and a "error!"
870dnl return is possible.
871AC_DEFUN([PAC_C_MAX_DOUBLE_FP_ALIGN],[
872AC_CACHE_CHECK([for max C struct alignment of structs with doubles],
873pac_cv_c_max_double_fp_align,[
874AC_TRY_RUN([
875#include <stdio.h>
876#define DBG(a,b,c)
877int main( int argc, char *argv[] )
878{
879    FILE *cf;
880    int is_packed  = 1;
881    int is_two     = 1;
882    int is_four    = 1;
883    int is_eight   = 1;
884    struct { char a; float b; } char_float;
885    struct { float b; char a; } float_char;
886    struct { char a; double b; } char_double;
887    struct { double b; char a; } double_char;
888    int size, extent1, extent2;
889
890    size = sizeof(char) + sizeof(float);
891    extent1 = sizeof(char_float);
892    extent2 = sizeof(float_char);
893    if (size != extent1) is_packed = 0;
894    if ( (extent1 % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
895    if ( (extent1 % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
896    if (sizeof(float) == 8 && (extent1 % 8) != 0 && (extent2 % 8) != 0)
897	is_eight = 0;
898    DBG("char_float",size,extent1);
899
900    size = sizeof(char) + sizeof(double);
901    extent1 = sizeof(char_double);
902    extent2 = sizeof(double_char);
903    if (size != extent1) is_packed = 0;
904    if ( (extent1 % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
905    if ( (extent1 % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
906    if (sizeof(double) == 8 && (extent1 % 8) != 0 && (extent2 % 8) != 0)
907	is_eight = 0;
908    DBG("char_double",size,extent1);
909
910    if (is_eight) { is_four = 0; is_two = 0; }
911
912    if (is_four) is_two = 0;
913
914    /* Tabulate the results */
915    cf = fopen( "ctest.out", "w" );
916    if (is_packed + is_two + is_four + is_eight == 0) {
917	fprintf( cf, "Could not determine alignment\n" );
918    }
919    else {
920	if (is_packed + is_two + is_four + is_eight != 1) {
921	    fprintf( cf, "error!\n" );
922	}
923	else {
924	    if (is_packed) fprintf( cf, "packed\n" );
925	    if (is_two) fprintf( cf, "two\n" );
926	    if (is_four) fprintf( cf, "four\n" );
927	    if (is_eight) fprintf( cf, "eight\n" );
928	}
929    }
930    fclose( cf );
931    return 0;
932}],
933pac_cv_c_max_double_fp_align=`cat ctest.out`,
934pac_cv_c_max_double_fp_align="unknown",
935pac_cv_c_max_double_fp_align="$CROSS_ALIGN_STRUCT_DOUBLE_FP")
936rm -f ctest.out
937])
938if test -z "$pac_cv_c_max_double_fp_align" ; then
939    pac_cv_c_max_double_fp_align="unknown"
940fi
941])
942AC_DEFUN([PAC_C_MAX_LONGDOUBLE_FP_ALIGN],[
943AC_CACHE_CHECK([for max C struct floating point alignment with long doubles],
944pac_cv_c_max_longdouble_fp_align,[
945AC_TRY_RUN([
946#include <stdio.h>
947#define DBG(a,b,c)
948int main( int argc, char *argv[] )
949{
950    FILE *cf;
951    int is_packed  = 1;
952    int is_two     = 1;
953    int is_four    = 1;
954    int is_eight   = 1;
955    int is_sixteen = 1;
956    struct { char a; long double b; } char_long_double;
957    struct { long double b; char a; } long_double_char;
958    struct { long double a; int b; char c; } long_double_int_char;
959    int size, extent1, extent2;
960
961    size = sizeof(char) + sizeof(long double);
962    extent1 = sizeof(char_long_double);
963    extent2 = sizeof(long_double_char);
964    if (size != extent1) is_packed = 0;
965    if ( (extent1 % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
966    if ( (extent1 % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
967    if (sizeof(long double) >= 8 && (extent1 % 8) != 0 && (extent2 % 8) != 0)
968	is_eight = 0;
969    if (sizeof(long double) > 8 && (extent1 % 16) != 0
970	&& (extent2 % 16) != 0) is_sixteen = 0;
971    DBG("char_long-double",size,extent1);
972
973    extent1 = sizeof(long_double_int_char);
974    if ( (extent1 % 2) != 0) is_two = 0;
975    if ( (extent1 % 4) != 0) is_four = 0;
976    if (sizeof(long double) >= 8 && (extent1 % 8) != 0)	is_eight = 0;
977    if (sizeof(long double) > 8 && (extent1 % 16) != 0) is_sixteen = 0;
978
979    if (is_sixteen) { is_eight = 0; is_four = 0; is_two = 0; }
980
981    if (is_eight) { is_four = 0; is_two = 0; }
982
983    if (is_four) is_two = 0;
984
985    /* Tabulate the results */
986    cf = fopen( "ctest.out", "w" );
987    if (is_packed + is_two + is_four + is_eight + is_sixteen == 0) {
988	fprintf( cf, "Could not determine alignment\n" );
989    }
990    else {
991	if (is_packed + is_two + is_four + is_eight + is_sixteen != 1) {
992	    fprintf( cf, "error!\n" );
993	}
994	else {
995	    if (is_packed) fprintf( cf, "packed\n" );
996	    if (is_two) fprintf( cf, "two\n" );
997	    if (is_four) fprintf( cf, "four\n" );
998	    if (is_eight) fprintf( cf, "eight\n" );
999	    if (is_sixteen) fprintf( cf, "sixteen\n" );
1000	}
1001    }
1002    fclose( cf );
1003    return 0;
1004}],
1005pac_cv_c_max_longdouble_fp_align=`cat ctest.out`,
1006pac_cv_c_max_longdouble_fp_align="unknown",
1007pac_cv_c_max_longdouble_fp_align="$CROSS_ALIGN_STRUCT_LONGDOUBLE_FP")
1008rm -f ctest.out
1009])
1010if test -z "$pac_cv_c_max_longdouble_fp_align" ; then
1011    pac_cv_c_max_longdouble_fp_align="unknown"
1012fi
1013])
1014
1015dnl Other tests assume that there is potentially a maximum alignment
1016dnl and that if there is no maximum alignment, or a type is smaller than
1017dnl that value, then we align on the size of the value, with the exception
1018dnl of the "position-based alignment" rules we test for separately.
1019dnl
1020dnl It turns out that these assumptions have fallen short in at least one
1021dnl case, on MacBook Pros, where doubles are aligned on 4-byte boundaries
1022dnl even when long doubles are aligned on 16-byte boundaries. So this test
1023dnl is here specifically to handle this case.
1024dnl
1025dnl Puts result in pac_cv_c_double_alignment_exception.
1026dnl
1027dnl Possible values currently include no and four.
1028dnl
1029AC_DEFUN([PAC_C_DOUBLE_ALIGNMENT_EXCEPTION],[
1030AC_CACHE_CHECK([if double alignment breaks rules, find actual alignment],
1031pac_cv_c_double_alignment_exception,[
1032AC_TRY_RUN([
1033#include <stdio.h>
1034#define DBG(a,b,c)
1035int main( int argc, char *argv[] )
1036{
1037    FILE *cf;
1038    struct { char a; double b; } char_double;
1039    struct { double b; char a; } double_char;
1040    int extent1, extent2, align_4 = 0;
1041
1042    extent1 = sizeof(char_double);
1043    extent2 = sizeof(double_char);
1044
1045    /* we're interested in the largest value, will let separate test
1046     * deal with position-based issues.
1047     */
1048    if (extent1 < extent2) extent1 = extent2;
1049    if ((sizeof(double) == 8) && (extent1 % 8) != 0) {
1050       if (extent1 % 4 == 0) {
1051#ifdef HAVE_MAX_FP_ALIGNMENT
1052          if (HAVE_MAX_FP_ALIGNMENT >= 8) align_4 = 1;
1053#else
1054          align_4 = 1;
1055#endif
1056       }
1057    }
1058
1059    cf = fopen( "ctest.out", "w" );
1060
1061    if (align_4) fprintf( cf, "four\n" );
1062    else fprintf( cf, "no\n" );
1063
1064    fclose( cf );
1065    return 0;
1066}],
1067pac_cv_c_double_alignment_exception=`cat ctest.out`,
1068pac_cv_c_double_alignment_exception="unknown",
1069pac_cv_c_double_alignment_exception="$CROSS_ALIGN_DOUBLE_EXCEPTION")
1070rm -f ctest.out
1071])
1072if test -z "$pac_cv_c_double_alignment_exception" ; then
1073    pac_cv_c_double_alignment_exception="unknown"
1074fi
1075])
1076
1077dnl Test for odd struct alignment rule that only applies max.
1078dnl padding when double value is at front of type.
1079dnl Puts result in pac_cv_c_double_pos_align.
1080dnl
1081dnl Search for "Power alignment mode" for more details.
1082dnl
1083dnl Possible values include yes, no, and unknown.
1084dnl
1085AC_DEFUN([PAC_C_DOUBLE_POS_ALIGN],[
1086AC_CACHE_CHECK([if alignment of structs with doubles is based on position],
1087pac_cv_c_double_pos_align,[
1088AC_TRY_RUN([
1089#include <stdio.h>
1090#define DBG(a,b,c)
1091int main( int argc, char *argv[] )
1092{
1093    FILE *cf;
1094    int padding_varies_by_pos = 0;
1095    struct { char a; double b; } char_double;
1096    struct { double b; char a; } double_char;
1097    int extent1, extent2;
1098
1099    extent1 = sizeof(char_double);
1100    extent2 = sizeof(double_char);
1101    if (extent1 != extent2) padding_varies_by_pos = 1;
1102
1103    cf = fopen( "ctest.out", "w" );
1104    if (padding_varies_by_pos) fprintf( cf, "yes\n" );
1105    else fprintf( cf, "no\n" );
1106
1107    fclose( cf );
1108    return 0;
1109}],
1110pac_cv_c_double_pos_align=`cat ctest.out`,
1111pac_cv_c_double_pos_align="unknown",
1112pac_cv_c_double_pos_align="$CROSS_ALIGN_DOUBLE_POS")
1113rm -f ctest.out
1114])
1115if test -z "$pac_cv_c_double_pos_align" ; then
1116    pac_cv_c_double_pos_align="unknown"
1117fi
1118])
1119
1120dnl Test for odd struct alignment rule that only applies max.
1121dnl padding when long long int value is at front of type.
1122dnl Puts result in pac_cv_c_llint_pos_align.
1123dnl
1124dnl Search for "Power alignment mode" for more details.
1125dnl
1126dnl Possible values include yes, no, and unknown.
1127dnl
1128AC_DEFUN([PAC_C_LLINT_POS_ALIGN],[
1129AC_CACHE_CHECK([if alignment of structs with long long ints is based on position],
1130pac_cv_c_llint_pos_align,[
1131AC_TRY_RUN([
1132#include <stdio.h>
1133#define DBG(a,b,c)
1134int main( int argc, char *argv[] )
1135{
1136    FILE *cf;
1137    int padding_varies_by_pos = 0;
1138#ifdef HAVE_LONG_LONG_INT
1139    struct { char a; long long int b; } char_llint;
1140    struct { long long int b; char a; } llint_char;
1141    int extent1, extent2;
1142
1143    extent1 = sizeof(char_llint);
1144    extent2 = sizeof(llint_char);
1145    if (extent1 != extent2) padding_varies_by_pos = 1;
1146#endif
1147
1148    cf = fopen( "ctest.out", "w" );
1149    if (padding_varies_by_pos) fprintf( cf, "yes\n" );
1150    else fprintf( cf, "no\n" );
1151
1152    fclose( cf );
1153    return 0;
1154}],
1155pac_cv_c_llint_pos_align=`cat ctest.out`,
1156pac_cv_c_llint_pos_align="unknown",
1157pac_cv_c_llint_pos_align="$CROSS_ALIGN_LLINT_POS")
1158rm -f ctest.out
1159])
1160if test -z "$pac_cv_c_llint_pos_align" ; then
1161    pac_cv_c_llint_pos_align="unknown"
1162fi
1163])
1164
1165dnl/*D
1166dnl PAC_FUNC_NEEDS_DECL - Set NEEDS_<funcname>_DECL if a declaration is needed
1167dnl
1168dnl Synopsis:
1169dnl PAC_FUNC_NEEDS_DECL(headerfiles,funcname)
1170dnl
1171dnl Output Effect:
1172dnl Sets 'NEEDS_<funcname>_DECL' if 'funcname' is not declared by the
1173dnl headerfiles.
1174dnl
1175dnl Approach:
1176dnl Try to compile a program with the function, but passed with an incorrect
1177dnl calling sequence.  If the compilation fails, then the declaration
1178dnl is provided within the header files.  If the compilation succeeds,
1179dnl the declaration is required.
1180dnl
1181dnl We use a 'double' as the first argument to try and catch varargs
1182dnl routines that may use an int or pointer as the first argument.
1183dnl
1184dnl There is one difficulty - if the compiler has been instructed to
1185dnl fail on implicitly defined functions, then this test will always
1186dnl fail.
1187dnl
1188dnl D*/
1189AC_DEFUN([PAC_FUNC_NEEDS_DECL],[
1190AC_CACHE_CHECK([whether $2 needs a declaration],
1191pac_cv_func_decl_$2,[
1192AC_TRY_COMPILE([$1
1193int $2(double, int, double, const char *);],[int a=$2(1.0,27,1.0,"foo");],
1194pac_cv_func_decl_$2=yes,pac_cv_func_decl_$2=no)])
1195if test "$pac_cv_func_decl_$2" = "yes" ; then
1196changequote(<<,>>)dnl
1197define(<<PAC_FUNC_NAME>>, translit(NEEDS_$2_DECL, [a-z *], [A-Z__]))dnl
1198changequote([, ])dnl
1199    AC_DEFINE_UNQUOTED(PAC_FUNC_NAME,1,[Define if $2 needs a declaration])
1200undefine([PAC_FUNC_NAME])
1201fi
1202])
1203
1204dnl PAC_C_GNU_ATTRIBUTE - See if the GCC __attribute__ specifier is allow.
1205dnl Use the following
1206dnl #ifndef HAVE_GCC_ATTRIBUTE
1207dnl #define __attribute__(a)
1208dnl #endif
1209dnl If *not*, define __attribute__(a) as null
1210dnl
1211dnl We start by requiring Gcc.  Some other compilers accept __attribute__
1212dnl but generate warning messages, or have different interpretations
1213dnl (which seems to make __attribute__ just as bad as #pragma)
1214dnl For example, the Intel icc compiler accepts __attribute__ and
1215dnl __attribute__((pure)) but generates warnings for __attribute__((format...))
1216dnl
1217AC_DEFUN([PAC_C_GNU_ATTRIBUTE],[
1218AC_REQUIRE([AC_PROG_CC_GNU])
1219if test "$ac_cv_prog_gcc" = "yes" ; then
1220    AC_CACHE_CHECK([whether __attribute__ allowed],
1221pac_cv_gnu_attr_pure,[
1222AC_TRY_COMPILE([int foo(int) __attribute__ ((pure));],[int a;],
1223pac_cv_gnu_attr_pure=yes,pac_cv_gnu_attr_pure=no)])
1224AC_CACHE_CHECK([whether __attribute__((format)) allowed],
1225pac_cv_gnu_attr_format,[
1226AC_TRY_COMPILE([int foo(char *,...) __attribute__ ((format(printf,1,2)));],[int a;],
1227pac_cv_gnu_attr_format=yes,pac_cv_gnu_attr_format=no)])
1228    if test "$pac_cv_gnu_attr_pure" = "yes" -a "$pac_cv_gnu_attr_format" = "yes" ; then
1229        AC_DEFINE(HAVE_GCC_ATTRIBUTE,1,[Define if GNU __attribute__ is supported])
1230    fi
1231fi
1232])
1233dnl
1234dnl Check for a broken install (fails to preserve file modification times,
1235dnl thus breaking libraries.
1236dnl
1237dnl Create a library, install it, and then try to link against it.
1238AC_DEFUN([PAC_PROG_INSTALL_BREAKS_LIBS],[
1239AC_CACHE_CHECK([whether install breaks libraries],
1240ac_cv_prog_install_breaks_libs,[
1241AC_REQUIRE([AC_PROG_RANLIB])
1242AC_REQUIRE([AC_PROG_INSTALL])
1243AC_REQUIRE([AC_PROG_CC])
1244ac_cv_prog_install_breaks_libs=yes
1245
1246AC_COMPILE_IFELSE([
1247    AC_LANG_SOURCE([ int foo(int); int foo(int a){return a;} ])
1248],[
1249    if ${AR-ar} ${AR_FLAGS-cr} libconftest.a conftest.$OBJEXT >/dev/null 2>&1 ; then
1250        if ${RANLIB-:} libconftest.a >/dev/null 2>&1 ; then
1251            # Anything less than sleep 10, and Mac OS/X (Darwin)
1252            # will claim that install works because ranlib won't complain
1253            sleep 10
1254            libinstall="$INSTALL_DATA"
1255            eval "libinstall=\"$libinstall\""
1256            if ${libinstall} libconftest.a libconftest1.a >/dev/null 2>&1 ; then
1257                saved_LIBS="$LIBS"
1258                LIBS="libconftest1.a"
1259                AC_LINK_IFELSE([
1260                    AC_LANG_SOURCE([
1261extern int foo(int);
1262int main(int argc, char **argv){ return foo(0); }
1263                    ])
1264                ],[
1265                    # Success!  Install works
1266                    ac_cv_prog_install_breaks_libs=no
1267                ],[
1268                    # Failure!  Does install -p work?
1269                    rm -f libconftest1.a
1270                    if ${libinstall} -p libconftest.a libconftest1.a >/dev/null 2>&1 ; then
1271                        AC_LINK_IFELSE([],[
1272                            # Success!  Install works
1273                            ac_cv_prog_install_breaks_libs="no, with -p"
1274                        ])
1275                    fi
1276                ])
1277                LIBS="$saved_LIBS"
1278            fi
1279        fi
1280    fi
1281])
1282rm -f libconftest*.a
1283]) dnl Endof ac_cache_check
1284
1285if test -z "$RANLIB_AFTER_INSTALL" ; then
1286    RANLIB_AFTER_INSTALL=no
1287fi
1288case "$ac_cv_prog_install_breaks_libs" in
1289    yes)
1290        RANLIB_AFTER_INSTALL=yes
1291    ;;
1292    "no, with -p")
1293        INSTALL_DATA="$INSTALL_DATA -p"
1294    ;;
1295    *)
1296    # Do nothing
1297    :
1298    ;;
1299esac
1300AC_SUBST(RANLIB_AFTER_INSTALL)
1301])
1302
1303#
1304# determine if the compiler defines a symbol containing the function name
1305#
1306# These tests check not only that the compiler defines some symbol, such
1307# as __FUNCTION__, but that the symbol correctly names the function.
1308#
1309# Defines
1310#   HAVE__FUNC__      (if __func__ defined)
1311#   HAVE_CAP__FUNC__  (if __FUNC__ defined)
1312#   HAVE__FUNCTION__  (if __FUNCTION__ defined)
1313#
1314AC_DEFUN([PAC_CC_FUNCTION_NAME_SYMBOL],[
1315AC_CACHE_CHECK([whether the compiler defines __func__],
1316pac_cv_have__func__,[
1317tmp_am_cross=no
1318AC_RUN_IFELSE([
1319AC_LANG_SOURCE([
1320#include <string.h>
1321int foo(void);
1322int foo(void)
1323{
1324    return (strcmp(__func__, "foo") == 0);
1325}
1326int main(int argc, char ** argv)
1327{
1328    return (foo() ? 0 : 1);
1329}
1330])
1331], pac_cv_have__func__=yes, pac_cv_have__func__=no,tmp_am_cross=yes)
1332if test "$tmp_am_cross" = yes ; then
1333    AC_LINK_IFELSE([
1334    AC_LANG_SOURCE([
1335#include <string.h>
1336int foo(void);
1337int foo(void)
1338{
1339    return (strcmp(__func__, "foo") == 0);
1340}
1341int main(int argc, char ** argv)
1342{
1343    return (foo() ? 0 : 1);
1344}
1345    ])
1346], pac_cv_have__func__=yes, pac_cv_have__func__=no)
1347fi
1348])
1349
1350if test "$pac_cv_have__func__" = "yes" ; then
1351    AC_DEFINE(HAVE__FUNC__,,[define if the compiler defines __func__])
1352fi
1353
1354AC_CACHE_CHECK([whether the compiler defines __FUNC__],
1355pac_cv_have_cap__func__,[
1356tmp_am_cross=no
1357AC_RUN_IFELSE([
1358AC_LANG_SOURCE([
1359#include <string.h>
1360int foo(void);
1361int foo(void)
1362{
1363    return (strcmp(__FUNC__, "foo") == 0);
1364}
1365int main(int argc, char ** argv)
1366{
1367    return (foo() ? 0 : 1);
1368}
1369])
1370], pac_cv_have_cap__func__=yes, pac_cv_have_cap__func__=no,tmp_am_cross=yes)
1371if test "$tmp_am_cross" = yes ; then
1372    AC_LINK_IFELSE([
1373    AC_LANG_SOURCE([
1374#include <string.h>
1375int foo(void);
1376int foo(void)
1377{
1378    return (strcmp(__FUNC__, "foo") == 0);
1379}
1380int main(int argc, char ** argv)
1381{
1382    return (foo() ? 0 : 1);
1383}
1384    ])
1385], pac_cv_have__func__=yes, pac_cv_have__func__=no)
1386fi
1387])
1388
1389if test "$pac_cv_have_cap__func__" = "yes" ; then
1390    AC_DEFINE(HAVE_CAP__FUNC__,,[define if the compiler defines __FUNC__])
1391fi
1392
1393AC_CACHE_CHECK([whether the compiler sets __FUNCTION__],
1394pac_cv_have__function__,[
1395tmp_am_cross=no
1396AC_RUN_IFELSE([
1397AC_LANG_SOURCE([
1398#include <string.h>
1399int foo(void);
1400int foo(void)
1401{
1402    return (strcmp(__FUNCTION__, "foo") == 0);
1403}
1404int main(int argc, char ** argv)
1405{
1406    return (foo() ? 0 : 1);
1407}
1408])
1409], pac_cv_have__function__=yes, pac_cv_have__function__=no,tmp_am_cross=yes)
1410if test "$tmp_am_cross" = yes ; then
1411    AC_LINK_IFELSE([
1412    AC_LANG_SOURCE([
1413#include <string.h>
1414int foo(void);
1415int foo(void)
1416{
1417    return (strcmp(__FUNCTION__, "foo") == 0);
1418}
1419int main(int argc, char ** argv)
1420{
1421    return (foo() ? 0 : 1);
1422}
1423    ])
1424], pac_cv_have__func__=yes, pac_cv_have__func__=no)
1425fi
1426])
1427
1428if test "$pac_cv_have__function__" = "yes" ; then
1429    AC_DEFINE(HAVE__FUNCTION__,,[define if the compiler defines __FUNCTION__])
1430fi
1431
1432])
1433
1434
1435dnl Check structure alignment
1436AC_DEFUN([PAC_STRUCT_ALIGNMENT],[
1437	# Initialize alignment checks
1438	is_packed=1
1439	is_two=1
1440	is_four=1
1441	is_eight=1
1442	is_largest=1
1443
1444	# See if long double exists
1445	AC_TRY_COMPILE(,[long double a;],have_long_double=yes,have_long_double=no)
1446
1447	# Get sizes of regular types
1448	AC_CHECK_SIZEOF(char)
1449	AC_CHECK_SIZEOF(int)
1450	AC_CHECK_SIZEOF(short)
1451	AC_CHECK_SIZEOF(long)
1452	AC_CHECK_SIZEOF(float)
1453	AC_CHECK_SIZEOF(double)
1454	AC_CHECK_SIZEOF(long double)
1455
1456	# char_int comparison
1457	AC_CHECK_SIZEOF(char_int, 0, [typedef struct { char a; int b; } char_int; ])
1458	size=`expr $ac_cv_sizeof_char + $ac_cv_sizeof_int`
1459	extent=$ac_cv_sizeof_char_int
1460	if test "$size" != "$extent" ; then is_packed=0 ; fi
1461	if test "`expr $extent % $ac_cv_sizeof_int`" != "0" ; then is_largest=0 ; fi
1462	if test "`expr $extent % 2`" != "0" ; then is_two=0 ; fi
1463	if test "`expr $extent % 4`" != "0" ; then is_four=0 ; fi
1464	if test "$ac_cv_sizeof_int" = "8" -a "`expr $extent % 8`" != "0" ; then
1465	   is_eight=0
1466	fi
1467
1468	# char_short comparison
1469	AC_CHECK_SIZEOF(char_short, 0, [typedef struct { char a; short b; } char_short; ])
1470	size=`expr $ac_cv_sizeof_char + $ac_cv_sizeof_short`
1471	extent=$ac_cv_sizeof_char_short
1472	if test "$size" != "$extent" ; then is_packed=0 ; fi
1473	if test "`expr $extent % $ac_cv_sizeof_short`" != "0" ; then is_largest=0 ; fi
1474	if test "`expr $extent % 2`" != "0" ; then is_two=0 ; fi
1475	if test "$ac_cv_sizeof_short" = "4" -a "`expr $extent % 4`" != "0" ; then
1476	   is_four=0
1477	fi
1478	if test "$ac_cv_sizeof_short" = "8" -a "`expr $extent % 8`" != "0" ; then
1479	   is_eight=0
1480	fi
1481
1482	# char_long comparison
1483	AC_CHECK_SIZEOF(char_long, 0, [typedef struct { char a; long b; } char_long; ])
1484	size=`expr $ac_cv_sizeof_char + $ac_cv_sizeof_long`
1485	extent=$ac_cv_sizeof_char_long
1486	if test "$size" != "$extent" ; then is_packed=0 ; fi
1487	if test "`expr $extent % $ac_cv_sizeof_long`" != "0" ; then is_largest=0 ; fi
1488	if test "`expr $extent % 2`" != "0" ; then is_two=0 ; fi
1489	if test "`expr $extent % 4`" != "0" ; then is_four=0 ; fi
1490	if test "$ac_cv_sizeof_long" = "8" -a "`expr $extent % 8`" != "0" ; then
1491	   is_eight=0
1492	fi
1493
1494	# char_float comparison
1495	AC_CHECK_SIZEOF(char_float, 0, [typedef struct { char a; float b; } char_float; ])
1496	size=`expr $ac_cv_sizeof_char + $ac_cv_sizeof_float`
1497	extent=$ac_cv_sizeof_char_float
1498	if test "$size" != "$extent" ; then is_packed=0 ; fi
1499	if test "`expr $extent % $ac_cv_sizeof_float`" != "0" ; then is_largest=0 ; fi
1500	if test "`expr $extent % 2`" != "0" ; then is_two=0 ; fi
1501	if test "`expr $extent % 4`" != "0" ; then is_four=0 ; fi
1502	if test "$ac_cv_sizeof_float" = "8" -a "`expr $extent % 8`" != "0" ; then
1503	   is_eight=0
1504	fi
1505
1506	# char_double comparison
1507	AC_CHECK_SIZEOF(char_double, 0, [typedef struct { char a; double b; } char_double; ])
1508	size=`expr $ac_cv_sizeof_char + $ac_cv_sizeof_double`
1509	extent=$ac_cv_sizeof_char_double
1510	if test "$size" != "$extent" ; then is_packed=0 ; fi
1511	if test "`expr $extent % $ac_cv_sizeof_double`" != "0" ; then is_largest=0 ; fi
1512	if test "`expr $extent % 2`" != "0" ; then is_two=0 ; fi
1513	if test "`expr $extent % 4`" != "0" ; then is_four=0 ; fi
1514	if test "$ac_cv_sizeof_double" = "8" -a "`expr $extent % 8`" != "0" ; then
1515	   is_eight=0
1516	fi
1517
1518	# char_long_double comparison
1519	if test "$have_long_double" = "yes"; then
1520	AC_CHECK_SIZEOF(char_long_double, 0, [
1521				       typedef struct {
1522				       	       char a;
1523					       long double b;
1524				       } char_long_double;
1525				       ])
1526	size=`expr $ac_cv_sizeof_char + $ac_cv_sizeof_long_double`
1527	extent=$ac_cv_sizeof_char_long_double
1528	if test "$size" != "$extent" ; then is_packed=0 ; fi
1529	if test "`expr $extent % $ac_cv_sizeof_long_double`" != "0" ; then is_largest=0 ; fi
1530	if test "`expr $extent % 2`" != "0" ; then is_two=0 ; fi
1531	if test "`expr $extent % 4`" != "0" ; then is_four=0 ; fi
1532	if test "$ac_cv_sizeof_long_double" = "8" -a "`expr $extent % 8`" != "0" ; then
1533	   is_eight=0
1534	fi
1535	fi
1536
1537	# char_int_char comparison
1538	AC_CHECK_SIZEOF(char_int_char, 0, [
1539				       typedef struct {
1540				       	       char a;
1541					       int b;
1542					       char c;
1543				       } char_int_char;
1544				       ])
1545	size=`expr $ac_cv_sizeof_char + $ac_cv_sizeof_int + $ac_cv_sizeof_char`
1546	extent=$ac_cv_sizeof_char_int_char
1547	if test "$size" != "$extent" ; then is_packed=0 ; fi
1548	if test "`expr $extent % $ac_cv_sizeof_int`" != "0" ; then is_largest=0 ; fi
1549	if test "`expr $extent % 2`" != "0" ; then is_two=0 ; fi
1550	if test "`expr $extent % 4`" != "0" ; then is_four=0 ; fi
1551	if test "$ac_cv_sizeof_int" = "8" -a "`expr $extent % 8`" != "0" ; then
1552	   is_eight=0
1553	fi
1554
1555	# char_short_char comparison
1556	AC_CHECK_SIZEOF(char_short_char, 0, [
1557				       typedef struct {
1558				       	       char a;
1559					       short b;
1560					       char c;
1561				       } char_short_char;
1562				       ])
1563	size=`expr $ac_cv_sizeof_char + $ac_cv_sizeof_short + $ac_cv_sizeof_char`
1564	extent=$ac_cv_sizeof_char_short_char
1565	if test "$size" != "$extent" ; then is_packed=0 ; fi
1566	if test "`expr $extent % $ac_cv_sizeof_short`" != "0" ; then is_largest=0 ; fi
1567	if test "`expr $extent % 2`" != "0" ; then is_two=0 ; fi
1568	if test "$ac_cv_sizeof_short" = "4" -a "`expr $extent % 4`" != "0" ; then
1569	   is_four=0
1570	fi
1571	if test "$ac_cv_sizeof_short" = "8" -a "`expr $extent % 8`" != "0" ; then
1572	   is_eight=0
1573	fi
1574
1575	# If aligned mod 8, it will be aligned mod 4
1576	if test $is_eight = 1 ; then is_four=0 ; is_two=0 ; fi
1577	if test $is_four = 1 ; then is_two=0 ; fi
1578
1579	# Largest supersedes 8
1580	if test $is_largest = 1 ; then is_eight=0 ; fi
1581
1582	# Find the alignment
1583	if test "`expr $is_packed + $is_largest + $is_two + $is_four + $is_eight`" = "0" ; then
1584	   pac_cv_struct_alignment="unknown"
1585	elif test "`expr $is_packed + $is_largest + $is_two + $is_four + $is_eight`" != "1" ; then
1586	   pac_cv_struct_alignment="unknown"
1587	elif test $is_packed = 1 ; then
1588	   pac_cv_struct_alignment="packed"
1589	elif test $is_largest = 1 ; then
1590	   pac_cv_struct_alignment="largest"
1591	elif test $is_two = 1 ; then
1592	   pac_cv_struct_alignment="two"
1593	elif test $is_four = 1 ; then
1594	   pac_cv_struct_alignment="four"
1595	elif test $is_eight = 1 ; then
1596	   pac_cv_struct_alignment="eight"
1597	fi
1598])
1599dnl
1600dnl PAC_C_MACRO_VA_ARGS
1601dnl
1602dnl will AC_DEFINE([HAVE_MACRO_VA_ARGS]) if the compiler supports C99 variable
1603dnl length argument lists in macros (#define foo(...) bar(__VA_ARGS__))
1604AC_DEFUN([PAC_C_MACRO_VA_ARGS],[
1605    AC_MSG_CHECKING([for variable argument list macro functionality])
1606    AC_LINK_IFELSE([AC_LANG_PROGRAM([
1607        #include <stdio.h>
1608        #define conftest_va_arg_macro(...) printf(__VA_ARGS__)
1609    ],
1610    [conftest_va_arg_macro("a test %d", 3);])],
1611    [AC_DEFINE([HAVE_MACRO_VA_ARGS],[1],[Define if C99-style variable argument list macro functionality])
1612     AC_MSG_RESULT([yes])],
1613    [AC_MSG_RESULT([no])])
1614])dnl
1615