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