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