dnl GMP specific autoconf macros dnl Copyright 2000, 2001, 2002 Free Software Foundation, Inc. dnl dnl This file is part of the GNU MP Library. dnl dnl The GNU MP Library is free software; you can redistribute it and/or modify dnl it under the terms of the GNU Lesser General Public License as published dnl by the Free Software Foundation; either version 2.1 of the License, or (at dnl your option) any later version. dnl dnl The GNU MP Library is distributed in the hope that it will be useful, but dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public dnl License for more details. dnl dnl You should have received a copy of the GNU Lesser General Public License dnl along with the GNU MP Library; see the file COPYING.LIB. If not, write to dnl the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, dnl MA 02111-1307, USA. define(X86_PATTERN, [[i?86*-*-* | k[5-8]*-*-* | pentium*-*-* | athlon-*-*]]) define(POWERPC64_PATTERN, [[powerpc64-*-* | powerpc64le-*-* | powerpc620-*-* | powerpc630-*-*]]) dnl GMP_STRIP_PATH(subdir) dnl ---------------------- dnl Strip entries */subdir from $path. define(GMP_STRIP_PATH, [tmp_path= for i in $path; do case $i in */$1) ;; *) tmp_path="$tmp_path $i" ;; esac done path="$tmp_path" ]) dnl GMP_INCLUDE_GMP_H dnl ----------------- dnl Expand to the right way to #include gmp-h.in. This must be used dnl instead of gmp.h, since that file isn't generated until the end of the dnl configure. dnl dnl GMP_INCLUDE_GMP_H_BITS_PER_MP_LIMB starts as a dummy, but gets dnl redefined in GMP_C_SIZES when the right value is known. define(GMP_INCLUDE_GMP_H, [[#define __GMP_WITHIN_CONFIGURE 1 /* ignore template stuff */ #define GMP_NAIL_BITS $GMP_NAIL_BITS] GMP_INCLUDE_GMP_H_BITS_PER_MP_LIMB [$DEFN_LONG_LONG_LIMB #include "$srcdir/gmp-h.in"] ]) define(GMP_INCLUDE_GMP_H_BITS_PER_MP_LIMB, [[#define __GMP_BITS_PER_MP_LIMB 123 /* dummy for GMP_NUMB_BITS etc */ #define GMP_LIMB_BITS 123]]) dnl GMP_HEADER_GETVAL(NAME,FILE) dnl ---------------------------- dnl Expand at autoconf time to the value of a "#define NAME" from the given dnl FILE. The regexps here aren't very rugged, but are enough for gmp. dnl /dev/null as a parameter prevents a hang if $2 is accidentally omitted. define(GMP_HEADER_GETVAL, [patsubst(patsubst( esyscmd([grep "^#define $1 " $2 /dev/null 2>/dev/null]), [^.*$1[ ]+],[]), [[ ]*$],[])]) dnl GMP_VERSION dnl ----------- dnl The gmp version number, extracted from the #defines in gmp-h.in at dnl autoconf time. Two digits like 3.0 if patchlevel <= 0, or three digits dnl like 3.0.1 if patchlevel > 0. define(GMP_VERSION, [GMP_HEADER_GETVAL(__GNU_MP_VERSION,gmp-h.in)[]dnl .GMP_HEADER_GETVAL(__GNU_MP_VERSION_MINOR,gmp-h.in)[]dnl ifelse(m4_eval(GMP_HEADER_GETVAL(__GNU_MP_VERSION_PATCHLEVEL,gmp-h.in) > 0),1, [.GMP_HEADER_GETVAL(__GNU_MP_VERSION_PATCHLEVEL,gmp-h.in)])]) dnl GMP_SUBST_CHECK_FUNCS(func,...) dnl ------------------------------ dnl Setup an AC_SUBST of HAVE_FUNC_01 for each argument. AC_DEFUN(GMP_SUBST_CHECK_FUNCS, [m4_if([$1],,, [_GMP_SUBST_CHECK_FUNCS(ac_cv_func_[$1],HAVE_[]m4_translit([$1],[a-z],[A-Z])_01) GMP_SUBST_CHECK_FUNCS(m4_shift($@))])]) dnl Called: _GMP_SUBST_CHECK_FUNCS(cachvar,substvar) AC_DEFUN(_GMP_SUBST_CHECK_FUNCS, [case $[$1] in yes) AC_SUBST([$2],1) ;; no) [$2]=0 ;; esac ]) dnl GMP_SUBST_CHECK_HEADERS(foo.h,...) dnl ---------------------------------- dnl Setup an AC_SUBST of HAVE_FOO_H_01 for each argument. AC_DEFUN(GMP_SUBST_CHECK_HEADERS, [m4_if([$1],,, [_GMP_SUBST_CHECK_HEADERS(ac_cv_header_[]m4_translit([$1],[./],[__]), HAVE_[]m4_translit([$1],[a-z./],[A-Z__])_01) GMP_SUBST_CHECK_HEADERS(m4_shift($@))])]) dnl Called: _GMP_SUBST_CHECK_HEADERS(cachvar,substvar) AC_DEFUN(_GMP_SUBST_CHECK_HEADERS, [case $[$1] in yes) AC_SUBST([$2],1) ;; no) [$2]=0 ;; esac ]) dnl GMP_COMPARE_GE(A1,B1, A2,B2, ...) dnl --------------------------------- dnl Compare two version numbers A1.A2.etc and B1.B2.etc. Set dnl $gmp_compare_ge to yes or no accoring to the result. The A parts dnl should be variables, the B parts fixed numbers. As many parts as dnl desired can be included. An empty string in an A part is taken to be dnl zero, the B parts should be non-empty and non-zero. dnl dnl For example, dnl dnl GMP_COMPARE($major,10, $minor,3, $subminor,1) dnl dnl would test whether $major.$minor.$subminor is greater than or equal to dnl 10.3.1. AC_DEFUN(GMP_COMPARE_GE, [gmp_compare_ge=no GMP_COMPARE_GE_INTERNAL($@) ]) AC_DEFUN(GMP_COMPARE_GE_INTERNAL, [ifelse(len([$3]),0, [if test -n "$1" && test "$1" -ge $2; then gmp_compare_ge=yes fi], [if test -n "$1"; then if test "$1" -gt $2; then gmp_compare_ge=yes else if test "$1" -eq $2; then GMP_COMPARE_GE_INTERNAL(m4_shift(m4_shift($@))) fi fi fi]) ]) dnl GMP_PROG_AR dnl ----------- dnl GMP additions to $AR. dnl dnl A cross-"ar" may be necessary when cross-compiling since the build dnl system "ar" might try to interpret the object files to build a symbol dnl table index, hence the use of AC_CHECK_TOOL. dnl dnl A user-selected $AR is always left unchanged. AC_CHECK_TOOL is still dnl run to get the "checking" message printed though. dnl dnl $AR_FLAGS is set to "cq" rather than leaving it to libtool "cru". The dnl latter fails when libtool goes into piecewise mode and is unlucky dnl enough to have two same-named objects in separate pieces, as happens dnl for instance to random.o (and others) on vax-dec-ultrix4.5. Naturally dnl a user-selected $AR_FLAGS is left unchanged. AC_DEFUN(GMP_PROG_AR, [dnl Want to establish $AR before libtool initialization. AC_BEFORE([$0],[AC_PROG_LIBTOOL]) gmp_user_AR=$AR AC_CHECK_TOOL(AR, ar, ar) if test -z "$gmp_user_AR"; then eval arflags=\"\$ar${abi1}_flags\" test -n "$arflags" || eval arflags=\"\$ar${abi2}_flags\" if test -n "$arflags"; then AC_MSG_CHECKING([for extra ar flags]) AR="$AR $arflags" AC_MSG_RESULT([$arflags]) fi fi if test -z "$AR_FLAGS"; then AR_FLAGS=cq fi ]) dnl GMP_PROG_HOST_CC dnl ---------------- dnl Establish a value for $HOST_CC. dnl dnl Any HOST_CC already set is used without testing. Likewise any dnl CC_FOR_BUILD is used without testing. CC_FOR_BUILD is the new name for dnl a build system compiler, see configfsf.guess. AC_DEFUN(GMP_PROG_HOST_CC, [AC_BEFORE([$0],[AC_PROG_LIBTOOL]) AC_REQUIRE([AC_PROG_CC]) AC_CACHE_CHECK([for HOST_CC build system compiler], gmp_cv_prog_host_cc, [if test -n "$HOST_CC"; then gmp_cv_prog_host_cc=$HOST_CC else if test -n "$CC_FOR_BUILD"; then gmp_cv_prog_host_cc=$CC_FOR_BUILD else cat >conftest.c <&AC_FD_CC if ($c conftest.c -o conftest) >&AC_FD_CC 2>&1; then if (./conftest) >&AC_FD_CC 2>&1; then gmp_cv_prog_host_cc=$c break fi fi done rm -f conftest* if test -z "$gmp_cv_prog_host_cc"; then AC_MSG_ERROR([cannot find a build system compiler]) fi fi fi ]) HOST_CC=$gmp_cv_prog_host_cc ]) dnl GMP_PROG_LEX dnl ------------ dnl AC_PROG_LEX bombs if $LEX is set to ${am_missing_run}flex by dnl AM_PROG_LEX. It needs to see LEX=: if lex is missing. Avoid this by dnl running AC_PROG_LEX first and then using "missing". dnl dnl FIXME: This can be removed and just AM_PROG_LEX used, one that macro dnl works properly. AC_DEFUN(GMP_PROG_LEX, [AC_REQUIRE([AC_PROG_LEX]) if test "$LEX" = :; then LEX=${am_missing_run}flex fi ]) dnl GMP_PROG_M4 dnl ----------- dnl Find a working m4, either in $PATH or likely locations, and setup $M4 dnl and an AC_SUBST accordingly. If $M4 is already set then it's a user dnl choice and is accepted with no checks. GMP_PROG_M4 is like dnl AC_PATH_PROG or AC_CHECK_PROG, but tests each m4 found to see if it's dnl good enough. dnl dnl See mpn/asm-defs.m4 for details on the known bad m4s. AC_DEFUN(GMP_PROG_M4, [AC_ARG_VAR(M4,[m4 macro processor]) AC_CACHE_CHECK([for suitable m4], gmp_cv_prog_m4, [if test -n "$M4"; then gmp_cv_prog_m4="$M4" else cat >conftest.m4 <<\EOF dnl Must protect this against being expanded during autoconf m4! dnl Dont put "dnl"s in this as autoconf will flag an error for unexpanded dnl macros. [define(dollarhash,``$][#'')ifelse(dollarhash(x),1,`define(t1,Y)', ``bad: $][# not supported (SunOS /usr/bin/m4) '')ifelse(eval(89),89,`define(t2,Y)', `bad: eval() doesnt support 8 or 9 in a constant (OpenBSD 2.6 m4) ')ifelse(t1`'t2,YY,`good ')] EOF dnl ' <- balance the quotes for emacs sh-mode echo "trying m4" >&AC_FD_CC gmp_tmp_val=`(m4 conftest.m4) 2>&AC_FD_CC` echo "$gmp_tmp_val" >&AC_FD_CC if test "$gmp_tmp_val" = good; then gmp_cv_prog_m4="m4" else IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" dnl $ac_dummy forces splitting on constant user-supplied paths. dnl POSIX.2 word splitting is done only on the output of word expansions, dnl not every word. This closes a longstanding sh security hole. ac_dummy="$PATH:/usr/5bin" for ac_dir in $ac_dummy; do test -z "$ac_dir" && ac_dir=. echo "trying $ac_dir/m4" >&AC_FD_CC gmp_tmp_val=`($ac_dir/m4 conftest.m4) 2>&AC_FD_CC` echo "$gmp_tmp_val" >&AC_FD_CC if test "$gmp_tmp_val" = good; then gmp_cv_prog_m4="$ac_dir/m4" break fi done IFS="$ac_save_ifs" if test -z "$gmp_cv_prog_m4"; then AC_MSG_ERROR([No usable m4 in \$PATH or /usr/5bin (see config.log for reasons).]) fi fi rm -f conftest.m4 fi]) M4="$gmp_cv_prog_m4" AC_SUBST(M4) ]) dnl GMP_M4_M4WRAP_SPURIOUS dnl ---------------------- dnl Check for spurious output from m4wrap(), as described in mpn/asm-defs.m4. dnl dnl The following systems have been seen with the problem. dnl dnl - Unicos alpha, but its assembler doesn't seem to mind. dnl - MacOS X Darwin, its assembler fails. dnl - NetBSD 1.4.1 m68k, and gas 1.92.3 there gives a warning and ignores dnl the bad last line since it doesn't have a newline. dnl - NetBSD 1.4.2 alpha, but its assembler doesn't seem to mind. dnl dnl Enhancement: Maybe this could be in GMP_PROG_M4, and attempt to prefer dnl an m4 with a working m4wrap, if it can be found. AC_DEFUN(GMP_M4_M4WRAP_SPURIOUS, [AC_REQUIRE([GMP_PROG_M4]) AC_CACHE_CHECK([if m4wrap produces spurious output], gmp_cv_m4_m4wrap_spurious, [# hide the d-n-l from autoconf's error checking tmp_d_n_l=d""nl cat >conftest.m4 <&AC_FD_CC cat conftest.m4 >&AC_FD_CC tmp_chars=`$M4 conftest.m4 | wc -c` echo produces $tmp_chars chars output >&AC_FD_CC rm -f conftest.m4 if test $tmp_chars = 0; then gmp_cv_m4_m4wrap_spurious=no else gmp_cv_m4_m4wrap_spurious=yes fi ]) GMP_DEFINE_RAW(["define(,<$gmp_cv_m4_m4wrap_spurious>)"]) ]) dnl GMP_PROG_NM dnl ----------- dnl GMP additions to libtool AC_PROG_NM. dnl dnl Note that if AC_PROG_NM can't find a working nm it still leaves dnl $NM set to "nm", so $NM can't be assumed to actually work. dnl dnl A user-selected $NM is always left unchanged. AC_PROG_NM is still run dnl to get the "checking" message printed though. AC_DEFUN(GMP_PROG_NM, [dnl Make sure we're the first to call AC_PROG_NM, so our extra flags are dnl used by everyone. AC_BEFORE([$0],[AC_PROG_NM]) gmp_user_NM=$NM AC_PROG_NM # FIXME: When cross compiling (ie. $ac_tool_prefix not empty), libtool # defaults to plain "nm" if a "${ac_tool_prefix}nm" is not found. In this # case run it again to try the native "nm", firstly so that likely locations # are searched, secondly so that -B or -p are added if necessary for BSD # format. This is necessary for instance on OSF with "./configure # --build=alphaev5-dec-osf --host=alphaev6-dec-osf". # if test -z "$gmp_user_NM" && test -n "$ac_tool_prefix" && test "$NM" = nm; then $as_unset lt_cv_path_NM gmp_save_ac_tool_prefix=$ac_tool_prefix ac_tool_prefix= NM= AC_PROG_NM ac_tool_prefix=$gmp_save_ac_tool_prefix fi if test -z "$gmp_user_NM"; then eval nmflags=\"\$nm${abi1}_flags\" test -n "$nmflags" || eval nmflags=\"\$nm${abi2}_flags\" if test -n "$nmflags"; then AC_MSG_CHECKING([for extra nm flags]) NM="$NM $nmflags" AC_MSG_RESULT([$nmflags]) fi fi ]) dnl GMP_PROG_CC_WORKS(cc+cflags,[ACTION-IF-WORKS][,ACTION-IF-NOT-WORKS]) dnl -------------------------------------------------------------------- dnl Check if cc+cflags can compile and link. dnl dnl This test is designed to be run repeatedly with different cc+cflags dnl selections, so the result is not cached. dnl dnl For a native build, meaning $cross_compiling == no, we require that the dnl generated program will run. This is the same as AC_PROG_CC does in dnl _AC_COMPILER_EXEEXT_WORKS, and checking here will ensure we don't pass dnl a CC/CFLAGS combination that it rejects. dnl dnl sparc-*-solaris2.7 can compile ABI=64 but won't run it if the kernel dnl was booted in 32-bit mode. The effect of requiring the compiler output dnl will run is that a plain native "./configure" falls back on ABI=32, but dnl ABI=64 is still available as a cross-compile. AC_DEFUN(GMP_PROG_CC_WORKS, [AC_MSG_CHECKING([compiler $1]) cat >conftest.c <= 0 ? n : 0); } /* The following provokes a linker invocation problem with gcc 3.0.3 on AIX 4.3 under "-maix64 -mpowerpc64 -mcpu=630". The -mcpu=630 option causes gcc to incorrectly select the 32-bit libgcc.a, not the 64-bit one, and consequently it misses out on the __fixunsdfdi helper (double -> uint64 conversion). */ double d; unsigned long gcc303 () { return (unsigned long) d; } int main () { return 0; } EOF gmp_prog_cc_works=no gmp_compile="$1 conftest.c >&AC_FD_CC" if AC_TRY_EVAL(gmp_compile); then if test "$cross_compiling" = no; then if AC_TRY_COMMAND([./a.out || ./a.exe || ./conftest]); then gmp_prog_cc_works=yes fi else gmp_prog_cc_works=yes fi fi rm -f conftest* a.out a.exe AC_MSG_RESULT($gmp_prog_cc_works) if test $gmp_prog_cc_works = yes; then ifelse([$2],,:,[$2]) else ifelse([$3],,:,[$3]) fi ]) dnl GMP_PROG_CC_IS_GNU(CC,[ACTIONS-IF-YES][,ACTIONS-IF-NO]) dnl ------------------------------------------------------- dnl Determine whether the given compiler is GNU C. dnl dnl This test is the same as autoconf _AC_LANG_COMPILER_GNU, but doesn't dnl cache the result. The same "ifndef" style test is used, to avoid dnl problems with syntax checking cpp's used on NeXT and Apple systems. AC_DEFUN(GMP_PROG_CC_IS_GNU, [cat >conftest.c <