mpc.m4 revision 1.1.1.4
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_C_CHECK_FLAG([FLAG,ACCUMULATOR])
68#
69# DESCRIPTION
70#
71# Checks if the C compiler accepts the flag FLAG
72# If yes, adds it to CFLAGS.
73
74AC_DEFUN([MPC_C_CHECK_FLAG], [
75   AX_C_CHECK_FLAG($1,,,[CFLAGS="$CFLAGS $1"])
76])
77
78
79#
80# SYNOPSIS
81#
82#
83# MPC_C_CHECK_WARNINGFLAGS
84#
85# DESCRIPTION
86#
87# For development version only: Checks if gcc accepts warning flags.
88# Adds accepted ones to CFLAGS.
89#
90AC_DEFUN([MPC_C_CHECK_WARNINGCFLAGS], [
91  AC_REQUIRE([AC_PROG_GREP])
92  if echo $VERSION | grep -c dev >/dev/null 2>&1 ; then
93    if test "x$GCC" = "xyes" -a "x$compiler" != "xicc"; then
94      MPC_C_CHECK_FLAG(-g)
95      MPC_C_CHECK_FLAG(-std=c99)
96      MPC_C_CHECK_FLAG(-Wno-long-long)
97      MPC_C_CHECK_FLAG(-Wall)
98      MPC_C_CHECK_FLAG(-Wextra)
99      MPC_C_CHECK_FLAG(-Wdeclaration-after-statement)
100      MPC_C_CHECK_FLAG(-Wshadow)
101      MPC_C_CHECK_FLAG(-Wstrict-prototypes)
102      MPC_C_CHECK_FLAG(-Wmissing-prototypes)
103      MPC_C_CHECK_FLAG(-Wno-unused-value)
104      MPC_C_CHECK_FLAG(-Wlogical-op)
105    fi
106  fi
107])
108
109
110#
111# SYNOPSIS
112#
113#
114# MPC_GMP_CC_CFLAGS
115#
116# DESCRIPTION
117#
118# Checks if CC and CFLAGS can be extracted from gmp.h
119# essentially copied from mpfr
120#
121AC_DEFUN([MPC_GMP_CC_CFLAGS], [
122   AC_MSG_CHECKING(for CC and CFLAGS in gmp.h)
123   GMP_CC=
124   GMP_CFLAGS=
125   # AC_PROG_CPP triggers the search for a C compiler; use hack instead
126   for cpp in "$CPP" cpp "gcc -E" /lib/cpp "cc -E" "c99 -E"
127   do
128      echo foo > conftest.c
129      if $cpp $CPPFLAGS conftest.c > /dev/null 2> /dev/null ; then
130         # Get CC
131         echo "#include \"gmp.h\"" >  conftest.c
132         echo "MPFR_OPTION __GMP_CC"           >> conftest.c
133         GMP_CC=`$cpp $CPPFLAGS conftest.c 2> /dev/null | $EGREP MPFR_OPTION | $SED -e 's/MPFR_OPTION //g;s/ *" *//g'`
134         # Get CFLAGS
135         echo "#include \"gmp.h\"" >  conftest.c
136         echo "MPFR_OPTION __GMP_CFLAGS"           >> conftest.c
137         GMP_CFLAGS=`$cpp $CPPFLAGS conftest.c 2> /dev/null | $EGREP MPFR_OPTION | $SED -e 's/MPFR_OPTION //g;s/ *" *//g'`
138         break
139      fi
140   done
141
142   if test -z "$GMP_CC$GMP_CFLAGS" ; then
143      AC_MSG_RESULT(no)
144   else
145      AC_MSG_RESULT(yes [CC=$GMP_CC CFLAGS=$GMP_CFLAGS])
146      # Check for validity of CC and CFLAGS obtained from gmp.h
147      AC_MSG_CHECKING(for CC=$GMP_CC and CFLAGS=$GMP_CFLAGS)
148      echo "int main (void) { return 0; }" > conftest.c
149      if $GMP_CC $GMP_CFLAGS -o conftest conftest.c 2> /dev/null ; then
150         AC_MSG_RESULT(yes)
151         CC=$GMP_CC
152         CFLAGS=$GMP_CFLAGS
153      else
154         AC_MSG_RESULT(no)
155      fi
156   fi
157
158   rm -f conftest*
159])
160
161
162#
163# SYNOPSIS
164#
165#
166# MPC_WINDOWS
167#
168# DESCRIPTION
169#
170# Additional checks on windows
171# libtool requires "-no-undefined" for win32 dll
172# It also disables the tests involving the linking with LIBGMP if DLL
173#
174AC_DEFUN([MPC_WINDOWS], [
175   if test "$enable_shared" = yes; then
176     MPC_LDFLAGS="$MPC_LDFLAGS -no-undefined"
177     AC_MSG_CHECKING(for DLL/static gmp)
178     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
179#include "gmp.h"
180#if !__GMP_LIBGMP_DLL
181#error
182error
183#endif
184     ]], [[]])],[AC_MSG_RESULT(DLL)],[
185  AC_MSG_RESULT(static)
186  AC_MSG_ERROR([gmp is not available as a DLL: use --enable-static --disable-shared]) ])
187     AC_MSG_CHECKING(for DLL/static mpfr)
188     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
189#include "mpfr.h"
190#if !__GMP_LIBGMP_DLL
191#error
192error
193#endif
194     ]], [[]])],[AC_MSG_RESULT(DLL)],[
195  AC_MSG_RESULT(static)
196  AC_MSG_ERROR([mpfr is not available as a DLL: use --enable-static --disable-shared]) ])
197   else
198     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
199#include "gmp.h"
200#if __GMP_LIBGMP_DLL
201#error
202error
203#endif
204     ]], [[]])],[AC_MSG_RESULT(static)],[
205  AC_MSG_RESULT(DLL)
206  AC_MSG_ERROR([gmp is only available as a DLL: use --disable-static --enable-shared]) ])
207  fi
208  ;;
209])
210
211
212#
213# SYNOPSIS
214#
215#
216# MPC_GITVERSION
217#
218# DESCRIPTION
219#
220# If current version string contains "dev", substitutes the short git hash
221# into GITVERSION
222#
223AC_DEFUN([MPC_GITVERSION], [
224   if echo $VERSION | grep -c dev >/dev/null 2>&1 ; then
225      AC_CHECK_PROG([HASGIT], [git], [yes], [no])
226      AS_IF([test "x$HASGIT" = "xyes"], [
227         AC_MSG_CHECKING([for current git version])
228         GITVERSION=esyscmd([git rev-parse --short HEAD])
229         AC_SUBST([GITVERSION])
230         AC_MSG_RESULT([$GITVERSION])
231      ])
232   fi
233])
234