Fix GMP v4 compatibility.
[packages/integer-gmp.git] / configure.ac
index bac536d..d5eb3b2 100644 (file)
@@ -1,7 +1,7 @@
 AC_INIT([Haskell integer (GMP)], [0.1], [libraries@haskell.org], [integer])
 
 # Safety check: Ensure that we are in the correct source directory.
-AC_CONFIG_SRCDIR([cbits/mkGmpDerivedConstants.c])
+AC_CONFIG_SRCDIR([cbits/gmp-wrappers.cmm])
 
 AC_CANONICAL_TARGET
 
@@ -27,62 +27,60 @@ AC_ARG_WITH([gmp-libraries],
     [GMP_LIB_DIRS=$withval; LDFLAGS="-L$withval"],
     [GMP_LIB_DIRS=])
 
+AC_ARG_WITH([gmp-framework-preferred],
+  [AC_HELP_STRING([--with-gmp-framework-preferred],
+    [on OSX, prefer the GMP framework to the gmp lib])],
+    [GMP_PREFER_FRAMEWORK=YES],
+    [GMP_PREFER_FRAMEWORK=NO])
 
-dnl--------------------------------------------------------------------
-dnl * Check whether this machine has gmp/gmp3 installed
-dnl--------------------------------------------------------------------
-
-AC_CHECK_LIB([gmp],  [__gmpz_fdiv_qr],
-             [HAVE_GMP=YES; GMP_LIBS=gmp],
-             [HAVE_GMP=NO;  GMP_LIBS=])
-if test "$HAVE_GMP" = "NO"; then
-AC_CHECK_LIB([gmp3], [__gmpz_fdiv_qr],
-             [HAVE_GMP=YES; GMP_LIBS=gmp3],
-             [HAVE_GMP=NO;  GMP_LIBS=])
-fi
+AC_ARG_WITH([intree-gmp],
+  [AC_HELP_STRING([--with-intree-gmp],
+    [force using the in-tree GMP])],
+    [GMP_FORCE_INTREE=YES],
+    [GMP_FORCE_INTREE=NO])
 
 dnl--------------------------------------------------------------------
-dnl * Mac OS X only: check for GMP.framework
+dnl * Detect gmp
 dnl--------------------------------------------------------------------
 
-case $target_os in
-  darwin*)
-    AC_MSG_CHECKING([for GMP.framework])
-    save_libs="$LIBS"
-    LIBS="-framework GMP"
-    AC_TRY_LINK_FUNC(__gmpz_fdiv_qr,
-      [HAVE_GMP_FRAMEWORK=yes; GMP_FRAMEWORK=GMP; GMP_LIBS=; HAVE_GMP=YES],
-      [HAVE_GMP_FRAMEWORK=no])
-    LIBS="$save_libs"
-    AC_MSG_RESULT([$HAVE_GMP_FRAMEWORK])
-    ;;
-esac
+HaveLibGmp=NO
+GMP_LIBS=
+HaveFrameworkGMP=NO
+GMP_FRAMEWORK=
+HaveSecurePowm=0
+
+if test "$GMP_FORCE_INTREE" != "YES"
+then
+    if test "$GMP_PREFER_FRAMEWORK" = "YES"
+    then
+        LOOK_FOR_GMP_FRAMEWORK
+        LOOK_FOR_GMP_LIB
+    else
+        LOOK_FOR_GMP_LIB
+        LOOK_FOR_GMP_FRAMEWORK
+    fi
+fi
+if test "$HaveFrameworkGMP" = "YES" || test "$HaveLibGmp" = "YES"
+then
+    AC_CHECK_HEADER([gmp.h], , [AC_MSG_ERROR([Cannot find gmp.h])])
+fi
 
 dnl--------------------------------------------------------------------
 dnl * Make sure we got some form of gmp
 dnl--------------------------------------------------------------------
 
-if test "$HAVE_GMP" = "NO"; then
-  AC_MSG_ERROR([cannot find the gmp library on the system.]
-    [If you have gmp installed in a non-standard location re-run ./configure]
-    [and specify the flags --with-gmp-includes= and/or --with-gmp-libraries=])
-fi
-
-
 AC_SUBST(GMP_INCLUDE_DIRS)
 AC_SUBST(GMP_LIBS)
 AC_SUBST(GMP_LIB_DIRS)
 AC_SUBST(GMP_FRAMEWORK)
+AC_SUBST(HaveLibGmp)
+AC_SUBST(HaveFrameworkGMP)
+AC_SUBST(HaveSecurePowm)
 
-AC_CONFIG_FILES([integer.buildinfo])
+AC_CONFIG_FILES([integer-gmp.buildinfo gmp/config.mk include/HsIntegerGmp.h])
 
 dnl--------------------------------------------------------------------
 dnl * Generate the header cbits/GmpDerivedConstants.h
 dnl--------------------------------------------------------------------
 
-AC_MSG_NOTICE([generating GmpDerivedConstants.h])
-${CC} $CFLAGS cbits/mkGmpDerivedConstants.c -o cbits/mkGmpDerivedConstants
-cbits/mkGmpDerivedConstants > cbits/GmpDerivedConstants.h
-rm cbits/mkGmpDerivedConstants
-
 AC_OUTPUT