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