1# mpc.m4
2#
3# Copyright (C) 2008, 2009, 2010, 2011, 2012, 2014, 2018 INRIA
4#
5# This file is part of GNU MPC.
6#
7# GNU MPC is free software; you can redistribute it and/or modify it under
8# the terms of the GNU Lesser General Public License as published by the
9# Free Software Foundation; either version 3 of the License, or (at your
10# option) any later version.
11#
12# GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
13# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15# more details.
16#
17# You should have received a copy of the GNU Lesser General Public License
18# along with this program. If not, see http://www.gnu.org/licenses/ .
19
20
21#
22# SYNOPSIS
23#
24#
25# MPC_COMPLEX_H
26#
27# DESCRIPTION
28#
29# Check whether complex.h is usable; if yes, define HAVE_COMPLEX_H.
30#
31AC_DEFUN([MPC_COMPLEX_H], [
32   AC_CHECK_HEADER(
33      [complex.h],
34      [
35         m4_define(
36            [MPC_CONFTEST],
37            [
38               AC_LANG_PROGRAM(
39                  [[#include <complex.h>]],
40                  [[complex double x = 1.0 + 2.0 * I; return (creal (x) + cimag (x));]]
41               )
42            ]
43         )
44
45         AC_SEARCH_LIBS([creal], [m])
46#           needed on Solaris
47         AC_MSG_CHECKING([whether creal, cimag and I can be used])
48         AC_LINK_IFELSE(
49            [MPC_CONFTEST],
50            [
51               AC_MSG_RESULT([yes])
52               AC_DEFINE([HAVE_COMPLEX_H], [1], [complex.h present and usable])
53            ],
54            [
55               AC_MSG_RESULT([no, build without support for C complex numbers])
56            ]
57         )
58      ]
59   )
60])
61
62
63#
64# SYNOPSIS
65#
66#
67# MPC_GMP_CC_CFLAGS
68#
69# DESCRIPTION
70#
71# Checks if CC and CFLAGS can be extracted from gmp.h
72# essentially copied from mpfr
73#
74AC_DEFUN([MPC_GMP_CC_CFLAGS], [
75   AC_MSG_CHECKING(for CC and CFLAGS in gmp.h)
76   GMP_CC=
77   GMP_CFLAGS=
78   # AC_PROG_CPP triggers the search for a C compiler; use hack instead
79   for cpp in "$CPP" cpp "gcc -E" /lib/cpp "cc -E" "c99 -E"
80   do
81      echo foo > conftest.c
82      if $cpp $CPPFLAGS conftest.c > /dev/null 2> /dev/null ; then
83         # Get CC
84         echo "#include \"gmp.h\"" >  conftest.c
85         echo "MPFR_OPTION __GMP_CC"           >> conftest.c
86         GMP_CC=`$cpp $CPPFLAGS conftest.c 2> /dev/null | $EGREP MPFR_OPTION | $SED -e 's/MPFR_OPTION //g;s/ *" *//g'`
87         # Get CFLAGS
88         echo "#include \"gmp.h\"" >  conftest.c
89         echo "MPFR_OPTION __GMP_CFLAGS"           >> conftest.c
90         GMP_CFLAGS=`$cpp $CPPFLAGS conftest.c 2> /dev/null | $EGREP MPFR_OPTION | $SED -e 's/MPFR_OPTION //g;s/ *" *//g'`
91         break
92      fi
93   done
94
95   if test -z "$GMP_CC$GMP_CFLAGS" ; then
96      AC_MSG_RESULT(no)
97   else
98      AC_MSG_RESULT(yes [CC=$GMP_CC CFLAGS=$GMP_CFLAGS])
99      # Check for validity of CC and CFLAGS obtained from gmp.h
100      AC_MSG_CHECKING(for CC=$GMP_CC and CFLAGS=$GMP_CFLAGS)
101      echo "int main (void) { return 0; }" > conftest.c
102      if $GMP_CC $GMP_CFLAGS -o conftest conftest.c 2> /dev/null ; then
103         AC_MSG_RESULT(yes)
104         CC=$GMP_CC
105         CFLAGS=$GMP_CFLAGS
106      else
107         AC_MSG_RESULT(no)
108      fi
109   fi
110
111   rm -f conftest*
112])
113
114
115#
116# SYNOPSIS
117#
118#
119# MPC_WINDOWS
120#
121# DESCRIPTION
122#
123# Additional checks on windows
124# libtool requires "-no-undefined" for win32 dll
125# It also disables the tests involving the linking with LIBGMP if DLL
126#
127AC_DEFUN([MPC_WINDOWS], [
128   if test "$enable_shared" = yes; then
129     MPC_LDFLAGS="$MPC_LDFLAGS -no-undefined"
130     AC_MSG_CHECKING(for DLL/static gmp)
131     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
132#include "gmp.h"
133#if !__GMP_LIBGMP_DLL
134#error
135error
136#endif
137     ]], [[]])],[AC_MSG_RESULT(DLL)],[
138  AC_MSG_RESULT(static)
139  AC_MSG_ERROR([gmp is not available as a DLL: use --enable-static --disable-shared]) ])
140     AC_MSG_CHECKING(for DLL/static mpfr)
141     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
142#include "mpfr.h"
143#if !__GMP_LIBGMP_DLL
144#error
145error
146#endif
147     ]], [[]])],[AC_MSG_RESULT(DLL)],[
148  AC_MSG_RESULT(static)
149  AC_MSG_ERROR([mpfr is not available as a DLL: use --enable-static --disable-shared]) ])
150   else
151     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
152#include "gmp.h"
153#if __GMP_LIBGMP_DLL
154#error
155error
156#endif
157     ]], [[]])],[AC_MSG_RESULT(static)],[
158  AC_MSG_RESULT(DLL)
159  AC_MSG_ERROR([gmp is only available as a DLL: use --disable-static --enable-shared]) ])
160  fi
161  ;;
162])
163
164
165#
166# SYNOPSIS
167#
168#
169# MPC_GITVERSION
170#
171# DESCRIPTION
172#
173# If current version string contains "dev", substitutes the short git hash
174# into GITVERSION
175#
176AC_DEFUN([MPC_GITVERSION], [
177   if echo $VERSION | grep -c dev >/dev/null 2>&1 ; then
178      AC_CHECK_PROG([HASGIT], [git], [yes], [no])
179      AS_IF([test "x$HASGIT" = "xyes"], [
180         AC_MSG_CHECKING([for current git version])
181         GITVERSION=esyscmd([git rev-parse --short HEAD])
182         AC_SUBST([GITVERSION])
183         AC_MSG_RESULT([$GITVERSION])
184      ])
185   fi
186])
187