Provide a way for OS X users to indicate a preference for the GMP framework
authorIan Lynagh <ian@well-typed.com>
Tue, 1 Jan 2013 17:01:00 +0000 (17:01 +0000)
committerIan Lynagh <ian@well-typed.com>
Tue, 1 Jan 2013 17:03:29 +0000 (17:03 +0000)
We used to always use the framework if it existed. Now the make variable
GMP_PREFER_FRAMEWORK can be used to control whether the library or the
framework is preferred.

Fixes #7466.

aclocal.m4 [new file with mode: 0644]
configure.ac
gmp/ghc.mk

diff --git a/aclocal.m4 b/aclocal.m4
new file mode 100644 (file)
index 0000000..8a9c467
--- /dev/null
@@ -0,0 +1,39 @@
+
+dnl--------------------------------------------------------------------
+dnl * Check whether this machine has gmp/gmp3 installed
+dnl--------------------------------------------------------------------
+
+AC_DEFUN([LOOK_FOR_GMP_LIB],[
+    if test "$HaveFrameworkGMP" = "NO"
+    then
+        AC_CHECK_LIB([gmp],  [__gmpz_fdiv_qr],
+                     [HaveLibGmp=YES; GMP_LIBS=gmp])
+        if test "$HaveLibGmp" = "NO"
+        then
+            AC_CHECK_LIB([gmp3], [__gmpz_fdiv_qr],
+                         [HaveLibGmp=YES; GMP_LIBS=gmp3])
+        fi
+    fi
+])
+
+dnl--------------------------------------------------------------------
+dnl * Mac OS X only: check for GMP.framework
+dnl--------------------------------------------------------------------
+
+AC_DEFUN([LOOK_FOR_GMP_FRAMEWORK],[
+    if test "$HaveLibGmp" = "NO"
+    then
+        case $target_os in
+        darwin*)
+            AC_MSG_CHECKING([for GMP.framework])
+            save_libs="$LIBS"
+            LIBS="-framework GMP"
+            AC_TRY_LINK_FUNC(__gmpz_fdiv_qr,
+                             [HaveFrameworkGMP=YES; GMP_FRAMEWORK=GMP])
+            LIBS="$save_libs"
+            AC_MSG_RESULT([$HaveFrameworkGMP])
+            ;;
+        esac
+    fi
+])
+
index b6a8003..7ea296c 100644 (file)
@@ -27,38 +27,33 @@ 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 * Detect gmp
 dnl--------------------------------------------------------------------
 
-AC_CHECK_LIB([gmp],  [__gmpz_fdiv_qr],
-             [HaveLibGmp=YES; GMP_LIBS=gmp],
-             [HaveLibGmp=NO;  GMP_LIBS=])
-if test "$HaveLibGmp" = "NO"; then
-AC_CHECK_LIB([gmp3], [__gmpz_fdiv_qr],
-             [HaveLibGmp=YES; GMP_LIBS=gmp3],
-             [HaveLibGmp=NO;  GMP_LIBS=])
+HaveLibGmp=NO
+GMP_LIBS=
+HaveFrameworkGMP=NO
+GMP_FRAMEWORK=
+
+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
+if test "$HaveFrameworkGMP" = "YES" || test "$HaveLibGmp" = "NO"
+then
+    AC_CHECK_HEADER([gmp.h], , [AC_MSG_ERROR([Cannot find gmp.h])])
 fi
-
-dnl--------------------------------------------------------------------
-dnl * Mac OS X only: check for GMP.framework
-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,
-      [HaveFrameworkGMP=YES; GMP_FRAMEWORK=GMP; GMP_LIBS=],
-      [HaveFrameworkGMP=NO])
-    LIBS="$save_libs"
-    AC_MSG_RESULT([$HaveFrameworkGMP])
-    ;;
-esac
-
-AC_CHECK_HEADER([gmp.h], , [HaveFrameworkGMP=NO; HaveLibGmp=NO; GMP_LIBS=])
 
 dnl--------------------------------------------------------------------
 dnl * Make sure we got some form of gmp
index 8c60e6f..b39f36a 100644 (file)
@@ -39,6 +39,10 @@ ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
 include libraries/integer-gmp/gmp/config.mk
 endif
 
+ifeq "$(GMP_PREFER_FRAMEWORK)" "YES"
+libraries/integer-gmp_CC_OPTS += --with-gmp-framework-preferred
+endif
+
 libraries/integer-gmp_CC_OPTS += $(addprefix -I,$(GMP_INCLUDE_DIRS))
 libraries/integer-gmp_CC_OPTS += $(addprefix -L,$(GMP_LIB_DIRS))