aclocal_cc.m4 72.3 KB
Newer Older
1
2
3
4
dnl
dnl This is a replacement for AC_PROG_CC that does not prefer gcc and
dnl that does not mess with CFLAGS.  See acspecific.m4 for the original defn.
dnl
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
dnl/*D
dnl PAC_PROG_CC - Find a working C compiler
dnl
dnl Synopsis:
dnl PAC_PROG_CC
dnl
dnl Output Effect:
dnl   Sets the variable CC if it is not already set
dnl
dnl Notes:
dnl   Unlike AC_PROG_CC, this does not prefer gcc and does not set CFLAGS.
dnl   It does check that the compiler can compile a simple C program.
dnl   It also sets the variable GCC to yes if the compiler is gcc.  It does
dnl   not yet check for some special options needed in particular for 
dnl   parallel computers, such as -Tcray-t3e, or special options to get
dnl   full ANSI/ISO C, such as -Aa for HP.
dnl
22
23
24
dnl D*/
dnl 2.52 doesn't have AC_PROG_CC_GNU
ifdef([AC_PROG_CC_GNU],,[AC_DEFUN([AC_PROG_CC_GNU],)])
25
26
AC_DEFUN(PAC_PROG_CC,[
AC_PROVIDE([AC_PROG_CC])
27
AC_CHECK_PROGS(CC, cc xlC xlc pgcc icc gcc )
28
test -z "$CC" && AC_MSG_ERROR([no acceptable cc found in \$PATH])
gropp's avatar
gropp committed
29
PAC_PROG_CC_WORKS
30
AC_PROG_CC_GNU
gropp's avatar
gropp committed
31
if test "$ac_cv_prog_gcc" = yes; then
32
33
34
35
36
37
  GCC=yes
else
  GCC=
fi
])
dnl
gropp's avatar
gropp committed
38
39
40
dnl/*D
dnl PAC_C_CHECK_COMPILER_OPTION - Check that a compiler option is accepted
dnl without warning messages
41
dnl
gropp's avatar
gropp committed
42
dnl Synopsis:
43
dnl PAC_C_CHECK_COMPILER_OPTION(optionname,action-if-ok,action-if-fail)
gropp's avatar
gropp committed
44
45
46
47
48
49
dnl
dnl Output Effects:
dnl
dnl If no actions are specified, a working value is added to 'COPTIONS'
dnl
dnl Notes:
50
51
52
53
54
55
56
57
dnl This is now careful to check that the output is different, since 
dnl some compilers are noisy.
dnl 
dnl We are extra careful to prototype the functions in case compiler options
dnl that complain about poor code are in effect.
dnl
dnl Because this is a long script, we have ensured that you can pass a 
dnl variable containing the option name as the first argument.
gropp's avatar
gropp committed
58
dnl D*/
59
AC_DEFUN(PAC_C_CHECK_COMPILER_OPTION,[
60
AC_MSG_CHECKING([whether C compiler accepts option $1])
61
62
63
64
65
save_CFLAGS="$CFLAGS"
CFLAGS="$1 $CFLAGS"
rm -f conftest.out
echo 'int try(void);int try(void){return 0;}' > conftest2.c
echo 'int main(void);int main(void){return 0;}' > conftest.c
gropp's avatar
gropp committed
66
67
if ${CC-cc} $save_CFLAGS $CPPFLAGS -o conftest conftest.c $LDFLAGS >conftest.bas 2>&1 ; then
   if ${CC-cc} $CFLAGS $CPPFLAGS -o conftest conftest.c $LDFLAGS >conftest.out 2>&1 ; then
68
69
      if diff -b conftest.out conftest.bas >/dev/null 2>&1 ; then
         AC_MSG_RESULT(yes)
70
         AC_MSG_CHECKING([whether routines compiled with $1 can be linked with ones compiled  without $1])       
71
72
         rm -f conftest.out
         rm -f conftest.bas
73
         if ${CC-cc} -c $save_CFLAGS $CPPFLAGS conftest2.c >conftest2.out 2>&1 ; then
gropp's avatar
gropp committed
74
75
            if ${CC-cc} $CFLAGS $CPPFLAGS -o conftest conftest2.o conftest.c $LDFLAGS >conftest.bas 2>&1 ; then
               if ${CC-cc} $CFLAGS $CPPFLAGS -o conftest conftest2.o conftest.c $LDFLAGS >conftest.out 2>&1 ; then
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
                  if diff -b conftest.out conftest.bas >/dev/null 2>&1 ; then
	             AC_MSG_RESULT(yes)	  
		     CFLAGS="$save_CFLAGS"
                     ifelse($2,,COPTIONS="$COPTIONS $1",$2)
                  elif test -s conftest.out ; then
	             cat conftest.out >&AC_FD_CC
	             AC_MSG_RESULT(no)
                     CFLAGS="$save_CFLAGS"
	             $3
                  else
                     AC_MSG_RESULT(no)
                     CFLAGS="$save_CFLAGS"
	             $3
                  fi  
               else
	          if test -s conftest.out ; then
	             cat conftest.out >&AC_FD_CC
	          fi
                  AC_MSG_RESULT(no)
                  CFLAGS="$save_CFLAGS"
                  $3
               fi
	    else
               # Could not link with the option!
               AC_MSG_RESULT(no)
            fi
         else
            if test -s conftest2.out ; then
               cat conftest.out >&AC_FD_CC
            fi
	    AC_MSG_RESULT(no)
            CFLAGS="$save_CFLAGS"
	    $3
         fi
      else
         cat conftest.out >&AC_FD_CC
         AC_MSG_RESULT(no)
         $3
         CFLAGS="$save_CFLAGS"         
      fi
   else
      AC_MSG_RESULT(no)
      $3
      if test -s conftest.out ; then cat conftest.out >&AC_FD_CC ; fi    
      CFLAGS="$save_CFLAGS"
   fi
else
    # Could not compile without the option!
    AC_MSG_RESULT(no)
fi
rm -f conftest*
])
dnl
gropp's avatar
gropp committed
129
130
131
132
133
134
135
136
137
138
dnl/*D
dnl PAC_C_OPTIMIZATION - Determine C options for producing optimized code
dnl
dnl Synopsis
dnl PAC_C_OPTIMIZATION([action if found])
dnl
dnl Output Effect:
dnl Adds options to 'COPTIONS' if no other action is specified
dnl 
dnl Notes:
139
140
141
142
143
dnl This is a temporary standin for compiler optimization.
dnl It should try to match known systems to known compilers (checking, of
dnl course), and then falling back to some common defaults.
dnl Note that many compilers will complain about -g and aggressive
dnl optimization.  
gropp's avatar
gropp committed
144
dnl D*/
145
146
147
AC_DEFUN(PAC_C_OPTIMIZATION,[
    for copt in "-O4 -Ofast" "-Ofast" "-fast" "-O3" "-xO3" "-O" ; do
        PAC_C_CHECK_COMPILER_OPTION($copt,found_opt=yes,found_opt=no)
gropp's avatar
gropp committed
148
        if test "$found_opt" = "yes" ; then
gropp's avatar
gropp committed
149
	    ifelse($1,,COPTIONS="$COPTIONS $copt",$1)
150
151
152
	    break
        fi
    done
153
154
155
156
157
158
159
160
161
162
163
164
    if test "$ac_cv_prog_gcc" = "yes" ; then
	for copt in "-fomit-frame-pointer" "-finline-functions" \
		 "-funroll-loops" ; do
	    PAC_C_CHECK_COMPILER_OPTION($copt,found_opt=yes,found_opt=no)
	    if test $found_opt = "yes" ; then
	        ifelse($1,,COPTIONS="$COPTIONS $copt",$1)
	        # no break because we're trying to add them all
	    fi
	done
	# We could also look for architecture-specific gcc options
    fi

165
])
gropp's avatar
gropp committed
166
167
168
169
170
171
172
173
174
175
176
177
dnl
dnl/*D
dnl PAC_C_DEPENDS - Determine how to use the C compiler to generate 
dnl dependency information
dnl
dnl Synopsis:
dnl PAC_C_DEPENDS
dnl
dnl Output Effects:
dnl Sets the following shell variables and call AC_SUBST for them:
dnl+ C_DEPEND_OPT - Compiler options needed to create dependencies
dnl. C_DEPEND_OUT - Shell redirection for dependency file (may be empty)
gropp's avatar
gropp committed
178
179
dnl. C_DEPEND_PREFIX - Empty (null) or true; this is used to handle
dnl  systems that do not provide dependency information
gropp's avatar
gropp committed
180
181
182
dnl- C_DEPEND_MV - Command to move created dependency file
dnl Also creates a Depends file in the top directory (!).
dnl
gropp's avatar
gropp committed
183
184
185
dnl In addition, the variable 'C_DEPEND_DIR' must be set to indicate the
dnl directory in which the dependency files should live.  
dnl
gropp's avatar
gropp committed
186
187
188
189
190
191
dnl Notes:
dnl A typical Make rule that exploits this macro is
dnl.vb
dnl #
dnl # Dependency processing
dnl .SUFFIXES: .dep
gropp's avatar
gropp committed
192
dnl DEP_SOURCES = ${SOURCES:%.c=.dep/%.dep}
gropp's avatar
gropp committed
193
dnl C_DEPEND_DIR = .dep
gropp's avatar
gropp committed
194
195
dnl Depends: ${DEP_SOURCES}
dnl         @-rm -f Depends
gropp's avatar
gropp committed
196
197
198
dnl         cat .dep/*.dep >Depends
dnl .dep/%.dep:%.c
dnl	    @if [ ! -d .dep ] ; then mkdir .dep ; fi
gropp's avatar
gropp committed
199
dnl         @@C_DEPEND_PREFIX@ ${C_COMPILE} @C_DEPEND_OPT@ $< @C_DEPEND_OUT@
gropp's avatar
gropp committed
200
201
202
203
204
205
206
207
208
dnl         @@C_DEPEND_MV@
dnl
dnl depends-clean:
dnl         @-rm -f *.dep ${srcdir}/*.dep Depends ${srcdir}/Depends
dnl         @-touch Depends
dnl.ve
dnl
dnl For each file 'foo.c', this creates a file 'foo.dep' and creates a file
dnl 'Depends' that contains all of the '*.dep' files.
gropp's avatar
gropp committed
209
dnl
gropp's avatar
gropp committed
210
211
212
213
214
dnl For your convenience, the autoconf variable 'C_DO_DEPENDS' names a file 
dnl that may contain this code (you must have `dependsrule` or 
dnl `dependsrule.in` in the same directory as the other auxillery configure 
dnl scripts (set with dnl 'AC_CONFIG_AUX_DIR').  If you use `dependsrule.in`,
dnl you must have `dependsrule` in 'AC_OUTPUT' before this `Makefile`.
gropp's avatar
gropp committed
215
dnl 
gropp's avatar
gropp committed
216
dnl D*/
gropp's avatar
gropp committed
217
218
219
220
dnl 
dnl Eventually, we can add an option to the C_DEPEND_MV to strip system
dnl includes, such as /usr/xxxx and /opt/xxxx
dnl
221
AC_DEFUN(PAC_C_DEPENDS,[
gropp's avatar
gropp committed
222
223
224
225
AC_SUBST(C_DEPEND_OPT)AM_IGNORE(C_DEPEND_OPT)
AC_SUBST(C_DEPEND_OUT)AM_IGNORE(C_DEPEND_OUT)
AC_SUBST(C_DEPEND_MV)AM_IGNORE(C_DEPEND_MV)
AC_SUBST(C_DEPEND_PREFIX)AM_IGNORE(C_DEPEND_PREFIX)
gropp's avatar
gropp committed
226
227
228
229
AC_SUBST_FILE(C_DO_DEPENDS) 
dnl set the value of the variable to a 
dnl file that contains the dependency code, such as
dnl ${top_srcdir}/maint/dependrule 
gropp's avatar
gropp committed
230
231
232
233
234
235
if test -n "$ac_cv_c_depend_opt" ; then
    AC_MSG_RESULT([Option $ac_cv_c_depend_opt creates dependencies (cached)])
    C_DEPEND_OUT="$ac_cv_c_depend_out"
    C_DEPEND_MV="$ac_cv_c_depend_mv"
    C_DEPEND_OPT="$ac_cv_c_depend_opt"
    C_DEPEND_PREFIX="$ac_cv_c_depend_prefix"
gropp's avatar
gropp committed
236
    C_DO_DEPENDS="$ac_cv_c_do_depends"
gropp's avatar
gropp committed
237
238
else
   # Determine the values
239
rm -f conftest*
gropp's avatar
gropp committed
240
241
242
243
dnl
dnl Some systems (/usr/ucb/cc on Solaris) do not generate a dependency for
dnl an include that doesn't begin in column 1
dnl
244
245
246
247
cat >conftest.c <<EOF
    #include "confdefs.h"
    int f(void) { return 0; }
EOF
248
249
250
251
252
dnl -xM1 is Solaris C compiler (no /usr/include files)
dnl -MM is gcc (no /usr/include files)
dnl -MMD is gcc to .d
dnl .u is xlC (AIX) output
for copt in "-xM1" "-c -xM1" "-xM" "-c -xM" "-MM" "-M" "-c -M"; do
253
    AC_MSG_CHECKING([whether $copt option generates dependencies])
gropp's avatar
gropp committed
254
    rm -f conftest.o conftest.u conftest.d conftest.err conftest.out
255
256
257
258
259
260
    dnl also need to check that error output is empty
    if $CC $CFLAGS $copt conftest.c >conftest.out 2>conftest.err && \
	test ! -s conftest.err ; then
        dnl Check for dependency info in conftest.out
        if test -s conftest.u ; then 
	    C_DEPEND_OUT=""
gropp's avatar
gropp committed
261
	    C_DEPEND_MV='mv $[*].u ${C_DEPEND_DIR}/$[*].dep'
262
            pac_dep_file=conftest.u 
263
264
        elif test -s conftest.d ; then
	    C_DEPEND_OUT=""
gropp's avatar
gropp committed
265
	    C_DEPEND_MV='mv $[*].d ${C_DEPEND_DIR}/$[*].dep'
266
            pac_dep_file=conftest.d 
267
        else
gropp's avatar
gropp committed
268
269
270
	    dnl C_DEPEND_OUT='>${C_DEPEND_DIR}/$[*].dep'
	    dnl This for is needed for VPATH.  Perhaps the others should match.
	    C_DEPEND_OUT='>$@'
271
272
273
274
275
276
277
278
279
280
281
	    C_DEPEND_MV=:
            pac_dep_file=conftest.out
        fi
        if grep 'confdefs.h' $pac_dep_file >/dev/null 2>&1 ; then
            AC_MSG_RESULT(yes)
	    C_DEPEND_OPT="$copt"
	    AC_MSG_CHECKING([whether .o file created with dependency file])
	    if test -s conftest.o ; then
	        AC_MSG_RESULT(yes)
	    else
                AC_MSG_RESULT(no)
gropp's avatar
gropp committed
282
283
		echo "Output of $copt option was" >&AC_FD_CC
		cat $pac_dep_file >&AC_FD_CC
284
285
286
287
288
289
            fi
	    break
        else
	    AC_MSG_RESULT(no)
        fi
    else
gropp's avatar
gropp committed
290
	echo "Error in compiling program with flags $copt" >&AC_FD_CC
291
	cat conftest.out >&AC_FD_CC
gropp's avatar
gropp committed
292
	if test -s conftest.err ; then cat conftest.err >&AC_FD_CC ; fi
293
294
295
296
	AC_MSG_RESULT(no)
    fi
    copt=""
done
gropp's avatar
gropp committed
297
298
    if test -f $CONFIG_AUX_DIR/dependsrule -o \
	    -f $CONFIG_AUX_DIR/dependsrule.in; then
gropp's avatar
gropp committed
299
300
301
302
	C_DO_DEPENDS="$CONFIG_AUX_DIR/dependsrule"
    else 
	C_DO_DEPENDS="/dev/null"
    fi
gropp's avatar
gropp committed
303
304
305
306
307
308
309
310
311
    if test "X$copt" = "X" ; then
        C_DEPEND_PREFIX="true"
    else
        C_DEPEND_PREFIX=""
    fi
    ac_cv_c_depend_out="$C_DEPEND_OUT"
    ac_cv_c_depend_mv="$C_DEPEND_MV"
    ac_cv_c_depend_opt="$C_DEPEND_OPT"
    ac_cv_c_depend_prefix="$C_DEPEND_PREFIX"
gropp's avatar
gropp committed
312
    ac_cv_c_do_depends="$C_DO_DEPENDS"
gropp's avatar
gropp committed
313
fi
314
])
315
dnl
gropp's avatar
gropp committed
316
317
dnl/*D 
dnl PAC_C_PROTOTYPES - Check that the compiler accepts ANSI prototypes.  
318
dnl
gropp's avatar
gropp committed
319
320
dnl Synopsis:
dnl PAC_C_PROTOTYPES([action if true],[action if false])
321
dnl
322
dnl D*/
323
AC_DEFUN(PAC_C_PROTOTYPES,[
324
AC_CACHE_CHECK([whether $CC supports function prototypes],
325
326
327
328
329
330
331
332
333
334
pac_cv_c_prototypes,[
AC_TRY_COMPILE([int f(double a){return 0;}],[return 0];,
pac_cv_c_prototypes="yes",pac_cv_c_prototypes="no")])
if test "$pac_cv_c_prototypes" = "yes" ; then
    ifelse([$1],,:,[$1])
else
    ifelse([$2],,:,[$2])
fi
])dnl
dnl
gropp's avatar
gropp committed
335
336
dnl/*D
dnl PAC_FUNC_SEMCTL - Check for semctl and its argument types
337
dnl
gropp's avatar
gropp committed
338
339
340
341
342
343
344
345
dnl Synopsis:
dnl PAC_FUNC_SEMCTL
dnl
dnl Output Effects:
dnl Sets 'HAVE_SEMCTL' if semctl is available.
dnl Sets 'HAVE_UNION_SEMUN' if 'union semun' is available.
dnl Sets 'SEMCTL_NEEDS_SEMUN' if a 'union semun' type must be passed as the
dnl fourth argument to 'semctl'.
gropp's avatar
gropp committed
346
dnl D*/ 
347
348
dnl Check for semctl and arguments
AC_DEFUN(PAC_FUNC_SEMCTL,[
gropp's avatar
gropp committed
349
350
351
352
353
AC_CHECK_FUNC(semctl)
if test "$ac_cv_func_semctl" = "yes" ; then
    AC_CACHE_CHECK([for union semun],
    pac_cv_type_union_semun,[
    AC_TRY_COMPILE([#include <sys/types.h>
354
355
#include <sys/ipc.h>
#include <sys/sem.h>],[union semun arg;arg.val=0;],
gropp's avatar
gropp committed
356
357
    pac_cv_type_union_semun="yes",pac_cv_type_union_semun="no")])
    if test "$pac_cv_type_union_semun" = "yes" ; then
358
        AC_DEFINE(HAVE_UNION_SEMUN,1,[Has union semun])
gropp's avatar
gropp committed
359
360
361
362
363
        #
        # See if we can use an int in semctl or if we need the union
        AC_CACHE_CHECK([whether semctl needs union semun],
        pac_cv_func_semctl_needs_semun,[
        AC_TRY_COMPILE([#include <sys/types.h>
364
365
366
#include <sys/ipc.h>
#include <sys/sem.h>],[
int arg = 0; semctl( 1, 1, SETVAL, arg );],
gropp's avatar
gropp committed
367
368
369
370
        pac_cv_func_semctl_needs_semun="yes",
        pac_cv_func_semctl_needs_semun="no")
        ])
        if test "$pac_cv_func_semctl_needs_semun" = "yes" ; then
371
            AC_DEFINE(SEMCTL_NEEDS_SEMUN,1,[Needs an explicit definition of semun])
gropp's avatar
gropp committed
372
373
        fi
    fi
374
375
376
377
378
379
380
381
382
383
fi
])
dnl
dnl/*D
dnl PAC_C_VOLATILE - Check if C supports volatile
dnl
dnl Synopsis:
dnl PAC_C_VOLATILE
dnl
dnl Output Effect:
gropp's avatar
gropp committed
384
dnl Defines 'volatile' as empty if volatile is not available.
385
dnl
gropp's avatar
gropp committed
386
dnl D*/
387
388
389
390
391
AC_DEFUN(PAC_C_VOLATILE,[
AC_CACHE_CHECK([for volatile],
pac_cv_c_volatile,[
AC_TRY_COMPILE(,[volatile int a;],pac_cv_c_volatile="yes",
pac_cv_c_volatile="no")])
gropp's avatar
gropp committed
392
if test "$pac_cv_c_volatile" = "no" ; then
gropp's avatar
gropp committed
393
    AC_DEFINE(volatile,,[if C does not support volatile])
394
395
396
397
fi
])dnl
dnl
dnl/*D
gropp's avatar
gropp committed
398
399
400
401
402
403
404
405
dnl PAC_C_INLINE - Check if C supports inline
dnl
dnl Synopsis:
dnl PAC_C_INLINE
dnl
dnl Output Effect:
dnl Defines 'inline' as empty if inline is not available.
dnl
gropp's avatar
gropp committed
406
dnl D*/
gropp's avatar
gropp committed
407
408
409
410
411
412
AC_DEFUN(PAC_C_INLINE,[
AC_CACHE_CHECK([for inline],
pac_cv_c_inline,[
AC_TRY_COMPILE([inline int a( int b ){return b+1;}],[int a;],
pac_cv_c_inline="yes",pac_cv_c_inline="no")])
if test "$pac_cv_c_inline" = "no" ; then
gropp's avatar
gropp committed
413
    AC_DEFINE(inline,,[if C does not support inline])
gropp's avatar
gropp committed
414
415
416
417
fi
])dnl
dnl
dnl/*D
418
419
420
421
422
423
424
425
426
dnl PAC_C_CPP_CONCAT - Check whether the C compiler accepts ISO CPP string
dnl   concatenation
dnl
dnl Synopsis:
dnl PAC_C_CPP_CONCAT([true-action],[false-action])
dnl
dnl Output Effects:
dnl Invokes the true or false action
dnl
gropp's avatar
gropp committed
427
dnl D*/
428
429
AC_DEFUN(PAC_C_CPP_CONCAT,[
pac_pound="#"
430
AC_CACHE_CHECK([whether the compiler $CC accepts $ac_pound$ac_pound for concatenation in cpp],
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
pac_cv_c_cpp_concat,[
AC_TRY_COMPILE([
#define concat(a,b) a##b],[int concat(a,b);return ab;],
pac_cv_cpp_concat="yes",pac_cv_cpp_concat="no")])
if test $pac_cv_c_cpp_concat = "yes" ; then
    ifelse([$1],,:,[$1])
else
    ifelse([$2],,:,[$2])
fi
])dnl
dnl
dnl/*D
dnl PAC_FUNC_GETTIMEOFDAY - Check whether gettimeofday takes 1 or 2 arguments
dnl
dnl Synopsis
dnl  PAC_IS_GETTIMEOFDAY_OK(ok_action,failure_action)
dnl
dnl Notes:
dnl One version of Solaris accepted only one argument.
dnl
gropp's avatar
gropp committed
451
dnl D*/
452
453
454
455
456
457
458
459
460
461
462
463
464
AC_DEFUN(PAC_FUNC_GETTIMEOFDAY,[
AC_CACHE_CHECK([whether gettimeofday takes 2 arguments],
pac_cv_func_gettimeofday,[
AC_TRY_COMPILE([#include <sys/time.h>],[struct timeval tp;
gettimeofday(&tp,(void*)0);return 0;],pac_cv_func_gettimeofday="yes",
pac_cv_func_gettimeofday="no")
])
if test "$pac_cv_func_gettimeofday" = "yes" ; then
     ifelse($1,,:,$1)
else
     ifelse($2,,:,$2)
fi
])
465
466
467
468
469
470
471
472
473
474
475
476
477
dnl
dnl/*D
dnl PAC_C_RESTRICT - Check if C supports restrict
dnl
dnl Synopsis:
dnl PAC_C_RESTRICT
dnl
dnl Output Effect:
dnl Defines 'restrict' if some version of restrict is supported; otherwise
dnl defines 'restrict' as empty.  This allows you to include 'restrict' in 
dnl declarations in the same way that 'AC_C_CONST' allows you to use 'const'
dnl in declarations even when the C compiler does not support 'const'
dnl
gropp's avatar
gropp committed
478
479
480
dnl Note that some compilers accept restrict only with additional options.
dnl DEC/Compaq/HP Alpha Unix (Tru64 etc.) -accept restrict_keyword
dnl
gropp's avatar
gropp committed
481
dnl D*/
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
AC_DEFUN(PAC_C_RESTRICT,[
AC_CACHE_CHECK([for restrict],
pac_cv_c_restrict,[
AC_TRY_COMPILE(,[int * restrict a;],pac_cv_c_restrict="restrict",
pac_cv_c_restrict="no")
if test "$pac_cv_c_restrict" = "no" ; then
   AC_TRY_COMPILE(,[int * _Restrict a;],pac_cv_c_restrict="_Restrict",
   pac_cv_c_restrict="no")
fi
if test "$pac_cv_c_restrict" = "no" ; then
   AC_TRY_COMPILE(,[int * __restrict a;],pac_cv_c_restrict="__restrict",
   pac_cv_c_restrict="no")
fi
])
if test "$pac_cv_c_restrict" = "no" ; then
497
  restrict_val=""
498
elif test "$pac_cv_c_restrict" != "restrict" ; then
499
500
501
502
  restrict_val=$pac_cv_c_restrict
fi
if test "$restrict_val" != "restrict" ; then 
  AC_DEFINE_UNQUOTED(restrict,$restrict_val,[if C does not support restrict])
503
504
fi
])dnl
gropp's avatar
gropp committed
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
dnl
dnl/*D
dnl PAC_HEADER_STDARG - Check whether standard args are defined and whether
dnl they are old style or new style
dnl
dnl Synopsis:
dnl PAC_HEADER_STDARG(action if works, action if oldstyle, action if fails)
dnl
dnl Output Effects:
dnl Defines HAVE_STDARG_H if the header exists.
dnl defines 
dnl
dnl Notes:
dnl It isn't enough to check for stdarg.  Even gcc doesn't get it right;
dnl on some systems, the gcc version of stdio.h loads stdarg.h `with the wrong
dnl options` (causing it to choose the `old style` 'va_start' etc).
dnl
dnl The original test tried the two-arg version first; the old-style
dnl va_start took only a single arg.
dnl This turns out to be VERY tricky, because some compilers (e.g., Solaris) 
dnl are quite happy to accept the *wrong* number of arguments to a macro!
dnl Instead, we try to find a clean compile version, using our special
dnl PAC_C_TRY_COMPILE_CLEAN command.
dnl
gropp's avatar
gropp committed
529
dnl D*/
gropp's avatar
gropp committed
530
AC_DEFUN(PAC_HEADER_STDARG,[
gropp's avatar
gropp committed
531
AC_CHECK_HEADER(stdarg.h)
gropp's avatar
gropp committed
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
dnl Sets ac_cv_header_stdarg_h
if test "$ac_cv_header_stdarg_h" = "yes" ; then
    dnl results are yes,oldstyle,no.
    AC_CACHE_CHECK([whether stdarg is oldstyle],
    pac_cv_header_stdarg_oldstyle,[
PAC_C_TRY_COMPILE_CLEAN([#include <stdio.h>
#include <stdarg.h>],
[int func( int a, ... ){
int b;
va_list ap;
va_start( ap );
b = va_arg(ap, int);
printf( "%d-%d\n", a, b );
va_end(ap);
fflush(stdout);
return 0;
}
int main() { func( 1, 2 ); return 0;}],pac_check_compile)
gropp's avatar
gropp committed
550
case "$pac_check_compile" in 
gropp's avatar
gropp committed
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
    0)  pac_cv_header_stdarg_oldstyle="yes"
	;;
    1)  pac_cv_header_stdarg_oldstyle="may be newstyle"
	;;
    2)  pac_cv_header_stdarg_oldstyle="no"   # compile failed
	;;
esac
])
if test "$pac_cv_header_stdarg_oldstyle" = "yes" ; then
    ifelse($2,,:,[$2])
else
    AC_CACHE_CHECK([whether stdarg works],
    pac_cv_header_stdarg_works,[
    PAC_C_TRY_COMPILE_CLEAN([
#include <stdio.h>
#include <stdarg.h>],[
int func( int a, ... ){
int b;
va_list ap;
va_start( ap, a );
b = va_arg(ap, int);
printf( "%d-%d\n", a, b );
va_end(ap);
fflush(stdout);
return 0;
}
int main() { func( 1, 2 ); return 0;}],pac_check_compile)
gropp's avatar
gropp committed
578
case "$pac_check_compile" in 
gropp's avatar
gropp committed
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
    0)  pac_cv_header_stdarg_works="yes"
	;;
    1)  pac_cv_header_stdarg_works="yes with warnings"
	;;
    2)  pac_cv_header_stdarg_works="no"
	;;
esac
])
fi   # test on oldstyle
if test "$pac_cv_header_stdarg_works" = "no" ; then
    ifelse($3,,:,[$3])
