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