[PATCH] Fix bug in evaluation of real and imaginary parts of powers.
[ginac.git] / acinclude.m4
1 dnl ===========================================================================
2 dnl Additional macros used to configure GiNaC.  We don't start our own 
3 dnl additions' names with AC_ but with GINAC_ in order to steer clear of
4 dnl future trouble.
5 dnl ===========================================================================
6
7 dnl  GINAC_HEADER_GETVAL(NAME,FILE)
8 dnl  ----------------------------
9 dnl  Expand at autoconf time to the value of a "#define NAME" from the given
10 dnl  FILE. The regexps here aren't very rugged, but are enough for us.
11 dnl  /dev/null as a parameter prevents a hang if $2 is accidentally omitted.
12 dnl  (shamelessly ripped from GMP, and changed prefix to GINAC_).
13
14 define(GINAC_HEADER_GETVAL,
15 [patsubst(patsubst(
16 esyscmd([grep "^#define $1 " $2 /dev/null 2>/dev/null]),
17 [^.*$1[         ]+],[]),
18 [[
19         ]*$],[])])
20 define(GINAC_GET_VERSION,
21 [GINAC_HEADER_GETVAL(GINACLIB_$1_VERSION,[ginac/version.h])])
22 define(GINAC_GET_LTVERSION,
23 [GINAC_HEADER_GETVAL(GINAC_LT_$1,[ginac/version.h])])
24
25 dnl Usage: GINAC_STD_CXX_HEADERS
26 dnl Check for standard C++ headers, bail out if something is missing.
27 AC_DEFUN([GINAC_STD_CXX_HEADERS], [
28 AC_CACHE_CHECK([for standard C++ header files], [ginac_cv_std_cxx_headers], [
29         ginac_cv_std_cxx_headers="no"
30         AC_LANG_PUSH([C++])
31         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
32                 #include <algorithm>
33                 #include <cstddef>
34                 #include <cstdio>
35                 #include <cstdlib>
36                 #include <cstring>
37                 #include <cstdint>
38                 #include <ctime>
39                 #include <fstream>
40                 #include <functional>
41                 #include <iomanip>
42                 #include <ios>
43                 #include <iosfwd>
44                 #include <iostream>
45                 #include <iterator>
46                 #include <limits>
47                 #include <list>
48                 #include <map>
49                 #include <memory>
50                 #include <numeric>
51                 #include <ostream>
52                 #include <set>
53                 #include <sstream>
54                 #include <stack>
55                 #include <stdexcept>
56                 #include <string>
57                 #include <typeinfo>
58                 #include <utility>
59                 #include <vector>
60                 ]])], [ginac_cv_std_cxx_headers="yes"])
61         AC_LANG_POP([C++])])
62 if test "${ginac_cv_std_cxx_headers}" != "yes"; then
63         AC_MSG_ERROR([Standard ISO C++ headers are missing])
64 fi
65 ])
66
67 dnl Usage: GINAC_LIBREADLINE
68 dnl
69 dnl Check if GNU readline library and headers are avialable.
70 dnl Defines GINSH_LIBS variable, and HAVE_LIBREADLINE,
71 dnl HAVE_READLINE_READLINE_H, HAVE_READLINE_HISTORY_H preprocessor macros.
72 dnl
73 dnl Note: this macro rejects readline versions <= 4.2 and non-GNU
74 dnl implementations.
75 dnl
76 AC_DEFUN([GINAC_READLINE],[
77 AC_REQUIRE([GINAC_TERMCAP])
78 GINSH_LIBS=""
79 AC_CHECK_HEADERS(readline/readline.h readline/history.h)
80 if test "x${ac_cv_header_readline_readline_h}" != "xyes" -o "x${ac_cv_header_readline_history_h}" != "xyes"; then
81         GINAC_WARNING([ginsh will not compile, because readline headers could not be found.])
82 else
83         AC_CACHE_CHECK([for version of libreadline], [ginac_cv_rl_supported], [
84                 ginac_cv_rl_supported="no"
85                 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
86                         #include <cstdio>
87                         #include <readline/readline.h>
88                         #if !defined(RL_VERSION_MAJOR) || !defined(RL_VERSION_MINOR)
89                         #error "Ancient/unsupported version of readline"
90                         #endif]])],
91                         [ginac_cv_rl_supported="yes"])])
92         if test "x${ginac_cv_rl_supported}" != "xyes"; then
93                 GINAC_WARNING([ginsh will not compile, because of an unsupported version of readline (<= 4.2 or non-GNU).])
94         else
95                 save_LIBS="$LIBS"
96                 LIBS="$LIBTERMCAP $LIBS"
97                 AC_CHECK_LIB(readline, readline)
98                 if test "x${ac_cv_lib_readline_readline}" != "xyes"; then
99                         GINAC_WARNING([ginsh will not compile, because libreadline could not be found.])
100                 fi
101                 GINSH_LIBS="$LIBS"
102                 LIBS="$save_LIBS"
103         fi
104 fi
105 AC_SUBST(GINSH_LIBS)])
106         
107 dnl Usage: GINAC_TERMCAP
108 dnl libreadline is based on the termcap functions.
109 dnl Some systems have tgetent(), tgetnum(), tgetstr(), tgetflag(), tputs(),
110 dnl tgoto() in libc, some have it in libtermcap, some have it in libncurses.
111 dnl When both libtermcap and libncurses exist, we prefer the latter, because
112 dnl libtermcap is being phased out.
113 AC_DEFUN([GINAC_TERMCAP],
114 [LIBTERMCAP=
115 case $host_os in
116 *mingw32*)
117  ;; dnl no termcap libraries are necessary (need hacked libreadline)
118 *)
119 AC_CHECK_FUNCS(tgetent)
120 if test "x$ac_cv_func_tgetent" = "xyes"; then
121     :
122 else
123     AC_CHECK_LIB(ncurses, tgetent, LIBTERMCAP="-lncurses")
124     if test -z "$LIBTERMCAP"; then
125         AC_CHECK_LIB(termcap, tgetent, LIBTERMCAP="-ltermcap")
126     fi
127 fi
128 ;;
129 esac
130 AC_SUBST(LIBTERMCAP)
131 ])
132
133 dnl Usage: GINAC_ERROR(message)
134 dnl This macro displays the warning "message" and sets the flag ginac_error
135 dnl to yes.
136 AC_DEFUN([GINAC_ERROR],[
137 ginac_error_txt="$ginac_error_txt
138 ** $1
139 "
140 ginac_error=yes])
141
142 dnl Usage: GINAC_WARNING(message)
143 dnl This macro displays the warning "message" and sets the flag ginac_warning
144 dnl to yes.
145 AC_DEFUN([GINAC_WARNING],[
146 ginac_warning_txt="$ginac_warning_txt
147 == $1
148 "
149 ginac_warning=yes])
150
151 dnl Usage: GINAC_CHECK_ERRORS
152 dnl (must be put at end of configure.in, because it exits on error)
153 dnl This macro displays a warning message if GINAC_ERROR or GINAC_WARNING 
154 dnl has occured previously.
155 AC_DEFUN([GINAC_CHECK_ERRORS],[
156 if test "x${ginac_error}" = "xyes"; then
157         echo
158     echo "**** The following problems have been detected by configure."
159     echo "**** Please check the messages below before running \"make\"."
160     echo "**** (see the section 'Common Problems' in the INSTALL file)"
161     echo "$ginac_error_txt"
162     if test "x${ginac_warning_txt}" != "x"; then
163         echo "${ginac_warning_txt}"
164     fi
165     if test "x$cache_file" != "x/dev/null"; then
166         echo "deleting cache ${cache_file}"
167         rm -f $cache_file
168     fi
169     exit 1
170 else 
171     if test "x${ginac_warning}" = "xyes"; then
172                 echo
173         echo "=== The following minor problems have been detected by configure."
174         echo "=== Please check the messages below before running \"make\"."
175         echo "=== (see the section 'Common Problems' in the INSTALL file)"
176         echo "$ginac_warning_txt"
177     fi
178     echo "Configuration of GiNaC $VERSION done. Now type \"make\"."
179 fi])
180
181 AC_DEFUN([GINAC_HAVE_RUSAGE],
182 [AC_CACHE_CHECK([whether struct rusage is declared in <sys/resource.h>],
183 ac_cv_have_rusage,
184  [AC_TRY_COMPILE([#include <sys/times.h>
185                   #include <sys/resource.h>],
186                   [struct rusage resUsage;
187                    getrusage(RUSAGE_SELF, &resUsage);
188                    return 0;],
189                  [ac_cv_have_rusage=yes],
190                  [ac_cv_have_rusage=no])
191 ])
192 CONFIG_RUSAGE="no"
193 if test "$ac_cv_have_rusage" = yes; then
194   CONFIG_RUSAGE="yes"
195   AC_DEFINE(HAVE_RUSAGE,,[define if struct rusage declared in <sys/resource.h>])
196 fi
197 AC_SUBST(CONFIG_RUSAGE)
198 ])
199
200 dnl Usage: GINAC_EXCOMPILER
201 dnl - Checks if dlopen is available
202 dnl - Allows user to disable GiNaC::compile_ex (e.g. for security reasons)
203 dnl Defines HAVE_LIBDL preprocessor macro, sets DL_LIBS and CONFIG_EXCOMPILER
204 dnl variables.
205 AC_DEFUN([GINAC_EXCOMPILER], [
206 CONFIG_EXCOMPILER=yes
207 DL_LIBS=""
208
209 AC_ARG_ENABLE([excompiler], 
210         [AS_HELP_STRING([--enable-excompiler], [Enable GiNaC::compile_ex (default: yes)])],
211         [if test "$enableval" = "no"; then
212                 CONFIG_EXCOMPILER="no"
213         fi],
214         [CONFIG_EXCOMPILER="yes"])
215
216 case $host_os in
217         *mingw32*)
218         CONFIG_EXCOMPILER="notsupported"
219         ;;
220         *)
221         ;;
222 esac
223
224 if test "$CONFIG_EXCOMPILER" = "yes"; then
225         AC_CHECK_HEADER([dlfcn.h], [CONFIG_EXCOMPILER="yes"], [CONFIG_EXCOMPILER="no"])
226 elif test "$CONFIG_EXCOMPILER" = "no"; then
227         AC_MSG_NOTICE([GiNaC::compile_ex disabled at user request.])
228 else
229         AC_MSG_NOTICE([GiNaC::compile_ex is not supported on $host_os.])
230 fi
231         
232 if test "$CONFIG_EXCOMPILER" = "yes"; then
233         dnl Some systems (GNU/Linux, Solaris) have dlopen in -ldl, some
234         dnl others (OpenBSD) -- in libc
235         found_dlopen_lib="no"
236         DL_LIBS="-ldl"
237         AC_CHECK_LIB(dl, dlopen, [found_dlopen_lib="yes"])
238         if test "$found_dlopen_lib" = "no"; then
239                 DL_LIBS=""
240                 AC_CHECK_FUNC(dlopen, [found_dlopen_lib="yes"])
241         fi
242         if test "$found_dlopen_lib" = "no"; then
243                 CONFIG_EXCOMPILER="no"
244                 AC_MSG_WARN([Could not found working dlopen(). GiNaC::compile_ex will be disabled.])
245         else
246                 AC_DEFINE(HAVE_LIBDL, 1, [set to 1 if dlopen() works.])
247         fi
248 fi
249 AC_SUBST(DL_LIBS)
250 AC_SUBST(CONFIG_EXCOMPILER)])
251