else
    ifelse($1,,:,[$1])
fi
else 
    ifelse($3,,:,[$3])
fi  # test on header
])
dnl/*D
dnl PAC_C_TRY_COMPILE_CLEAN - Try to compile a program, separating success
dnl with no warnings from success with warnings.
dnl
dnl Synopsis:
dnl PAC_C_TRY_COMPILE_CLEAN(header,program,flagvar)
dnl
dnl Output Effect:
dnl The 'flagvar' is set to 0 (clean), 1 (dirty but success ok), or 2
dnl (failed).
dnl
gropp's avatar
gropp committed
608
dnl D*/
gropp's avatar
gropp committed
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
AC_DEFUN(PAC_C_TRY_COMPILE_CLEAN,[
$3=2
dnl Get the compiler output to test against
if test -z "$pac_TRY_COMPLILE_CLEAN" ; then
    rm -f conftest*
    echo 'int try(void);int try(void){return 0;}' > conftest.c
    if ${CC-cc} $CFLAGS -c conftest.c >conftest.bas 2>&1 ; then
	if test -s conftest.bas ; then 
	    pac_TRY_COMPILE_CLEAN_OUT=`cat conftest.bas`
        fi
        pac_TRY_COMPILE_CLEAN=1
    else
	AC_MSG_WARN([Could not compile simple test program!])
	if test -s conftest.bas ; then 	cat conftest.bas >> config.log ; fi
    fi
fi
dnl
dnl Create the program that we need to test with
rm -f conftest*
cat >conftest.c <<EOF
#include "confdefs.h"
[$1]
[$2]
EOF
dnl
dnl Compile it and test
if ${CC-cc} $CFLAGS -c conftest.c >conftest.bas 2>&1 ; then
    dnl Success.  Is the output the same?
    if test "$pac_TRY_COMPILE_CLEAN_OUT" = "`cat conftest.bas`" ; then
	$3=0
    else
        cat conftest.c >>config.log
	if test -s conftest.bas ; then 	cat conftest.bas >> config.log ; fi
        $3=1
    fi
else
    dnl Failure.  Set flag to 2
    cat conftest.c >>config.log
    if test -s conftest.bas ; then cat conftest.bas >> config.log ; fi
    $3=2
fi
rm -f conftest*
])
gropp's avatar
gropp committed
652
653
654
655
656
657
658
659
660
661
662
dnl
dnl/*D
dnl PAC_PROG_C_UNALIGNED_DOUBLES - Check that the C compiler allows unaligned
dnl doubles
dnl
dnl Synopsis:
dnl   PAC_PROG_C_UNALIGNED_DOUBLES(action-if-true,action-if-false,
dnl       action-if-unknown)
dnl
dnl Notes:
dnl 'action-if-unknown' is used in the case of cross-compilation.
gropp's avatar
gropp committed
663
dnl D*/
gropp's avatar
gropp committed
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
AC_DEFUN(PAC_PROG_C_UNALIGNED_DOUBLES,[
AC_CACHE_CHECK([whether C compiler allows unaligned doubles],
pac_cv_prog_c_unaligned_doubles,[
AC_TRY_RUN([
void fetch_double( v )
double *v;
{
*v = 1.0;
}
int main( argc, argv )
int argc;
char **argv;
{
int p[4];
double *p_val;
fetch_double( (double *)&(p[0]) );
p_val = (double *)&(p[0]);
if (*p_val != 1.0) return 1;
fetch_double( (double *)&(p[1]) );
p_val = (double *)&(p[1]);
if (*p_val != 1.0) return 1;
return 0;
}
],pac_cv_prog_c_unaligned_doubles="yes",pac_cv_prog_c_unaligned_doubles="no",
pac_cv_prog_c_unaligned_doubles="unknown")])
ifelse($1,,,if test "X$pac_cv_prog_c_unaligned_doubles" = "yes" ; then 
$1
fi)
ifelse($2,,,if test "X$pac_cv_prog_c_unaligned_doubles" = "no" ; then 
$2
fi)
ifelse($3,,,if test "X$pac_cv_prog_c_unaligned_doubles" = "unknown" ; then 
$3
fi)
])
dnl
dnl/*D 
dnl PAC_PROG_C_WEAK_SYMBOLS - Test whether C supports weak symbols.
dnl
dnl Synopsis
dnl PAC_PROG_C_WEAK_SYMBOLS(action-if-true,action-if-false)
dnl
dnl Output Effect:
dnl Defines one of the following if a weak symbol pragma is found:
dnl.vb
dnl    HAVE_PRAGMA_WEAK - #pragma weak
dnl    HAVE_PRAGMA_HP_SEC_DEF - #pragma _HP_SECONDARY_DEF
711
dnl    HAVE_PRAGMA_CRI_DUP  - #pragma _CRI duplicate x as y
gropp's avatar
gropp committed
712
dnl.ve
713
714
715
716
717
dnl May also define
dnl.vb
dnl    HAVE_WEAK_ATTRIBUTE
dnl.ve
dnl if functions can be declared as 'int foo(...) __attribute__ ((weak));'
718
dnl sets the shell variable pac_cv_attr_weak to yes.
gropp's avatar
gropp committed
719
dnl 
gropp's avatar
gropp committed
720
dnl D*/
gropp's avatar
gropp committed
721
AC_DEFUN(PAC_PROG_C_WEAK_SYMBOLS,[
722
pragma_extra_message=""
gropp's avatar
gropp committed
723
724
725
726
727
728
AC_CACHE_CHECK([for type of weak symbol support],
pac_cv_prog_c_weak_symbols,[
# Test for weak symbol support...
# We can't put # in the message because it causes autoconf to generate
# incorrect code
AC_TRY_LINK([
gropp's avatar
gropp committed
729
extern int PFoo(int);
gropp's avatar
gropp committed
730
#pragma weak PFoo = Foo
731
int Foo(int a) { return a; }
732
733
734
735
],[return PFoo(1);],has_pragma_weak=yes)
#
# Some systems (Linux ia64 and ecc, for example), support weak symbols
# only within a single object file!  This tests that case.
gropp's avatar
gropp committed
736
737
738
# Note that there is an extern int PFoo declaration before the
# pragma.  Some compilers require this in order to make the weak symbol
# extenally visible.  
739
740
741
if test "$has_pragma_weak" = yes ; then
    rm -f conftest*
    cat >>conftest1.c <<EOF
gropp's avatar
gropp committed
742
extern int PFoo(int);
743
744
#pragma weak PFoo = Foo
int Foo(int);
745
int Foo(int a) { return a; }
746
747
EOF
    cat >>conftest2.c <<EOF
gropp's avatar
gropp committed
748
extern int PFoo(int);
749
int main(int argc, char **argv) {
750
751
752
753
return PFoo(0);}
EOF
    ac_link2='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest1.c conftest2.c $LIBS >conftest.out 2>&1'
    if eval $ac_link2 ; then
754
755
756
757
758
759
760
761
762
763
764
765
766
        # The gcc 3.4.x compiler accepts the pragma weak, but does not
        # correctly implement it on systems where the loader doesn't 
        # support weak symbols (e.g., cygwin).  This is a bug in gcc, but it
        # it is one that *we* have to detect.
        rm -f conftest*
        cat >>conftest1.c <<EOF
extern int PFoo(int);
#pragma weak PFoo = Foo
int Foo(int);
int Foo(int a) { return a; }
EOF
    cat >>conftest2.c <<EOF
extern int Foo(int);
767
int PFoo(int a) { return a+1;}
768
769
770
771
772
773
774
775
776
777
778
779
780
781
int main(int argc, char **argv) {
return Foo(0);}
EOF
        if eval $ac_link2 ; then
            pac_cv_prog_c_weak_symbols="pragma weak"
        else 
            echo "$ac_link2" >> config.log
	    echo "Failed program was" >> config.log
            cat conftest1.c >>config.log
            cat conftest2.c >>config.log
            if test -s conftest.out ; then cat conftest.out >> config.log ; fi
            has_pragma_weak=0
            pragma_extra_message="pragma weak accepted but does not work (probably creates two non-weak entries)"
        fi
782
783
784
785
786
787
788
789
790
791
792
    else
      echo "$ac_link2" >>config.log
      echo "Failed program was" >>config.log
      cat conftest1.c >>config.log
      cat conftest2.c >>config.log
      if test -s conftest.out ; then cat conftest.out >> config.log ; fi
      has_pragma_weak=0
      pragma_extra_message="pragma weak does not work outside of a file"
    fi
    rm -f conftest*
fi
gropp's avatar
gropp committed
793
794
795
dnl
if test -z "$pac_cv_prog_c_weak_symbols" ; then 
    AC_TRY_LINK([
gropp's avatar
gropp committed
796
extern int PFoo(int);
gropp's avatar
gropp committed
797
#pragma _HP_SECONDARY_DEF Foo  PFoo
798
int Foo(int a) { return a; }
gropp's avatar
gropp committed
799
800
801
802
803
],[return PFoo(1);],pac_cv_prog_c_weak_symbols="pragma _HP_SECONDARY_DEF")
fi
dnl
if test -z "$pac_cv_prog_c_weak_symbols" ; then
    AC_TRY_LINK([
gropp's avatar
gropp committed
804
extern int PFoo(int);
gropp's avatar
gropp committed
805
#pragma _CRI duplicate PFoo as Foo
806
int Foo(int a) { return a; }
gropp's avatar
gropp committed
807
808
809
810
811
812
813
],[return PFoo(1);],pac_cv_prog_c_weak_symbols="pragma _CRI duplicate x as y")
fi
dnl
if test -z "$pac_cv_prog_c_weak_symbols" ; then
    pac_cv_prog_c_weak_symbols="no"
fi
dnl
814
815
816
817
818
819
dnl If there is an extra explanatory message, echo it now so that it
dnl doesn't interfere with the cache result value
if test -n "$pragma_extra_message" ; then
    echo $pragma_extra_message
fi
dnl
gropp's avatar
gropp committed
820
])
gropp's avatar
gropp committed
821
822
823
824
if test "$pac_cv_prog_c_weak_symbols" = "no" ; then
    ifelse([$2],,:,[$2])
else
    case "$pac_cv_prog_c_weak_symbols" in
825
	"pragma weak") AC_DEFINE(HAVE_PRAGMA_WEAK,1,[Supports weak pragma]) 
gropp's avatar
gropp committed
826
	;;
827
	"pragma _HP")  AC_DEFINE(HAVE_PRAGMA_HP_SEC_DEF,1,[HP style weak pragma])
