Make configure fail if deriving the constants fails
[packages/integer-gmp.git] / configure.ac
1 AC_INIT([Haskell integer (GMP)], [0.1], [libraries@haskell.org], [integer])
2
3 # Safety check: Ensure that we are in the correct source directory.
4 AC_CONFIG_SRCDIR([cbits/mkGmpDerivedConstants.c])
5
6 AC_CANONICAL_TARGET
7
8 AC_ARG_WITH([cc],
9             [C compiler],
10             [CC=$withval])
11 AC_PROG_CC()
12
13
14 dnl--------------------------------------------------------------------
15 dnl * Deal with arguments telling us gmp is somewhere odd
16 dnl--------------------------------------------------------------------
17
18 AC_ARG_WITH([gmp-includes],
19   [AC_HELP_STRING([--with-gmp-includes],
20     [directory containing gmp.h])],
21     [GMP_INCLUDE_DIRS=$withval; CPPFLAGS="-I$withval"],
22     [GMP_INCLUDE_DIRS=])
23
24 AC_ARG_WITH([gmp-libraries],
25   [AC_HELP_STRING([--with-gmp-libraries],
26     [directory containing gmp library])],
27     [GMP_LIB_DIRS=$withval; LDFLAGS="-L$withval"],
28     [GMP_LIB_DIRS=])
29
30
31 dnl--------------------------------------------------------------------
32 dnl * Check whether this machine has gmp/gmp3 installed
33 dnl--------------------------------------------------------------------
34
35 AC_CHECK_LIB([gmp],  [__gmpz_fdiv_qr],
36              [HaveLibGmp=YES; GMP_LIBS=gmp],
37              [HaveLibGmp=NO;  GMP_LIBS=])
38 if test "$HaveLibGmp" = "NO"; then
39 AC_CHECK_LIB([gmp3], [__gmpz_fdiv_qr],
40              [HaveLibGmp=YES; GMP_LIBS=gmp3],
41              [HaveLibGmp=NO;  GMP_LIBS=])
42 fi
43
44 dnl--------------------------------------------------------------------
45 dnl * Mac OS X only: check for GMP.framework
46 dnl--------------------------------------------------------------------
47
48 case $target_os in
49   darwin*)
50     AC_MSG_CHECKING([for GMP.framework])
51     save_libs="$LIBS"
52     LIBS="-framework GMP"
53     AC_TRY_LINK_FUNC(__gmpz_fdiv_qr,
54       [HaveFrameworkGMP=yes; GMP_FRAMEWORK=GMP; GMP_LIBS=],
55       [HaveFrameworkGMP=no])
56     LIBS="$save_libs"
57     AC_MSG_RESULT([$HaveFrameworkGMP])
58     ;;
59 esac
60
61 dnl--------------------------------------------------------------------
62 dnl * Make sure we got some form of gmp
63 dnl--------------------------------------------------------------------
64
65 AC_SUBST(GMP_INCLUDE_DIRS)
66 AC_SUBST(GMP_LIBS)
67 AC_SUBST(GMP_LIB_DIRS)
68 AC_SUBST(GMP_FRAMEWORK)
69 AC_SUBST(HaveLibGmp)
70 AC_SUBST(HaveFrameworkGMP)
71
72 AC_CONFIG_FILES([integer.buildinfo gmp/config.mk])
73
74 dnl--------------------------------------------------------------------
75 dnl * Generate the header cbits/GmpDerivedConstants.h
76 dnl--------------------------------------------------------------------
77
78 AC_MSG_NOTICE([generating GmpDerivedConstants.h])
79 ${CC} $CFLAGS cbits/mkGmpDerivedConstants.c -o cbits/mkGmpDerivedConstants || exit 1
80 { cbits/mkGmpDerivedConstants > cbits/GmpDerivedConstants.h; } || exit 1
81 rm cbits/mkGmpDerivedConstants
82
83 AC_OUTPUT