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