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