remove empty dir
[ghc-hetmet.git] / ghc / rts / gmp / acinclude.m4
1 dnl  GMP specific autoconf macros
2
3
4 dnl  Copyright (C) 2000 Free Software Foundation, Inc.
5 dnl
6 dnl  This file is part of the GNU MP Library.
7 dnl
8 dnl  The GNU MP Library is free software; you can redistribute it and/or modify
9 dnl  it under the terms of the GNU Lesser General Public License as published
10 dnl  by the Free Software Foundation; either version 2.1 of the License, or (at
11 dnl  your option) any later version.
12 dnl
13 dnl  The GNU MP Library is distributed in the hope that it will be useful, but
14 dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16 dnl  License for more details.
17 dnl
18 dnl  You should have received a copy of the GNU Lesser General Public License
19 dnl  along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
20 dnl  the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21 dnl  MA 02111-1307, USA.
22
23
24 dnl  GMP_HEADER_GETVAL(NAME,FILE)
25 dnl  ----------------------------
26 dnl  Expand to the value of a "#define NAME" from the given FILE.
27 dnl  The regexps here aren't very rugged, but are enough for gmp.
28 dnl  /dev/null as a parameter prevents a hang if $2 is accidentally omitted.
29
30 define(GMP_HEADER_GETVAL,
31 [patsubst(patsubst(
32 esyscmd([grep "^#define $1 " $2 /dev/null 2>/dev/null]),
33 [^.*$1[         ]+],[]),
34 [[
35         ]*$],[])])
36
37
38 dnl  GMP_VERSION
39 dnl  -----------
40 dnl  The gmp version number, extracted from the #defines in gmp.h.
41 dnl  Two digits like 3.0 if patchlevel <= 0, or three digits like 3.0.1 if
42 dnl  patchlevel > 0.
43
44 define(GMP_VERSION,
45 [GMP_HEADER_GETVAL(__GNU_MP_VERSION,gmp.h)[]dnl
46 .GMP_HEADER_GETVAL(__GNU_MP_VERSION_MINOR,gmp.h)[]dnl
47 ifelse(m4_eval(GMP_HEADER_GETVAL(__GNU_MP_VERSION_PATCHLEVEL,gmp.h) > 0),1,
48 [.GMP_HEADER_GETVAL(__GNU_MP_VERSION_PATCHLEVEL,gmp.h)])])
49
50
51 dnl  GMP_PROG_M4()
52 dnl  -------------
53 dnl
54 dnl  Find a working m4, either in $PATH or likely locations, and setup $M4
55 dnl  and an AC_SUBST accordingly.  If $M4 is already set then it's a user
56 dnl  choice and is accepted with no checks.  GMP_PROG_M4 is like
57 dnl  AC_PATH_PROG or AC_CHECK_PROG, but it tests each m4 found to see if
58 dnl  it's good enough.
59 dnl 
60 dnl  See mpn/asm-defs.m4 for details on the known bad m4s.
61
62 AC_DEFUN(GMP_PROG_M4,
63 [AC_CACHE_CHECK([for suitable m4],
64                 gmp_cv_prog_m4,
65 [if test -n "$M4"; then
66   gmp_cv_prog_m4="$M4"
67 else
68   cat >conftest.m4 <<\EOF
69 dnl  must protect this against being expanded during autoconf m4!
70 [define(dollarhash,``$][#'')dnl
71 ifelse(dollarhash(x),1,`define(t1,Y)',
72 ``bad: $][# not supported (SunOS /usr/bin/m4)
73 '')dnl
74 ifelse(eval(89),89,`define(t2,Y)',
75 `bad: eval() doesnt support 8 or 9 in a constant (OpenBSD 2.6 m4)
76 ')dnl
77 ifelse(t1`'t2,YY,`good
78 ')dnl]
79 EOF
80   echo "trying m4" 1>&AC_FD_CC
81   gmp_tmp_val="`(m4 conftest.m4) 2>&AC_FD_CC`"
82   echo "$gmp_tmp_val" 1>&AC_FD_CC
83   if test "$gmp_tmp_val" = good; then
84     gmp_cv_prog_m4="m4"
85   else
86     IFS="${IFS=         }"; ac_save_ifs="$IFS"; IFS=":"
87 dnl $ac_dummy forces splitting on constant user-supplied paths.
88 dnl POSIX.2 word splitting is done only on the output of word expansions,
89 dnl not every word.  This closes a longstanding sh security hole.
90     ac_dummy="$PATH:/usr/5bin"
91     for ac_dir in $ac_dummy; do
92       test -z "$ac_dir" && ac_dir=.
93       echo "trying $ac_dir/m4" 1>&AC_FD_CC
94       gmp_tmp_val="`($ac_dir/m4 conftest.m4) 2>&AC_FD_CC`"
95       echo "$gmp_tmp_val" 1>&AC_FD_CC
96       if test "$gmp_tmp_val" = good; then
97         gmp_cv_prog_m4="$ac_dir/m4"
98         break
99       fi
100     done
101     IFS="$ac_save_ifs"
102     if test -z "$gmp_cv_prog_m4"; then
103       AC_MSG_ERROR([No usable m4 in \$PATH or /usr/5bin (see config.log for reasons).])
104     fi
105   fi
106   rm -f conftest.m4
107 fi])
108 M4="$gmp_cv_prog_m4"
109 AC_SUBST(M4)
110 ])
111
112
113 dnl  GMP_PROG_CC_FIND([CC_LIST], [REQ_64BIT_CC])
114 dnl  Find first working compiler in CC_LIST.
115 dnl  If REQ_64BIT_CC is "yes", the compiler is required to be able to 
116 dnl  produce 64-bit code.
117 dnl  NOTE: If a compiler needs any special flags for producing 64-bit code,
118 dnl  these have to be found in shell variable `gmp_cflags64_{cc}', where `{cc}'
119 dnl  is the name of the compiler.
120 dnl  Set CC to the name of the first working compiler.
121 dnl  If a 64-bit compiler is found, set CC64 to the name of the compiler and
122 dnl  CFLAGS64 to flags to use.
123 dnl  This macro does not test if any of the compilers found is a GNU compiler.
124 dnl  To do this, when you have finally made up your mind on which one to use, 
125 dnl  and set CC accordingly, invoke [GMP_PROG_CC_SELECT].  That macro will 
126 dnl  also make sure that your selection of CFLAGS is valid.
127 dnl
128 AC_DEFUN(GMP_PROG_CC_FIND,
129 [AC_BEFORE([$0], [CC_PROG_CPP])
130 ifelse([$1], , gmp_cc_list="gcc cc", gmp_cc_list="[$1]")
131 ifelse([$2], , gmp_req_64bit_cc="no", gmp_req_64bit_cc="[$2]")
132
133 CC32=
134 CC64=
135 for c in $gmp_cc_list; do
136   # Avoid cache hits.
137   unset CC
138   unset ac_cv_prog_CC
139   AC_CHECK_TOOL(CC, $c, $c)
140   if test -n "$CC"; then
141     eval c_flags=\$gmp_cflags_$c
142     GMP_PROG_CC_WORKS($CC, $c_flags,
143                       gmp_prog_cc_works=yes, 
144                       gmp_prog_cc_works=no)
145
146     if test "$gmp_prog_cc_works" != "yes"; then
147       continue
148     fi
149
150     # Save first working compiler, whether 32- or 64-bit capable.
151     if test -z "$CC32"; then
152       CC32="$CC"
153     fi
154     if test "$gmp_req_64bit_cc" = "yes"; then
155       eval c_flags=\$gmp_cflags64_$c
156
157       # Verify that the compiler works in 64-bit mode as well.
158       # /usr/ucb/cc on Solaris 7 can *compile* in 64-bit mode, but not link.
159       GMP_PROG_CC_WORKS($c, $c_flags,
160                         gmp_prog_cc_works=yes, 
161                         gmp_prog_cc_works=no)
162
163       if test "$gmp_prog_cc_works" = "yes"; then
164         GMP_CHECK_CC_64BIT($c, $c_flags)
165         if test "$gmp_cv_cc_64bit" = "yes"; then
166           test -z "$CC64" && CC64="$c"
167           test -z "$CFLAGS64" && CFLAGS64="$c_flags"
168           # We have CC64 so we're done.
169           break
170         fi
171       fi
172     else
173       # We have CC32, and we don't need a 64-bit compiler so we're done.
174       break
175     fi
176   fi
177 done
178 CC="$CC32"
179 ])dnl
180
181 dnl  GMP_PROG_CC_SELECT
182 dnl  Check that `CC' works with `CFLAGS'.  Check if `CC' is a GNU compiler.
183 dnl  Cache the result as `ac_cv_prog_CC'.
184 AC_DEFUN(GMP_PROG_CC_SELECT,
185 [AC_BEFORE([$0], [CC_PROG_CPP])
186 AC_PROG_CC_WORKS
187 AC_PROG_CC_GNU
188
189 if test "$ac_cv_prog_gcc" = "yes"; then
190   GCC=yes
191 else
192   GCC=
193 fi
194
195 # Set CFLAGS if not already set.
196 if test -z "$CFLAGS"; then
197   CFLAGS="-g"
198   if test "$GCC" = "yes"; then
199     CFLAGS="$CFLAGS -O2"
200   fi
201 fi
202
203 AC_SUBST(CC)
204 AC_CACHE_VAL(ac_cv_prog_CC, ac_cv_prog_CC="$CC")
205 AC_PROVIDE([AC_PROG_CC])
206 ])dnl
207
208 dnl  GMP_CHECK_CC_64BIT(cc, cflags64)
209 dnl  Find out if `CC' can produce 64-bit code.
210 dnl  Requires NM to be set to nm for target.
211 dnl  FIXME: Cache result.
212 AC_DEFUN(GMP_CHECK_CC_64BIT,
213 [
214   gmp_tmp_CC_save="$CC"
215   CC="[$1]"
216   AC_MSG_CHECKING([whether the C compiler ($CC) is 64-bit capable])
217   if test -z "$NM"; then
218     echo; echo ["configure: $0: fatal: need nm"]
219     exit 1
220   fi
221   gmp_tmp_CFLAGS_save="$CFLAGS"
222   CFLAGS="[$2]"
223
224   case "$target" in 
225     hppa2.0*-*-*)
226       # FIXME: If gcc is installed under another name than "gcc", we will 
227       # test the wrong thing.
228       if test "$CC" != "gcc"; then
229         dnl Let compiler version A.10.32.30 or higher be ok.
230         dnl Bad compiler output:
231         dnl   ccom: HP92453-01 G.10.32.05 HP C Compiler
232         dnl Good compiler output:
233         dnl   ccom: HP92453-01 A.10.32.30 HP C Compiler
234         echo >conftest.c
235         gmp_tmp_vs=`$CC $CFLAGS -V -c -o conftest.o conftest.c 2>&1 | grep "^ccom:"`
236         rm conftest*
237         gmp_tmp_v1=`echo $gmp_tmp_vs | sed 's/.* .\.\(.*\)\..*\..* HP C.*/\1/'`
238         gmp_tmp_v2=`echo $gmp_tmp_vs | sed 's/.* .\..*\.\(.*\)\..* HP C.*/\1/'`
239         gmp_tmp_v3=`echo $gmp_tmp_vs | sed 's/.* .\..*\..*\.\(.*\) HP C.*/\1/'`
240         gmp_cv_cc_64bit=no
241         test -n "$gmp_tmp_v1" && test "$gmp_tmp_v1" -ge "10" \
242           && test -n "$gmp_tmp_v2" && test "$gmp_tmp_v2" -ge "32" \
243           && test -n "$gmp_tmp_v3" && test "$gmp_tmp_v3" -ge "30" \
244           && gmp_cv_cc_64bit=yes
245       else      # gcc
246         # FIXME: Compile a minimal file and determine if the resulting object 
247         # file is an ELF file.  If so, gcc can produce 64-bit code.
248         # Do we have file(1) for target?
249         gmp_cv_cc_64bit=no
250       fi
251       ;;
252     mips-sgi-irix6.*)
253       # We use `-n32' to cc and `-mabi=n32' to gcc, resulting in 64-bit 
254       # arithmetic but not 64-bit pointers, so the general test for sizeof
255       # (void *) is not valid.
256       # Simply try to compile an empty main.  If that succeeds return
257       # true.
258       AC_TRY_COMPILE( , ,
259                      gmp_cv_cc_64bit=yes, gmp_cv_cc_64bit=no,
260                      gmp_cv_cc_64bit=no)
261       ;;
262     *-*-*)
263       # Allocate an array of size sizeof (void *) and use nm to determine its 
264       # size.  We depend on the first declared variable being put at address 0.
265       cat >conftest.c <<EOF
266 [char arr[sizeof (void *)]={0};
267 char post=0;]
268 EOF
269       gmp_compile="$CC $CFLAGS -c conftest.c 1>&AC_FD_CC"
270       if AC_TRY_EVAL(gmp_compile); then
271         changequote(<,>)dnl
272         gmp_tmp_val=`$NM conftest.o | grep post | sed -e 's;[[][0-9][]]\(.*\);\1;' \
273           -e 's;[^1-9]*\([0-9]*\).*;\1;'`
274         changequote([, ])dnl
275         if test "$gmp_tmp_val" = "8"; then
276           gmp_cv_cc_64bit=yes
277         else
278           gmp_cv_cc_64bit=no
279         fi
280       else
281         echo "configure: failed program was:" >&AC_FD_CC
282         cat conftest.$ac_ext >&AC_FD_CC
283         gmp_cv_cc_64bit=no
284       fi
285       rm -f conftest*
286       ;;
287   esac
288
289   CC="$gmp_tmp_CC_save"
290   CFLAGS="$gmp_tmp_CFLAGS_save"
291   AC_MSG_RESULT($gmp_cv_cc_64bit)
292 ])dnl
293
294 dnl  GMP_INIT([M4-DEF-FILE])
295 dnl  
296 AC_DEFUN(GMP_INIT,
297 [ifelse([$1], , gmp_configm4=config.m4, gmp_configm4="[$1]")
298 gmp_tmpconfigm4=cnfm4.tmp
299 gmp_tmpconfigm4i=cnfm4i.tmp
300 gmp_tmpconfigm4p=cnfm4p.tmp
301 test -f $gmp_tmpconfigm4 && rm $gmp_tmpconfigm4
302 test -f $gmp_tmpconfigm4i && rm $gmp_tmpconfigm4i
303 test -f $gmp_tmpconfigm4p && rm $gmp_tmpconfigm4p
304 ])dnl
305
306 dnl  GMP_FINISH
307 dnl  ----------
308 dnl  Create config.m4 from its accumulated parts.
309 dnl
310 dnl  __CONFIG_M4_INCLUDED__ is used so that a second or subsequent include
311 dnl  of config.m4 is harmless.
312 dnl
313 dnl  A separate ifdef on the angle bracket quoted part ensures the quoting
314 dnl  style there is respected.  The basic defines from gmp_tmpconfigm4 are
315 dnl  fully quoted but are still put under an ifdef in case any have been
316 dnl  redefined by one of the m4 include files.
317 dnl
318 dnl  Doing a big ifdef within asm-defs.m4 and/or other macro files wouldn't
319 dnl  work, since it'd interpret parentheses and quotes in dnl comments, and
320 dnl  having a whole file as a macro argument would overflow the string space
321 dnl  on BSD m4.
322
323 AC_DEFUN(GMP_FINISH,
324 [AC_REQUIRE([GMP_INIT])
325 echo "creating $gmp_configm4"
326 echo ["dnl $gmp_configm4.  Generated automatically by configure."] > $gmp_configm4
327 if test -f $gmp_tmpconfigm4; then
328   echo ["changequote(<,>)dnl"] >> $gmp_configm4
329   echo ["ifdef(<__CONFIG_M4_INCLUDED__>,,<"] >> $gmp_configm4
330   cat $gmp_tmpconfigm4 >> $gmp_configm4
331   echo [">)"] >> $gmp_configm4
332   echo ["changequote(\`,')dnl"] >> $gmp_configm4
333   rm $gmp_tmpconfigm4
334 fi
335 echo ["ifdef(\`__CONFIG_M4_INCLUDED__',,\`"] >> $gmp_configm4
336 if test -f $gmp_tmpconfigm4i; then
337   cat $gmp_tmpconfigm4i >> $gmp_configm4
338   rm $gmp_tmpconfigm4i
339 fi
340 if test -f $gmp_tmpconfigm4p; then
341   cat $gmp_tmpconfigm4p >> $gmp_configm4
342   rm $gmp_tmpconfigm4p
343 fi
344 echo ["')"] >> $gmp_configm4
345 echo ["define(\`__CONFIG_M4_INCLUDED__')"] >> $gmp_configm4
346 ])dnl
347
348 dnl  GMP_INCLUDE(FILE)
349 AC_DEFUN(GMP_INCLUDE,
350 [AC_REQUIRE([GMP_INIT])
351 echo ["include(\`$1')"] >> $gmp_tmpconfigm4i
352 ])dnl
353
354 dnl  GMP_SINCLUDE(FILE)
355 AC_DEFUN(GMP_SINCLUDE,
356 [AC_REQUIRE([GMP_INIT])
357 echo ["sinclude(\`$1')"] >> $gmp_tmpconfigm4i
358 ])dnl
359
360 dnl GMP_DEFINE(MACRO, DEFINITION [, LOCATION])
361 dnl [ Define M4 macro MACRO as DEFINITION in temporary file.            ]
362 dnl [ If LOCATION is `POST', the definition will appear after any       ]
363 dnl [ include() directives inserted by GMP_INCLUDE/GMP_SINCLUDE.        ]
364 dnl [ Mind the quoting!  No shell variables will get expanded.          ]
365 dnl [ Don't forget to invoke GMP_FINISH to create file config.m4.       ]
366 dnl [ config.m4 uses `<' and '>' as quote characters for all defines.   ]
367 AC_DEFUN(GMP_DEFINE, 
368 [AC_REQUIRE([GMP_INIT])
369 echo ['define(<$1>, <$2>)'] >> ifelse([$3], [POST], $gmp_tmpconfigm4p, $gmp_tmpconfigm4)
370 ])dnl
371
372 dnl GMP_DEFINE_RAW(STRING, [, LOCATION])
373 dnl [ Put STRING in temporary file.                                     ]
374 dnl [ If LOCATION is `POST', the definition will appear after any       ]
375 dnl [ include() directives inserted by GMP_INCLUDE/GMP_SINCLUDE.        ]
376 dnl [ Don't forget to invoke GMP_FINISH to create file config.m4.       ]
377 AC_DEFUN(GMP_DEFINE_RAW,
378 [AC_REQUIRE([GMP_INIT])
379 echo [$1] >> ifelse([$2], [POST], $gmp_tmpconfigm4p, $gmp_tmpconfigm4)
380 ])dnl
381
382 dnl  GMP_CHECK_ASM_LABEL_SUFFIX
383 dnl  Should a label have a colon or not?
384 AC_DEFUN(GMP_CHECK_ASM_LABEL_SUFFIX,
385 [AC_CACHE_CHECK([what assembly label suffix to use],
386                gmp_cv_check_asm_label_suffix,
387 [case "$target" in 
388   *-*-hpux*) gmp_cv_check_asm_label_suffix=[""] ;;
389   *) gmp_cv_check_asm_label_suffix=[":"] ;;
390 esac
391 ])
392 echo ["define(<LABEL_SUFFIX>, <\$][1$gmp_cv_check_asm_label_suffix>)"] >> $gmp_tmpconfigm4
393 ])dnl
394
395 dnl  GMP_CHECK_ASM_UNDERSCORE([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
396 dnl  Shamelessly borrowed from glibc.
397 AC_DEFUN(GMP_CHECK_ASM_UNDERSCORE,
398 [AC_CACHE_CHECK([if symbols are prefixed by underscore], 
399                 gmp_cv_check_asm_underscore,
400 [cat > conftest.$ac_ext <<EOF
401 dnl This sometimes fails to find confdefs.h, for some reason.
402 dnl [#]line __oline__ "[$]0"
403 [#]line __oline__ "configure"
404 #include "confdefs.h"
405 int underscore_test() {
406 return; }
407 EOF
408 if AC_TRY_EVAL(ac_compile); then
409   if grep _underscore_test conftest* >/dev/null; then
410     gmp_cv_check_asm_underscore=yes
411   else
412     gmp_cv_check_asm_underscore=no
413   fi
414 else
415   echo "configure: failed program was:" >&AC_FD_CC
416   cat conftest.$ac_ext >&AC_FD_CC
417 fi
418 rm -f conftest*
419 ])
420 if test "$gmp_cv_check_asm_underscore" = "yes"; then
421   GMP_DEFINE(GSYM_PREFIX, [_])
422   ifelse([$1], , :, [$1])
423 else
424   GMP_DEFINE(GSYM_PREFIX, [])
425   ifelse([$2], , :, [$2])
426 fi    
427 ])dnl
428
429 dnl  GMP_CHECK_ASM_ALIGN_LOG([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
430 dnl  Is parameter to `.align' logarithmic?
431 dnl  Requires NM to be set to nm for target.
432 AC_DEFUN(GMP_CHECK_ASM_ALIGN_LOG,
433 [AC_REQUIRE([GMP_CHECK_ASM_GLOBL])
434 AC_REQUIRE([GMP_CHECK_ASM_DATA])
435 AC_REQUIRE([GMP_CHECK_ASM_LABEL_SUFFIX])
436 AC_CACHE_CHECK([if .align assembly directive is logarithmic],
437                 gmp_cv_check_asm_align_log,
438 [if test -z "$NM"; then
439   echo; echo ["configure: $0: fatal: need nm"]
440   exit 1
441 fi
442 cat > conftest.s <<EOF
443         $gmp_cv_check_asm_data
444         .align  4
445         $gmp_cv_check_asm_globl foo
446         .byte   1
447         .align  4
448 foo$gmp_cv_check_asm_label_suffix
449         .byte   2
450 EOF
451 ac_assemble="$CCAS $CFLAGS conftest.s 1>&AC_FD_CC"
452 if AC_TRY_EVAL(ac_assemble); then
453   changequote(<,>)
454   gmp_tmp_val=`$NM conftest.o | grep foo | sed -e 's;[[][0-9][]]\(.*\);\1;' \
455        -e 's;[^1-9]*\([0-9]*\).*;\1;'`
456   changequote([, ])dnl
457   if test "$gmp_tmp_val" = "10" || test "$gmp_tmp_val" = "16"; then
458     gmp_cv_check_asm_align_log=yes
459   else
460     gmp_cv_check_asm_align_log=no
461   fi
462 else 
463   echo "configure: failed program was:" >&AC_FD_CC
464   cat conftest.s >&AC_FD_CC
465 fi
466 rm -f conftest*
467 ])
468 GMP_DEFINE_RAW(["define(<ALIGN_LOGARITHMIC>,<$gmp_cv_check_asm_align_log>)"])
469 if test "$gmp_cv_check_asm_align_log" = "yes"; then
470   ifelse([$1], , :, [$1])
471 else
472   ifelse([$2], , :, [$2])
473 fi  
474 ])dnl
475
476
477 dnl  GMP_CHECK_ASM_ALIGN_FILL_0x90
478 dnl  -----------------------------
479 dnl  Determine whether a ",0x90" suffix works on a .align directive.
480 dnl  This is only meant for use on x86, where 0x90 is a "nop".
481 dnl
482 dnl  Old gas, eg. 1.92.3 - needs ",0x90" or else the fill is an invalid 0x00.
483 dnl  New gas, eg. 2.91 - generates the good multibyte nop fills even when
484 dnl                      ",0x90" is given.
485 dnl  Solaris 2.6 as - doesn't allow ",0x90", gives a fatal error.
486 dnl  Solaris 2.8 as - gives a warning for ",0x90", no ill effect.
487 dnl
488 dnl  Note that both solaris "as"s only care about ",0x90" if they actually
489 dnl  have to use it to fill something, hence the .byte in the sample.  It's
490 dnl  only the second .align that provokes an error or warning.
491 dnl
492 dnl  We prefer to suppress the warning from solaris 2.8 to stop anyone
493 dnl  worrying something might be wrong.
494
495 AC_DEFUN(GMP_CHECK_ASM_ALIGN_FILL_0x90,
496 [AC_CACHE_CHECK([if the .align directive accepts an 0x90 fill in .text],
497                 gmp_cv_check_asm_align_fill_0x90,
498 [AC_REQUIRE([GMP_CHECK_ASM_TEXT])
499 cat > conftest.s <<EOF
500         $gmp_cv_check_asm_text
501         .align  4, 0x90
502         .byte   0
503         .align  4, 0x90
504 EOF
505 gmp_tmp_val="`$CCAS $CFLAGS conftest.s 2>&1`"
506 if test $? = 0; then
507   echo "$gmp_tmp_val" 1>&AC_FD_CC
508   if echo "$gmp_tmp_val" | grep "Warning: Fill parameter ignored for executable section"; then
509     echo "Supressing this warning by omitting 0x90" 1>&AC_FD_CC
510     gmp_cv_check_asm_align_fill_0x90=no
511   else
512     gmp_cv_check_asm_align_fill_0x90=yes
513   fi
514 else
515   echo "Non-zero exit code" 1>&AC_FD_CC
516   echo "$gmp_tmp_val" 1>&AC_FD_CC
517   gmp_cv_check_asm_align_fill_0x90=no
518 fi
519 rm -f conftest*
520 ])
521 GMP_DEFINE_RAW(
522 ["define(<ALIGN_FILL_0x90>,<$gmp_cv_check_asm_align_fill_0x90>)"])
523 ])
524
525
526 dnl  GMP_CHECK_ASM_TEXT
527 AC_DEFUN(GMP_CHECK_ASM_TEXT,
528 [AC_CACHE_CHECK([how to switch to text section], gmp_cv_check_asm_text,
529 [case "$target" in
530   *-*-aix*)
531     changequote({, })
532     gmp_cv_check_asm_text={".csect .text[PR]"}
533     changequote([, ])
534     ;;
535   *-*-hpux*) gmp_cv_check_asm_text=[".code"] ;;
536   *) gmp_cv_check_asm_text=[".text"] ;;
537 esac
538 ])
539 echo ["define(<TEXT>, <$gmp_cv_check_asm_text>)"] >> $gmp_tmpconfigm4
540 ])dnl
541
542 dnl  GMP_CHECK_ASM_DATA
543 dnl  Can we say `.data'?
544 AC_DEFUN(GMP_CHECK_ASM_DATA,
545 [AC_CACHE_CHECK([how to switch to data section], gmp_cv_check_asm_data,
546 [case "$target" in
547   *-*-aix*)
548     changequote({, })
549     gmp_cv_check_asm_data={".csect .data[RW]"}
550     changequote([, ])
551     ;;
552   *) gmp_cv_check_asm_data=[".data"] ;;
553 esac
554 ])
555 echo ["define(<DATA>, <$gmp_cv_check_asm_data>)"] >> $gmp_tmpconfigm4
556 ])dnl
557
558 dnl  GMP_CHECK_ASM_GLOBL
559 dnl  Can we say `.global'?
560 AC_DEFUN(GMP_CHECK_ASM_GLOBL,
561 [AC_CACHE_CHECK([how to export a symbol], gmp_cv_check_asm_globl,
562 [case "$target" in
563   *-*-hpux*) gmp_cv_check_asm_globl=[".export"] ;;
564   *) gmp_cv_check_asm_globl=[".globl"] ;;
565 esac
566 ])
567 echo ["define(<GLOBL>, <$gmp_cv_check_asm_globl>)"] >> $gmp_tmpconfigm4
568 ])dnl
569
570 dnl  GMP_CHECK_ASM_TYPE
571 dnl  Can we say `.type'?
572 AC_DEFUN(GMP_CHECK_ASM_TYPE,
573 [AC_CACHE_CHECK([how the .type assembly directive should be used],
574 gmp_cv_check_asm_type,
575 [ac_assemble="$CCAS $CFLAGS conftest.s 1>&AC_FD_CC"
576 for gmp_tmp_prefix in @ \# %; do
577   echo "        .type   sym,${gmp_tmp_prefix}function" > conftest.s
578   if AC_TRY_EVAL(ac_assemble); then
579     gmp_cv_check_asm_type="[.type       \$][1,${gmp_tmp_prefix}\$][2]"
580     break
581   fi
582 done
583 if test -z "$gmp_cv_check_asm_type"; then
584   gmp_cv_check_asm_type="[dnl]"
585 fi
586 ])
587 echo ["define(<TYPE>, <$gmp_cv_check_asm_type>)"] >> $gmp_tmpconfigm4
588 ])dnl
589
590 dnl  GMP_CHECK_ASM_SIZE
591 dnl  Can we say `.size'?
592 AC_DEFUN(GMP_CHECK_ASM_SIZE,
593 [AC_CACHE_CHECK([if the .size assembly directive works], gmp_cv_check_asm_size,
594 [ac_assemble="$CCAS $CFLAGS conftest.s 1>&AC_FD_CC"
595 echo '  .size   sym,1' > conftest.s
596 if AC_TRY_EVAL(ac_assemble); then
597   gmp_cv_check_asm_size="[.size \$][1,\$][2]"
598 else
599   gmp_cv_check_asm_size="[dnl]"
600 fi
601 ])
602 echo ["define(<SIZE>, <$gmp_cv_check_asm_size>)"] >> $gmp_tmpconfigm4
603 ])dnl
604
605 dnl  GMP_CHECK_ASM_LSYM_PREFIX
606 dnl  What is the prefix for a local label?
607 dnl  Requires NM to be set to nm for target.
608 AC_DEFUN(GMP_CHECK_ASM_LSYM_PREFIX,
609 [AC_REQUIRE([GMP_CHECK_ASM_LABEL_SUFFIX])
610 AC_CACHE_CHECK([what prefix to use for a local label], 
611 gmp_cv_check_asm_lsym_prefix,
612 [if test -z "$NM"; then
613   echo; echo ["$0: fatal: need nm"]
614   exit 1
615 fi
616 ac_assemble="$CCAS $CFLAGS conftest.s 1>&AC_FD_CC"
617 gmp_cv_check_asm_lsym_prefix="L"
618 for gmp_tmp_pre in L .L $ L$; do
619   cat > conftest.s <<EOF
620 dummy${gmp_cv_check_asm_label_suffix}
621 ${gmp_tmp_pre}gurkmacka${gmp_cv_check_asm_label_suffix}
622         .byte 0
623 EOF
624   if AC_TRY_EVAL(ac_assemble); then
625     $NM conftest.o >/dev/null 2>&1
626     gmp_rc=$?
627     if test "$gmp_rc" != "0"; then
628       echo "configure: $NM failure, using default"
629       break
630     fi
631     if $NM conftest.o | grep gurkmacka >/dev/null; then true; else
632       gmp_cv_check_asm_lsym_prefix="$gmp_tmp_pre"
633       break
634     fi
635   else
636     echo "configure: failed program was:" >&AC_FD_CC
637     cat conftest.s >&AC_FD_CC
638     # Use default.
639   fi
640 done
641 rm -f conftest*
642 ])
643 echo ["define(<LSYM_PREFIX>, <${gmp_cv_check_asm_lsym_prefix}>)"] >> $gmp_tmpconfigm4
644 ])
645
646 dnl  GMP_CHECK_ASM_W32
647 dnl  How to [define] a 32-bit word.
648 dnl  Requires NM to be set to nm for target.
649 AC_DEFUN(GMP_CHECK_ASM_W32,
650 [AC_REQUIRE([GMP_CHECK_ASM_DATA])
651 AC_REQUIRE([GMP_CHECK_ASM_GLOBL])
652 AC_REQUIRE([GMP_CHECK_ASM_LABEL_SUFFIX])
653 AC_CACHE_CHECK([how to [define] a 32-bit word],
654                gmp_cv_check_asm_w32,
655 [if test -z "$NM"; then
656   echo; echo ["configure: $0: fatal: need nm"]
657   exit 1
658 fi
659
660 # FIXME: HPUX puts first symbol at 0x40000000, breaking our assumption
661 # that it's at 0x0.  We'll have to declare another symbol before the
662 # .long/.word and look at the distance between the two symbols.  The
663 # only problem is that the sed expression(s) barfs (on Solaris, for
664 # example) for the symbol with value 0.  For now, HPUX uses .word.
665
666 case "$target" in 
667   *-*-hpux*)
668     gmp_cv_check_asm_w32=".word"
669     ;;
670   *-*-*)
671     ac_assemble="$CCAS $CFLAGS conftest.s 1>&AC_FD_CC"
672     for gmp_tmp_op in .long .word; do
673       cat > conftest.s <<EOF
674         $gmp_cv_check_asm_data
675         $gmp_cv_check_asm_globl foo
676         $gmp_tmp_op     0
677 foo${gmp_cv_check_asm_label_suffix}
678         .byte   0
679 EOF
680       if AC_TRY_EVAL(ac_assemble); then
681         changequote(<,>)
682         gmp_tmp_val=`$NM conftest.o | grep foo | sed -e 's;[[][0-9][]]\(.*\);\1;' \
683              -e 's;[^1-9]*\([0-9]*\).*;\1;'`
684         changequote([, ])dnl
685         if test "$gmp_tmp_val" = "4"; then
686           gmp_cv_check_asm_w32="$gmp_tmp_op"
687           break
688         fi
689       fi
690     done
691     ;;
692 esac
693
694 if test -z "$gmp_cv_check_asm_w32"; then
695   echo; echo ["configure: $0: fatal: do not know how to define a 32-bit word"]
696   exit 1
697 fi
698 rm -f conftest*
699 ])
700 echo ["define(<W32>, <$gmp_cv_check_asm_w32>)"] >> $gmp_tmpconfigm4
701 ])
702
703 dnl  GMP_CHECK_ASM_MMX([ACTION-IF-FOUND, [ACTION-IF-NOT-FOUND]])
704 dnl  Can we assemble MMX insns?
705 AC_DEFUN(GMP_CHECK_ASM_MMX,
706 [AC_REQUIRE([GMP_CHECK_ASM_TEXT])
707 AC_CACHE_CHECK([if the assembler knows about MMX instructions],
708                 gmp_cv_check_asm_mmx,
709 [cat > conftest.s <<EOF
710         $gmp_cv_check_asm_text
711         por     %mm0, %mm0
712 EOF
713 ac_assemble="$CCAS $CFLAGS conftest.s 1>&AC_FD_CC"
714 if AC_TRY_EVAL(ac_assemble); then
715   gmp_cv_check_asm_mmx=yes
716 else 
717   gmp_cv_check_asm_mmx=no
718 fi
719 rm -f conftest*
720 ])
721 if test "$gmp_cv_check_asm_mmx" = "yes"; then
722   ifelse([$1], , :, [$1])
723 else
724   AC_MSG_WARN([+----------------------------------------------------------])
725   AC_MSG_WARN([| WARNING WARNING WARNING])
726   AC_MSG_WARN([| Target CPU has MMX code, but it can't be assembled by])
727   AC_MSG_WARN([|     $CCAS $CFLAGS])
728   AC_MSG_WARN([| Non-MMX replacements will be used.])
729   AC_MSG_WARN([| This will be an inferior build.])
730   AC_MSG_WARN([+----------------------------------------------------------])
731   ifelse([$2], , :, [$2])
732 fi
733 ])dnl
734
735 dnl  GMP_CHECK_ASM_SHLDL_CL([ACTION-IF-FOUND, [ACTION-IF-NOT-FOUND]])
736 AC_DEFUN(GMP_CHECK_ASM_SHLDL_CL,
737 [AC_REQUIRE([GMP_CHECK_ASM_TEXT])
738 AC_CACHE_CHECK([if the assembler takes cl with shldl],
739                 gmp_cv_check_asm_shldl_cl,
740 [cat > conftest.s <<EOF
741         $gmp_cv_check_asm_text
742         shldl   %cl, %eax, %ebx
743 EOF
744 ac_assemble="$CCAS $CFLAGS conftest.s 1>&AC_FD_CC"
745 if AC_TRY_EVAL(ac_assemble); then
746   gmp_cv_check_asm_shldl_cl=yes
747 else 
748   gmp_cv_check_asm_shldl_cl=no
749 fi
750 rm -f conftest*
751 ])
752 if test "$gmp_cv_check_asm_shldl_cl" = "yes"; then
753   ifelse([$1], , :, [$1])
754 else
755   ifelse([$2], , :, [$2])
756 fi
757 ])dnl
758
759 dnl  GMP_PROG_CC_WORKS(CC, CFLAGS, ACTION-IF-WORKS, [ACTION-IF-NOT-WORKS])
760 dnl  Check if CC can compile and link.  Perform various target specific tests.
761 dnl  FIXME: Require `$target'.
762 AC_DEFUN(GMP_PROG_CC_WORKS,
763 [AC_LANG_C      dnl  Note: Destructive.
764 CC="[$1]"
765 CFLAGS="[$2]"
766 AC_MSG_CHECKING([if the C compiler ($CC) works with flags $CFLAGS])
767
768 # Simple test for all targets.
769 AC_TRY_COMPILER([int main(){return(0);}],
770                 tmp_works, tmp_cross)
771
772 # Target specific tests.
773 if test "$tmp_works" = "yes"; then
774   case "$target" in 
775     *-*-aix*)   # Returning a funcptr.
776       AC_TRY_COMPILE( , [} void *g(); void *f() { return g(); } int bar(){],
777                       tmp_works=yes, tmp_works=no)
778       ;;
779   esac
780 fi
781
782 if test "$tmp_works" = "yes"; then
783   [$3]
784 else
785   ifelse([$4], , :, [$4])
786 fi
787
788 AC_MSG_RESULT($tmp_works)
789 ])dnl
790
791
792 dnl  GMP_C_ANSI2KNR
793 dnl  --------------
794 dnl  Setup to use ansi2knr if necessary.
795 dnl
796 dnl  The test here is simply that if an ANSI style function works then
797 dnl  ansi2knr isn't needed.  The normal tests for whether $CC works mean we
798 dnl  don't need to worry here about anything badly broken.
799 dnl
800 dnl  AM_C_PROTOTYPES is the normal way to set up ansi2knr, but (in automake
801 dnl  March 2000) it gives the wrong answer on a C++ compiler because its
802 dnl  test requires that the compiler accept both ANSI and K&R, or otherwise
803 dnl  ansi2knr is used.  A C++ compiler fails on the K&R part, which makes
804 dnl  AM_C_PROTOTYPES think it needs ansi2knr!  GMP has no bare K&R so we
805 dnl  only need ANSI or K&R to work, not both.
806
807 AC_DEFUN(GMP_C_ANSI2KNR,
808 [AC_CACHE_CHECK([if ansi2knr should be used],
809                 gmp_cv_c_ansi2knr,
810 [cat >conftest.c <<EOF
811 int main (int argc, char *argv[]) { return 0; }
812 EOF
813 if AC_TRY_EVAL(ac_compile); then
814   gmp_cv_c_ansi2knr=no
815 else
816   gmp_cv_c_ansi2knr=yes
817 fi
818 rm -f conftest.*
819 ])
820 if test $gmp_cv_c_ansi2knr = no; then
821   U= ANSI2KNR=
822 else
823   U=_ ANSI2KNR=./ansi2knr
824   # Ensure some checks needed by ansi2knr itself.
825   AC_HEADER_STDC
826   AC_CHECK_HEADERS(string.h)
827 fi
828 AC_SUBST(U)
829 AC_SUBST(ANSI2KNR)
830 ])
831
832
833 dnl  Deal with bad synchronization of Autoconf with Libtool.
834 AC_DEFUN(AC_CANONICAL_BUILD, [_AC_CANONICAL_BUILD])
835 AC_DEFUN(AC_CHECK_TOOL_PREFIX, [_AC_CHECK_TOOL_PREFIX])