gropp's avatar
gropp committed
828
	;;
829
	"pragma _CRI") AC_DEFINE(HAVE_PRAGMA_CRI_DUP,1,[Cray style weak pragma])
gropp's avatar
gropp committed
830
831
832
833
	;;
    esac
    ifelse([$1],,:,[$1])
fi
834
835
836
837
838
839
AC_CACHE_CHECK([whether __attribute__ ((weak)) allowed],
pac_cv_attr_weak,[
AC_TRY_COMPILE([int foo(int) __attribute__ ((weak));],[int a;],
pac_cv_attr_weak=yes,pac_cv_attr_weak=no)])
])

gropp's avatar
gropp committed
840
841
842
#
# This is a replacement that checks that FAILURES are signaled as well
# (later configure macros look for the .o file, not just success from the
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
# compiler, but they should not HAVE to
#
dnl --- insert 2.52 compatibility here ---
dnl 2.52 does not have AC_PROG_CC_WORKS
ifdef([AC_PROG_CC_WORKS],,[AC_DEFUN([AC_PROG_CC_WORKS],)])
dnl
AC_DEFUN(PAC_PROG_CC_WORKS,
[AC_PROG_CC_WORKS
AC_MSG_CHECKING([whether the C compiler sets its return status correctly])
AC_LANG_SAVE
AC_LANG_C
AC_TRY_COMPILE(,[int a = bzzzt;],notbroken=no,notbroken=yes)
AC_MSG_RESULT($notbroken)
if test "$notbroken" = "no" ; then
    AC_MSG_ERROR([installation or configuration problem: C compiler does not
correctly set error code when a fatal error occurs])
fi
])
dnl
dnl/*D 
dnl PAC_PROG_C_MULTIPLE_WEAK_SYMBOLS - Test whether C and the
dnl linker allow multiple weak symbols.
dnl
dnl Synopsis
dnl PAC_PROG_C_MULTIPLE_WEAK_SYMBOLS(action-if-true,action-if-false)
dnl
dnl 
dnl D*/
AC_DEFUN(PAC_PROG_C_MULTIPLE_WEAK_SYMBOLS,[
AC_CACHE_CHECK([for multiple weak symbol support],
pac_cv_prog_c_multiple_weak_symbols,[
# Test for multiple weak symbol support...
#
rm -f conftest*
cat >>conftest1.c <<EOF
extern int PFoo(int);
extern int PFoo_(int);
extern int pfoo_(int);
#pragma weak PFoo = Foo
#pragma weak PFoo_ = Foo
#pragma weak pfoo_ = Foo
int Foo(int);
int Foo(a) { return a; }
EOF
cat >>conftest2.c <<EOF
extern int PFoo(int), PFoo_(int), pfoo_(int);
int main() {
return PFoo(0) + PFoo_(1) + pfoo_(2);}
EOF
ac_link2='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest1.c conftest2.c $LIBS >conftest.out 2>&1'
if eval $ac_link2 ; then
    pac_cv_prog_c_multiple_weak_symbols="yes"
else
    echo "$ac_link2" >>config.log
    echo "Failed program was" >>config.log
    cat conftest1.c >>config.log
    cat conftest2.c >>config.log
    if test -s conftest.out ; then cat conftest.out >> config.log ; fi
fi
rm -f conftest*
dnl
])
if test "$pac_cv_prog_c_multiple_weak_symbols" = "yes" ; then
    ifelse([$1],,:,[$1])
else
    ifelse([$2],,:,[$2])
fi
])
gropp's avatar
gropp committed
911
912
913
914
915
916
917
918
919
920
921
922
dnl
dnl/*D
dnl PAC_FUNC_CRYPT - Check that the function crypt is defined
dnl
dnl Synopsis:
dnl PAC_FUNC_CRYPT
dnl
dnl Output Effects:
dnl 
dnl In Solaris, the crypt function is not defined in unistd unless 
dnl _XOPEN_SOURCE is defines and _XOPEN_VERSION is 4 or greater.
dnl We test by looking for a missing crypt by defining our own
gropp's avatar
gropp committed
923
924
dnl incompatible one and trying to compile it.
dnl Defines NEED_CRYPT_PROTOTYPE if no prototype is found.
gropp's avatar
gropp committed
925
dnl D*/
gropp's avatar
gropp committed
926
AC_DEFUN(PAC_FUNC_CRYPT,[
927
AC_CACHE_CHECK([whether crypt defined in unistd.h],
gropp's avatar
gropp committed
928
929
930
931
932
933
934
pac_cv_func_crypt_defined,[
AC_TRY_COMPILE([
#include <unistd.h>
double crypt(double a){return a;}],[return 0];,
pac_cv_func_crypt_defined="no",pac_cv_func_crypt_defined="yes")])
if test "$pac_cv_func_crypt_defined" = "no" ; then
    # check to see if defining _XOPEN_SOURCE helps
935
    AC_CACHE_CHECK([whether crypt defined in unistd with _XOPEN_SOURCE],
gropp's avatar
gropp committed
936
937
938
939
940
941
942
943
pac_cv_func_crypt_xopen,[
    AC_TRY_COMPILE([
#define _XOPEN_SOURCE    
#include <unistd.h>
double crypt(double a){return a;}],[return 0];,
pac_cv_func_crypt_xopen="no",pac_cv_func_crypt_xopen="yes")])
fi
if test "$pac_cv_func_crypt_xopen" = "yes" ; then
944
    AC_DEFINE(_XOPEN_SOURCE,1,[if xopen needed for crypt])
gropp's avatar
gropp committed
945
elif test "$pac_cv_func_crypt_defined" = "no" ; then
946
    AC_DEFINE(NEED_CRYPT_PROTOTYPE,1,[if a prototype for crypt is needed])
gropp's avatar
gropp committed
947
948
fi
])dnl
gropp's avatar
gropp committed
949
950
951
952
953
954
955
956
957
dnl/*D
dnl PAC_ARG_STRICT - Add --enable-strict to configure.  
dnl
dnl Synopsis:
dnl PAC_ARG_STRICT
dnl 
dnl Output effects:
dnl Adds '--enable-strict' to the command line.  If this is enabled, then
dnl if no compiler has been set, set 'CC' to 'gcc'.
gropp's avatar
gropp committed
958
dnl If the compiler is 'gcc', 'COPTIONS' is set to include
gropp's avatar
gropp committed
959
dnl.vb
960
dnl	-O -Wall -Wstrict-prototypes -Wmissing-prototypes -DGCC_WALL -std=c89
gropp's avatar
gropp committed
961
dnl.ve
gropp's avatar
gropp committed
962
dnl
963
964
965
dnl -std=c89 is used to select the C89 version of the ANSI/ISO C standard.
dnl As of this writing, many C compilers still accepted only this version,
dnl not the later C99 version.  When all compilers accept C99, this 
966
967
968
969
dnl should be changed to the appropriate standard level.  Note that we've
dnl had trouble with gcc 2.95.3 accepting -std=c89 but then trying to 
dnl compile program with a invalid set of options 
dnl (-D __STRICT_ANSI__-trigraphs)
970
dnl
gropp's avatar
gropp committed
971
972
973
974
975
dnl If the value 'all' is given to '--enable-strict', additional warning
dnl options are included.  These are
dnl.vb
dnl -Wunused -Wshadow -Wmissing-declarations -Wno-long-long -Wpointer-arith
dnl.ve
gropp's avatar
gropp committed
976
dnl 
gropp's avatar
gropp committed
977
978
979
980
dnl If the value 'noopt' is given to '--enable-strict', no optimization
dnl options are set.  For some compilers (including gcc), this may 
dnl cause some strict complication tests to be skipped (typically, these are
dnl tests for unused variables or variables used before they are defined).
981
dnl
982
983
dnl If the value 'posix' is given to '--enable-strict', POSIX is selected
dnl as the C dialect (including the definition for the POSIX level)
gropp's avatar
gropp committed
984
dnl 
gropp's avatar
gropp committed
985
986
987
dnl This only works where 'gcc' is available.
dnl In addition, it exports the variable 'enable_strict_done'. This
dnl ensures that subsidiary 'configure's do not add the above flags to
gropp's avatar
gropp committed
988
989
dnl 'COPTIONS' once the top level 'configure' sees '--enable-strict'.  To ensure
dnl this, 'COPTIONS' is also exported.
gropp's avatar
gropp committed
990
991
992
993
994
dnl
dnl Not yet available: options when using other compilers.  However, 
dnl here are some possible choices
dnl Solaris cc
dnl  -fd -v -Xc
995
996
dnl -Xc is strict ANSI (some version) and does not allow "long long", for 
dnl example
997
998
dnl IRIX
dnl  -ansi -DEBUG:trap_uninitialized=ON:varargs_interface_check=ON:verbose_runtime=ON
gropp's avatar
gropp committed
999
dnl
gropp's avatar
gropp committed
1000
dnl D*/
gropp's avatar
gropp committed
1001
1002
1003
AC_DEFUN(PAC_ARG_STRICT,[
AC_ARG_ENABLE(strict,
[--enable-strict  - Turn on strict compilation testing when using gcc])
gropp's avatar
gropp committed
1004
saveCFLAGS="$CFLAGS"
gropp's avatar
gropp committed
1005
if test "$enable_strict_done" != "yes" ; then
1006
    if test -z "$GCC_OPTFLAG" ; then GCC_OPTFLAG="-O2" ; fi
gropp's avatar
gropp committed
1007
1008
1009
1010
1011
1012
1013
    if test -z "CC" ; then
        AC_CHECK_PROGS(CC,gcc)
    fi
    case "$enable_strict" in 
	yes)
        enable_strict_done="yes"
        if test "$CC" = "gcc" ; then 
1014
            COPTIONS="${COPTIONS} -Wall $GCC_OPTFLAG -Wstrict-prototypes -Wmissing-prototypes -DGCC_WALL -std=c89"
gropp's avatar
gropp committed
1015
1016
1017
        fi
	;;
	all)
