build: faster check for standard C++ headers.
[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([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([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([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 "**** The following problems have been detected by configure."
125     echo "**** Please check the messages below before running \"make\"."
126     echo "**** (see the section 'Common Problems' in the INSTALL file)"
127     echo "$ginac_error_txt"
128     if test "x${ginac_warning_txt}" != "x"; then
129         echo "${ginac_warning_txt}"
130     fi
131     if test "x$cache_file" != "x/dev/null"; then
132         echo "deleting cache ${cache_file}"
133         rm -f $cache_file
134     fi
135     exit 1
136 else 
137     if test "x${ginac_warning}" = "xyes"; then
138         echo "=== The following minor problems have been detected by configure."
139         echo "=== Please check the messages below before running \"make\"."
140         echo "=== (see the section 'Common Problems' in the INSTALL file)"
141         echo "$ginac_warning_txt"
142     fi
143     echo "Configuration of GiNaC $VERSION done. Now type \"make\"."
144 fi])
145
146 AC_DEFUN([GINAC_HAVE_RUSAGE],
147 [AC_CACHE_CHECK([whether struct rusage is declared in <sys/resource.h>],
148 ac_cv_have_rusage,
149  [AC_TRY_COMPILE([#include <sys/times.h>
150                   #include <sys/resource.h>],
151                   [struct rusage resUsage;
152                    getrusage(RUSAGE_SELF, &resUsage);
153                    return 0;],
154                  [ac_cv_have_rusage=yes],
155                  [ac_cv_have_rusage=no])
156 ])
157 CONFIG_RUSAGE="no"
158 if test "$ac_cv_have_rusage" = yes; then
159   CONFIG_RUSAGE="yes"
160   AC_DEFINE(HAVE_RUSAGE,,[define if struct rusage declared in <sys/resource.h>])
161 fi
162 AC_SUBST(CONFIG_RUSAGE)
163 ])