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