gropp's avatar
gropp committed
1018
        enable_strict_done="yes"
gropp's avatar
gropp committed
1019
        if test "$CC" = "gcc" ; then 
1020
1021
1022
	    # Note that -Wall does not include all of the warnings that
	    # the gcc documentation claims that it does; in particular,
	    # the -Wunused-parameter option is *not* part of -Wall
1023
            COPTIONS="${COPTIONS} -Wall $GCC_OPTFLAG -Wstrict-prototypes -Wmissing-prototypes -DGCC_WALL -Wunused -Wshadow -Wmissing-declarations -Wno-long-long -Wunused-parameter -Wunused-value -std=c89"
gropp's avatar
gropp committed
1024
        fi
gropp's avatar
gropp committed
1025
	;;
1026
1027
1028
1029

	posix)
	enable_strict_done="yes"
        if test "$CC" = "gcc" ; then
1030
            COPTIONS="${COPTIONS} -Wall $GCC_OPTFLAG -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wpointer-arith -Wbad-function-cast -ansi -DGCC_WALL -D_POSIX_C_SOURCE=199506L -std=c89"
1031
1032
1033
    	fi
 	;;	
	
gropp's avatar
gropp committed
1034
	noopt)
gropp's avatar
gropp committed
1035
        enable_strict_done="yes"
gropp's avatar
gropp committed
1036
        if test "$CC" = "gcc" ; then 
1037
            COPTIONS="${COPTIONS} -Wall -Wstrict-prototypes -Wmissing-prototypes -DGCC_WALL -std=c89"
gropp's avatar
gropp committed
1038
        fi
gropp's avatar
gropp committed
1039
	;;
gropp's avatar
gropp committed
1040
1041
1042
1043
	no)
	# Accept and ignore this value
	:
	;;
gropp's avatar
gropp committed
1044
	*)
gropp's avatar
gropp committed
1045
1046
1047
1048
	# Silently accept blank values for enable strict
	if test -n "$enable_strict" ; then
  	    AC_MSG_WARN([Unrecognized value for enable-strict:$enable_strict])
	fi
gropp's avatar
gropp committed
1049
1050
	;;
    esac
gropp's avatar
gropp committed
1051
fi
gropp's avatar
gropp committed
1052
export enable_strict_done
gropp's avatar
gropp committed
1053
])
gropp's avatar
gropp committed
1054
1055
dnl
dnl Use the value of enable-strict to update CFLAGS
1056
1057
1058
1059
1060
1061
1062
1063
1064
dnl
dnl -std=c89 is used to select the C89 version of the ANSI/ISO C standard.
dnl As of this writing, many C compilers still accepted only this version,
dnl not the later C99 version.  When all compilers accept C99, this 
dnl should be changed to the appropriate standard level.  Note that we've
dnl had trouble with gcc 2.95.3 accepting -std=c89 but then trying to 
dnl compile program with a invalid set of options 
dnl (-D __STRICT_ANSI__-trigraphs)
dnl
gropp's avatar
gropp committed
1065
dnl 
gropp's avatar
gropp committed
1066
1067
1068
AC_DEFUN(PAC_CC_STRICT,[
export enable_strict_done
if test "$enable_strict_done" != "yes" ; then
gropp's avatar
gropp committed
1069
    # We must know the compiler type
1070
    if test -z "$GCC_OPTFLAG" ; then GCC_OPTFLAG="-O2" ; fi
gropp's avatar
gropp committed
1071
1072
1073
1074
1075
    if test -z "CC" ; then
        AC_CHECK_PROGS(CC,gcc)
    fi
    case "$enable_strict" in 
	yes)
gropp's avatar
gropp committed
1076
1077
        enable_strict_done="yes"
        if test "$ac_cv_prog_gcc" = "yes" ; then 
1078
            CFLAGS="${CFLAGS} -Wall $GCC_OPTFLAG -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wpointer-arith -Wbad-function-cast -ansi -DGCC_WALL"
gropp's avatar
gropp committed
1079
	    AC_MSG_RESULT([Adding strict check arguments to CFLAGS])
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
	    AC_MSG_CHECKING([whether we can add -std=c89])
            # See if we can add -std=c89
            savCFLAGS=$CFLAGS
            CFLAGS="$CFLAGS -std=c89"
            AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[int a;])],
                  stdc_ok=yes,
                  stdc_ok=no)
            AC_MSG_RESULT($stdc_ok)
            if test "$stdc_ok" != yes ; then
                CFLAGS="$savCFLAGS"
            fi
gropp's avatar
gropp committed
1091
1092
1093
	else 
	    AC_MSG_WARN([enable strict supported only for gcc])
    	fi
gropp's avatar
gropp committed
1094
1095
 	;;	
	all)
gropp's avatar
gropp committed
1096
1097
        enable_strict_done="yes"
        if test "$ac_cv_prog_gcc" = "yes" ; then 
1098
            CFLAGS="${CFLAGS} -Wall $GCC_OPTFLAG -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wpointer-arith -Wbad-function-cast -ansi -DGCC_WALL -Wunused -Wshadow -Wmissing-declarations -Wunused-parameter -Wunused-value -Wno-long-long"
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
	    AC_MSG_CHECKING([whether we can add -std=c89])
            # See if we can add -std=c89
            savCFLAGS=$CFLAGS
            CFLAGS="$CFLAGS -std=c89"
            AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[int a;])],
                  stdc_ok=yes,
                  stdc_ok=no)
            AC_MSG_RESULT($stdc_ok)
            if test "$stdc_ok" != yes ; then
                CFLAGS="$savCFLAGS"
            fi
gropp's avatar
gropp committed
1110
1111
1112
	else 
	    AC_MSG_WARN([enable strict supported only for gcc])
    	fi
gropp's avatar
gropp committed
1113
	;;
1114
1115
1116
1117

	posix)
	enable_strict_done="yes"
        if test "$ac_cv_prog_gcc" = "yes" ; then 
1118
            CFLAGS="${CFLAGS} -Wall $GCC_OPTFLAG -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wpointer-arith -Wbad-function-cast -ansi -DGCC_WALL -D_POSIX_C_SOURCE=199506L"
1119
	    AC_MSG_RESULT([Adding strict check arguments (POSIX flavor) to CFLAGS])
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
	    AC_MSG_CHECKING([whether we can add -std=c89])
            # See if we can add -std=c89
            savCFLAGS=$CFLAGS
            CFLAGS="$CFLAGS -std=c89"
            AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[int a;])],
                  stdc_ok=yes,
                  stdc_ok=no)
            AC_MSG_RESULT($stdc_ok)
            if test "$stdc_ok" != yes ; then
                CFLAGS="$savCFLAGS"
            fi
1131
1132
1133
1134
1135
	else 
	    AC_MSG_WARN([enable strict supported only for gcc])
    	fi
 	;;	
	
gropp's avatar
gropp committed
1136
1137
1138
	noopt)
        enable_strict_done="yes"
        if test "$ac_cv_prog_gcc" = "yes" ; then 
1139
            CFLAGS="${CFLAGS} -Wall -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wpointer-arith -Wbad-function-cast -ansi -DGCC_WALL"
gropp's avatar
gropp committed
1140
	    AC_MSG_RESULT([Adding strict check arguments to CFLAGS])
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
	    AC_MSG_CHECKING([whether we can add -std=c89])
            # See if we can add -std=c89
            savCFLAGS=$CFLAGS
            CFLAGS="$CFLAGS -std=c89"
            AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[int a;])],
                  stdc_ok=yes,
                  stdc_ok=no)
            AC_MSG_RESULT($stdc_ok)
            if test "$stdc_ok" != yes ; then
                CFLAGS="$savCFLAGS"
            fi
gropp's avatar
gropp committed
1152
1153
1154
1155
	else 
	    AC_MSG_WARN([enable strict supported only for gcc])
    	fi
	;;
gropp's avatar
gropp committed
1156
1157
1158
1159
	no)
	# Accept and ignore this value
	:
	;;
gropp's avatar
gropp committed
1160
	*)
gropp's avatar
gropp committed
1161
1162
1163
	if test -n "$enable_strict" ; then
  	    AC_MSG_WARN([Unrecognized value for enable-strict:$enable_strict])
	fi
gropp's avatar
gropp committed
1164
1165
	;;
    esac	
gropp's avatar
gropp committed
1166
1167
fi
])
gropp's avatar
gropp committed
1168
1169
1170
1171
1172
1173
1174
dnl/*D
dnl PAC_ARG_CC_G - Add debugging flags for the C compiler
dnl
dnl Synopsis:
dnl PAC_ARG_CC_G
dnl
dnl Output Effect:
gropp's avatar
gropp committed
1175
dnl Adds '-g' to 'COPTIONS' and exports 'COPTIONS'.  Sets and exports the 
gropp's avatar
gropp committed
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
dnl variable 'enable_g_simple' so that subsidiary 'configure's will not
dnl add another '-g'.
dnl
dnl Notes:
dnl '--enable-g' should be used for all internal debugging modes if possible.
dnl Use the 'enable_val' that 'enable_g' is set to to pass particular values,
dnl and ignore any values that are not recognized (some other 'configure' 
dnl may have used them.  Of course, if you need extra values, you must
dnl add code to extract values from 'enable_g'.
dnl
dnl For example, to look for a particular keyword, you could use
dnl.vb
dnl SaveIFS="$IFS"
dnl IFS=","
dnl for key in $enable_g ; do
dnl     case $key in 
dnl         mem) # add code for memory debugging 
dnl         ;;
dnl         *)   # ignore all other values
dnl         ;;
dnl     esac
dnl done
dnl IFS="$SaveIFS"
dnl.ve
dnl
gropp's avatar
gropp committed
1201
dnl D*/
gropp's avatar
gropp committed
1202
1203
AC_DEFUN(PAC_ARG_CC_G,[
AC_ARG_ENABLE(g,
gropp's avatar
gropp committed
1204
1205
[--enable-g  - Turn on debugging of the package (typically adds -g to COPTIONS)])
export COPTIONS
gropp's avatar
gropp committed
1206
1207
1208
1209
1210
export enable_g_simple
if test -n "$enable_g" -a "$enable_g" != "no" -a \
   "$enable_g_simple" != "done" ; then
    enable_g_simple="done"
    if test "$enable_g" = "g" -o "$enable_g" = "yes" ; then
gropp's avatar
gropp committed
1211
        COPTIONS="$COPTIONS -g"
gropp's avatar
gropp committed
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
    fi
fi
])
dnl
dnl Simple version for both options
dnl
AC_DEFUN(PAC_ARG_CC_COMMON,[
PAC_ARG_CC_G
PAC_ARG_STRICT
])
gropp's avatar
gropp committed
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
dnl
dnl Eventually, this can be used instead of the funky Fortran stuff to 
dnl access the command line from a C routine.
dnl #
dnl # Under IRIX (some version) __Argc and __Argv gave the argc,argv values
dnl #Under linux, __libc_argv and __libc_argc
dnl AC_MSG_CHECKING([for alternative argc,argv names])
dnl AC_TRY_LINK([
dnl extern int __Argc; extern char **__Argv;],[return __Argc;],
dnl alt_argv="__Argv")
dnl if test -z "$alt_argv" ; then
dnl    AC_TRY_LINK([
dnl extern int __libc_argc; extern char **__libc_argv;],[return __lib_argc;],
dnl alt_argv="__lib_argv")
dnl fi
dnl if test -z "$alt_argv" ; then
dnl   AC_MSG_RESULT(none found)) 
dnl else 
dnl   AC_MSG_RESULT($alt_argv) 
dnl fi
dnl 
dnl
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
dnl Check whether we need -fno-common to correctly compile the source code.
dnl This is necessary if global variables are defined without values in
dnl gcc.  Here is the test
dnl conftest1.c:
dnl extern int a; int a;
dnl conftest2.c:
dnl extern int a; int main(int argc; char *argv[] ){ return a; }
dnl Make a library out of conftest1.c and try to link with it.
dnl If that fails, recompile it with -fno-common and see if that works.
dnl If so, add -fno-common to CFLAGS
dnl An alternative is to use, on some systems, ranlib -c to force 
dnl the system to find common symbols.
dnl
AC_DEFUN(PAC_PROG_C_BROKEN_COMMON,[
1258
1259
AC_CACHE_CHECK([whether global variables handled properly],
ac_cv_prog_cc_globals_work,[
1260
AC_REQUIRE([AC_PROG_RANLIB])
1261
ac_cv_prog_cc_globals_work=no
1262
rm -f libconftest.a
1263
1264
1265
echo 'extern int a; int a;' > conftest1.c
echo 'extern int a; int main( ){ return a; }' > conftest2.c
if ${CC-cc} $CFLAGS -c conftest1.c >conftest.out 2>&1 ; then
1266
1267
1268
    if ${AR-ar} cr libconftest.a conftest1.o >/dev/null 2>&1 ; then
        if ${RANLIB-:} libconftest.a >/dev/null 2>&1 ; then
            if ${CC-cc} $CFLAGS -o conftest conftest2.c $LDFLAGS libconftest.a >>conftest.out 2>&1 ; then
1269
1270
1271
		# Success!  C works
		ac_cv_prog_cc_globals_work=yes
	    else
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
		echo "Error linking program with uninitialized global" >&AC_FD_CC
	        echo "Programs were:" >&AC_FD_CC
		echo "conftest1.c:" >&AC_FD_CC
                cat conftest1.c >&AC_FD_CC
		echo "conftest2.c:" >&AC_FD_CC
		cat conftest2.c >&AC_FD_CC
		echo "and link line was:" >&AC_FD_CC
		echo "${CC-cc} $CFLAGS -o conftest conftest2.c $LDFLAGS libconftest.a" >&AC_FD_CC
		echo "with output:" >&AC_FD_CC
		cat conftest.out >&AC_FD_CC

1283
	        # Failure!  Do we need -fno-common?
1284
	        ${CC-cc} $CFLAGS -fno-common -c conftest1.c >> conftest.out 2>&1
1285
1286
1287
		rm -f libconftest.a
		${AR-ar} cr libconftest.a conftest1.o
	        ${RANLIB-:} libconftest.a
1288
1289
	        if ${CC-cc} $CFLAGS -o conftest conftest2.c $LDFLAGS libconftest.a >> conftest.out 2>&1 ; then
		    ac_cv_prog_cc_globals_work="needs -fno-common"
1290
		    CFLAGS="$CFLAGS -fno-common"
1291
1292
                elif test -n "$RANLIB" ; then 
		    # Try again, with ranlib changed to ranlib -c
1293
1294
1295
                    # (send output to /dev/null incase this ranlib
                    # doesn't know -c)
		    ${RANLIB} -c libconftest.a >/dev/null 2>&1
1296
1297
1298
1299
1300
1301
1302
1303
		    if ${CC-cc} $CFLAGS -o conftest conftest2.c $LDFLAGS libconftest.a >> conftest.out 2>&1 ; then
			RANLIB="$RANLIB -c"
	 	    #else
		    #	# That didn't work
		    #	:
		    fi
	        #else 
		#    :
1304
1305
1306
1307
1308
		fi
	    fi
        fi
    fi
fi
1309
1310
1311
1312
rm -f conftest* libconftest*])
if test "$ac_cv_prog_cc_globals_work" = no ; then
    AC_MSG_WARN([Common symbols not supported on this system!])
fi
1313
])
gropp's avatar
gropp committed
1314
1315
1316
dnl
dnl
dnl Return the structure alignment in pac_cv_c_struct_align
gropp's avatar
gropp committed
1317
dnl Possible values include
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
dnl	packed - no padding or alignment, any item may begin on any byte
dnl	largest - extent of a structure is a multiple of the largest item; 
dnl               items are aligned with their size 
dnl	four - structs padded to a multiple of four
dnl     two  - like four, but to a multiple of two
dnl     eight - If objects containing 8-byte items are padded to a multiple
dnl             of eight
dnl     largestor4 - like largest, except that for items of size > 4, align 
dnl                  on 4-byte boundaries.  E.g., align on the 
dnl                  min(4,max(size of items)).
dnl     largestorword - (should be named largestorqword, with qword meaning 
dnl                     quad-word): Like largestor4, but with a special case 
dnl                     for 16-byte items (this is the 16-byte aligned 
dnl                     quad-word-load special case).
gropp's avatar
gropp committed
1332
1333
1334
dnl
dnl In addition, a "Could not determine alignment" and a 
dnl "Multiple cases:" return is possible.  
1335
dnl
gropp's avatar
gropp committed
1336
1337
1338
1339
AC_DEFUN(PAC_C_STRUCT_ALIGNMENT,[
AC_CACHE_CHECK([for C struct alignment],pac_cv_c_struct_align,[
AC_TRY_RUN([
#include <stdio.h>
1340
1341
1342
1343
1344
#ifdef DEBUG_STRUCT_ALIGNMENT
#define DBG(a,b,c) printf( "type %s, size = %d, extent = %d\n", a, b, c )
#define CHECK(cond,flag) if (cond) { flag = 0; \
    printf( "Setting %s to false because of %s\n", #flag, #cond ); }
#else
gropp's avatar
gropp committed
1345
#define DBG(a,b,c)
1346
1347
1348
#define CHECK(cond,flag) if (cond) { flag = 0; }
#endif

gropp's avatar
gropp committed
1349
1350
1351
1352
1353
1354
1355
1356
int main( int argc, char *argv[] )
{
    FILE *cf;
    int is_packed  = 1;
    int is_two     = 1;
    int is_four    = 1;
    int is_eight   = 1;
    int is_largest = 1;
1357
1358
1359
1360
1361
1362
    int is_largestorword = 1;
    int is_largestor4 = 1;
    int numCases;

    /* We've seen PowerPC systems where the alignment may
       be largest for some items but not for double + int */
gropp's avatar
gropp committed
1363
    struct { char a; int b; } char_int;
1364
    struct { short a; int b; } short_int;
gropp's avatar
gropp committed
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
    struct { char a; short b; } char_short;
    struct { char a; long b; } char_long;
    struct { char a; float b; } char_float;
    struct { char a; double b; } char_double;
    struct { char a; int b; char c; } char_int_char;
    struct { char a; short b; char c; } char_short_char;
#ifdef HAVE_LONG_DOUBLE
    struct { char a; long double b; } char_long_double;
#endif
    int size, extent;

    size = sizeof(char) + sizeof(int);
    extent = sizeof(char_int);
    if (size != extent) is_packed = 0;
1379
1380
1381
    CHECK((extent % sizeof(int)) != 0, is_largest); 
    CHECK((extent % sizeof(int)) != 0, is_largestor4); 
    CHECK((extent % sizeof(int)) != 0, is_largestorword); 
gropp's avatar
gropp committed
1382
1383
1384
1385
1386
    if ( (extent % 2) != 0) is_two = 0;
    if ( (extent % 4) != 0) is_four = 0;
    if (sizeof(int) == 8 && (extent % 8) != 0) is_eight = 0;
    DBG("char_int",size,extent);

1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
    size = sizeof(short) + sizeof(int);
    extent = sizeof(short_int);
    if (size != extent) is_packed = 0;
    CHECK((extent % sizeof(int)) != 0, is_largest); 
    CHECK((extent % sizeof(int)) != 0, is_largestor4); 
    CHECK((extent % sizeof(int)) != 0, is_largestorword); 
    if ( (extent % 2) != 0) is_two = 0;
    if ( (size == 6) && (extent == 8) ) is_two = 0;
    if ( (extent % 4) != 0) is_four = 0;
    if (sizeof(int) == 8 && (extent % 8) != 0) is_eight = 0;
    DBG("short_int",size,extent);

gropp's avatar
gropp committed
1399
1400
1401
    size = sizeof(char) + sizeof(short);
    extent = sizeof(char_short);
    if (size != extent) is_packed = 0;
1402
1403
1404
    CHECK((extent % sizeof(short)) != 0,is_largest);
    CHECK((extent % sizeof(short)) != 0,is_largestor4);
    CHECK((extent % sizeof(short)) != 0,is_largestorword);
gropp's avatar
gropp committed
1405
1406
1407
1408
1409
1410
1411
1412
    if ( (extent % 2) != 0) is_two = 0;
    if (sizeof(short) == 4 && (extent % 4) != 0) is_four = 0;
    if (sizeof(short) == 8 && (extent % 8) != 0) is_eight = 0;
    DBG("char_short",size,extent);

    size = sizeof(char) + sizeof(long);
    extent = sizeof(char_long);
    if (size != extent) is_packed = 0;
1413
1414
1415
    CHECK((extent % sizeof(long)) != 0,is_largest);
    CHECK((extent % 4) != 0,is_largestor4);
    CHECK((extent % sizeof(long)) != 0,is_largestorword);
gropp's avatar
gropp committed
1416
1417
1418
1419
1420
1421
1422
1423
    if ( (extent % 2) != 0) is_two = 0;
    if ( (extent % 4) != 0) is_four = 0;
    if (sizeof(long) == 8 && (extent % 8) != 0) is_eight = 0;
    DBG("char_long",size,extent);

    size = sizeof(char) + sizeof(float);
    extent = sizeof(char_float);
    if (size != extent) is_packed = 0;
1424
1425
1426
    CHECK((extent % sizeof(float)) != 0,is_largest);
    CHECK((extent % sizeof(float)) != 0,is_largestor4);
    CHECK((extent % sizeof(float)) != 0,is_largestorword);
gropp's avatar
gropp committed
1427
1428
1429
1430
1431
1432
1433
1434
    if ( (extent % 2) != 0) is_two = 0;
    if ( (extent % 4) != 0) is_four = 0;
    if (sizeof(float) == 8 && (extent % 8) != 0) is_eight = 0;
    DBG("char_float",size,extent);

    size = sizeof(char) + sizeof(double);
    extent = sizeof(char_double);
    if (size != extent) is_packed = 0;
1435
1436
1437
    CHECK((extent % sizeof(double)) != 0,is_largest);
    CHECK((extent % 4) != 0,is_largestor4);
    CHECK((extent % sizeof(int)) != 0,is_largestorword);
gropp's avatar
gropp committed
1438
1439
1440
1441
1442
1443
1444
1445
1446
    if ( (extent % 2) != 0) is_two = 0;
    if ( (extent % 4) != 0) is_four = 0;
    if (sizeof(double) == 8 && (extent % 8) != 0) is_eight = 0;
    DBG("char_double",size,extent);

#ifdef HAVE_LONG_DOUBLE
    size = sizeof(char) + sizeof(long double);
    extent = sizeof(char_long_double);
    if (size != extent) is_packed = 0;
1447
1448
    CHECK((extent % sizeof(long double)) != 0,is_largest);
    CHECK((extent % 4) != 0,is_largestor4);
1449
    CHECK((extent % 16) == 0,is_largestor4);
1450
    CHECK((extent % sizeof(long double)) != 0,is_largestorword);
1451
1452
    /* This case only applies to largestorword if long doubles are 16 bytes */
    if (sizeof(long double) != 16) is_largestorword = 0;
gropp's avatar
gropp committed
1453
1454
1455
1456
    if ( (extent % 2) != 0) is_two = 0;
    if ( (extent % 4) != 0) is_four = 0;
    if (sizeof(long double) >= 8 && (extent % 8) != 0) is_eight = 0;
    DBG("char_long-double",size,extent);
1457
1458
1459
1460
#else
    /* The special case of largestorword only applies if long double 
       available */
    is_largestorword=0;
gropp's avatar
gropp committed
1461
1462
1463
1464
1465
1466
#endif

    /* char int char helps separate largest from 4/8 aligned */
    size = sizeof(char) + sizeof(int) + sizeof(char);
    extent = sizeof(char_int_char);
    if (size != extent) is_packed = 0;
1467
1468
1469
    CHECK((extent % sizeof(int)) != 0,is_largest);
    CHECK((extent % sizeof(int)) != 0,is_largestor4);
    CHECK((extent % sizeof(int)) != 0,is_largestorword);
gropp's avatar
gropp committed
1470
1471
1472
1473
1474
1475
1476
1477
1478
    if ( (extent % 2) != 0) is_two = 0;
    if ( (extent % 4) != 0) is_four = 0;
    if (sizeof(int) == 8 && (extent % 8) != 0) is_eight = 0;
    DBG("char_int_char",size,extent);

    /* char short char helps separate largest from 4/8 aligned */
    size = sizeof(char) + sizeof(short) + sizeof(char);
    extent = sizeof(char_short_char);
    if (size != extent) is_packed = 0;
1479
1480
1481
    CHECK((extent % sizeof(short)) != 0,is_largest);
    CHECK((extent % sizeof(short)) != 0,is_largestor4);
    CHECK((extent % sizeof(short)) != 0,is_largestorword);
gropp's avatar
gropp committed
1482
1483
    if ( (extent % 2) != 0) is_two = 0;
    if (sizeof(short) == 4 && (extent % 4) != 0) is_four = 0;
1484
    CHECK((extent == 6) && (size == 4),is_four);
gropp's avatar
gropp committed
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
    if (sizeof(short) == 8 && (extent % 8) != 0) is_eight = 0;
    DBG("char_short_char",size,extent);

    /* If aligned mod 8, it will be aligned mod 4 */
    if (is_eight) { is_four = 0; is_two = 0; }

    if (is_four) is_two = 0;

    /* largest superceeds eight */
    if (is_largest) is_eight = 0;

    /* Tabulate the results */
    cf = fopen( "ctest.out", "w" );
1498
1499
1500
    numCases = is_packed + is_largest + is_largestorword + is_largestor4 +
	is_two + is_four + is_eight;
    if (numCases == 0) {
gropp's avatar
gropp committed
1501
1502
1503
	fprintf( cf, "Could not determine alignment\n" );
    }
    else {
1504
	if (numCases != 1) {
gropp's avatar
gropp committed
1505
1506
1507
1508
	    fprintf( cf, "Multiple cases:\n" );
	}
	if (is_packed) fprintf( cf, "packed\n" );
	if (is_largest) fprintf( cf, "largest\n" );
1509
1510
	if (is_largestorword) fprintf( cf, "largestorword\n" );
	if (is_largestor4) fprintf( cf, "largestor4\n" );
gropp's avatar
gropp committed
1511
1512
1513
1514
1515
1516
1517
1518
	if (is_two) fprintf( cf, "two\n" );
	if (is_four) fprintf( cf, "four\n" );
	if (is_eight) fprintf( cf, "eight\n" );
    }
    fclose( cf );
    return 0;
}],
pac_cv_c_struct_align=`cat ctest.out`
1519
,pac_cv_c_struct_align="unknown",pac_cv_c_struct_align="$CROSS_ALIGN_STRUCT")
gropp's avatar
gropp committed
1520
1521
rm -f ctest.out
])
1522
1523
1524
if test -z "$pac_cv_c_struct_align" ; then
    pac_cv_c_struct_align="unknown"
fi
gropp's avatar
gropp committed
1525
])
1526
1527
dnl
dnl
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
dnl Return the integer structure alignment in pac_cv_c_max_integer_align
dnl Possible values include
dnl	packed
dnl	two
dnl	four
dnl	eight
dnl
dnl In addition, a "Could not determine alignment" and a "error!"
dnl return is possible.  
AC_DEFUN(PAC_C_MAX_INTEGER_ALIGN,[
AC_CACHE_CHECK([for max C struct integer alignment],
pac_cv_c_max_integer_align,[
AC_TRY_RUN([
#include <stdio.h>
#define DBG(a,b,c)
int main( int argc, char *argv[] )
{
    FILE *cf;
    int is_packed  = 1;
    int is_two     = 1;
    int is_four    = 1;
    int is_eight   = 1;
    struct { char a; int b; } char_int;
    struct { char a; short b; } char_short;
    struct { char a; long b; } char_long;
    struct { char a; int b; char c; } char_int_char;
    struct { char a; short b; char c; } char_short_char;
rross's avatar
rross committed
1555
1556
1557
1558
1559
#ifdef HAVE_LONG_LONG_INT
    struct { long long int a; char b; } lli_c;
    struct { char a; long long int b; } c_lli;
#endif
    int size, extent, extent2;
1560
1561
1562
1563

    /* assume max integer alignment isn't 8 if we don't have
     * an eight-byte value :)
     */
rross's avatar
rross committed
1564
1565
1566
1567
#ifdef HAVE_LONG_LONG_INT
    if (sizeof(int) < 8 && sizeof(long) < 8 && sizeof(long long int) < 8)
	is_eight = 0;
#else
1568
    if (sizeof(int) < 8 && sizeof(long) < 8) is_eight = 0;
rross's avatar
rross committed
1569
#endif
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594

    size = sizeof(char) + sizeof(int);
    extent = sizeof(char_int);
    if (size != extent) is_packed = 0;
    if ( (extent % 2) != 0) is_two = 0;
    if ( (extent % 4) != 0) is_four = 0;
    if (sizeof(int) == 8 && (extent % 8) != 0) is_eight = 0;
    DBG("char_int",size,extent);

    size = sizeof(char) + sizeof(short);
    extent = sizeof(char_short);
    if (size != extent) is_packed = 0;
    if ( (extent % 2) != 0) is_two = 0;
    if (sizeof(short) == 4 && (extent % 4) != 0) is_four = 0;
    if (sizeof(short) == 8 && (extent % 8) != 0) is_eight = 0;
    DBG("char_short",size,extent);

    size = sizeof(char) + sizeof(long);
    extent = sizeof(char_long);
    if (size != extent) is_packed = 0;
    if ( (extent % 2) != 0) is_two = 0;
    if ( (extent % 4) != 0) is_four = 0;
    if (sizeof(long) == 8 && (extent % 8) != 0) is_eight = 0;
    DBG("char_long",size,extent);

rross's avatar
rross committed
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
#ifdef HAVE_LONG_LONG_INT
    size = sizeof(char) + sizeof(long long int);
    extent = sizeof(lli_c);
    extent2 = sizeof(c_lli);
    if (size != extent) is_packed = 0;
    if ( (extent % 2) != 0 && (extent2 % 2) != 0) is_two = 0;
    if ( (extent % 4) != 0 && (extent2 % 4) != 0) is_four = 0;
    if (sizeof(long long int) >= 8 && (extent % 8) != 0 && (extent2 % 8) != 0)
	is_eight = 0;
#endif

1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
    size = sizeof(char) + sizeof(int) + sizeof(char);
    extent = sizeof(char_int_char);
    if (size != extent) is_packed = 0;
    if ( (extent % 2) != 0) is_two = 0;
    if ( (extent % 4) != 0) is_four = 0;
    if (sizeof(int) == 8 && (extent % 8) != 0) is_eight = 0;
    DBG("char_int_char",size,extent);

    size = sizeof(char) + sizeof(short) + sizeof(char);
    extent = sizeof(char_short_char);
    if (size != extent) is_packed = 0;
    if ( (extent % 2) != 0) is_two = 0;
    if (sizeof(short) == 4 && (extent % 4) != 0) is_four = 0;
    if (sizeof(short) == 8 && (extent % 8) != 0) is_eight = 0;
    DBG("char_short_char",size,extent);

    /* If aligned mod 8, it will be aligned mod 4 */
    if (is_eight) { is_four = 0; is_two = 0; }

    if (is_four) is_two = 0;

    /* Tabulate the results */
    cf = fopen( "ctest.out", "w" );
    if (is_packed + is_two + is_four + is_eight == 0) {
	fprintf( cf, "Could not determine alignment\n" );
    }
    else {
	if (is_packed + is_two + is_four + is_eight != 1) {
	    fprintf( cf, "error!\n" );
	}
	else {
	    if (is_packed) fprintf( cf, "packed\n" );
	    if (is_two) fprintf( cf, "two\n" );
	    if (is_four) fprintf( cf, "four\n" );
	    if (is_eight) fprintf( cf, "eight\n" );
	}
    }
    fclose( cf );
    return 0;
}],
pac_cv_c_max_integer_align=`cat ctest.out`,
pac_cv_c_max_integer_align="unknown",
1648
pac_cv_c_max_integer_align="$CROSS_ALIGN_STRUCT_INT")
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
rm -f ctest.out
])
if test -z "$pac_cv_c_max_integer_align" ; then
    pac_cv_c_max_integer_align="unknown"
fi
])
dnl
dnl
dnl Return the floating point structure alignment in
dnl pac_cv_c_max_fp_align.
dnl
dnl Possible values include:
dnl	packed
dnl	two
dnl	four
dnl	eight
rross's avatar
rross committed
1665
dnl     sixteen
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
dnl
dnl In addition, a "Could not determine alignment" and a "error!"
dnl return is possible.  
AC_DEFUN(PAC_C_MAX_FP_ALIGN,[
AC_CACHE_CHECK([for max C struct floating point alignment],
pac_cv_c_max_fp_align,[
AC_TRY_RUN([
#include <stdio.h>
#define DBG(a,b,c)
int main( int argc, char *argv[] )
{
    FILE *cf;
    int is_packed  = 1;
    int is_two     = 1;
    int is_four    = 1;
    int is_eight   = 1;
rross's avatar
rross committed
1682
    int is_sixteen = 1;
1683
    struct { char a; float b; } char_float;
rross's avatar
rross committed
1684
    struct { float b; char a; } float_char;
1685
    struct { char a; double b; } char_double;
rross's avatar
rross committed
1686
    struct { double b; char a; } double_char;
1687
1688
#ifdef HAVE_LONG_DOUBLE
    struct { char a; long double b; } char_long_double;
rross's avatar
rross committed
1689
    struct { long double b; char a; } long_double_char;
1690
    struct { long double a; int b; char c; } long_double_int_char;
1691
#endif
rross's avatar
rross committed
1692
    int size, extent1, extent2;