]> www.ginac.de Git - ginac.git/blob - acinclude.m4
build: don't run any ${host} binaries while checking for readline.
[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_LIBREADLINE
8 dnl
9 dnl Check if GNU readline library and headers are avialable.
10 dnl Defines GINSH_LIBS variable, and HAVE_LIBREADLINE,
11 dnl HAVE_READLINE_READLINE_H, HAVE_READLINE_HISTORY_H preprocessor macros.
12 dnl
13 dnl Note: this macro rejects readline versions <= 4.2 and non-GNU
14 dnl implementations.
15 dnl
16 AC_DEFUN([GINAC_READLINE],[
17 AC_REQUIRE([GINAC_TERMCAP])
18 GINSH_LIBS=""
19 AC_CHECK_HEADERS(readline/readline.h readline/history.h)
20 if test "x${ac_cv_header_readline_readline_h}" != "xyes" -o "x${ac_cv_header_readline_history_h}" != "xyes"; then
21         GINAC_WARNING([readline headers could not be found.])
22 else
23         AC_CACHE_CHECK([for version of libreadline], [ginac_cv_rl_supported], [
24                 ginac_cv_rl_supported="no"
25                 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
26                         #include <stdio.h>
27                         #include <readline/readline.h>
28                         #if !defined(RL_VERSION_MAJOR) || !defined(RL_VERSION_MINOR)
29                         #error "Ancient/unsupported version of readline"
30                         #endif]])],
31                         [ginac_cv_rl_supported="yes"])])
32         if test "x${ginac_cv_rl_supported}" != "xyes"; then
33                 GINAC_WARNING([Unsupported version of readline (<= 4.2 or non-GNU).])
34         else
35                 save_LIBS="$LIBS"
36                 LIBS="$LIBTERMCAP $LIBS"
37                 AC_CHECK_LIB(readline, readline)
38                 if test "x${ac_cv_lib_readline_readline}" != "xyes"; then
39                         GINAC_WARNING([libreadline could not be found.])
40                 fi
41                 GINSH_LIBS="$LIBS"
42                 LIBS="$save_LIBS"
43         fi
44 fi
45 AC_SUBST(GINSH_LIBS)])
46         
47 dnl Usage: GINAC_TERMCAP
48 dnl libreadline is based on the termcap functions.
49 dnl Some systems have tgetent(), tgetnum(), tgetstr(), tgetflag(), tputs(),
50 dnl tgoto() in libc, some have it in libtermcap, some have it in libncurses.
51 dnl When both libtermcap and libncurses exist, we prefer the latter, because
52 dnl libtermcap is being phased out.
53 AC_DEFUN([GINAC_TERMCAP],
54 [LIBTERMCAP=
55 case $host_os in
56 *mingw32*)
57  ;; dnl no termcap libraries are necessary (need hacked libreadline)
58 *)
59 AC_CHECK_FUNCS(tgetent)
60 if test "x$ac_cv_func_tgetent" = "xyes"; then
61     :
62 else
63     AC_CHECK_LIB(ncurses, tgetent, LIBTERMCAP="-lncurses")
64     if test -z "$LIBTERMCAP"; then
65         AC_CHECK_LIB(termcap, tgetent, LIBTERMCAP="-ltermcap")
66     fi
67 fi
68 ;;
69 esac
70 AC_SUBST(LIBTERMCAP)
71 ])
72
73 dnl Usage: GINAC_ERROR(message)
74 dnl This macro displays the warning "message" and sets the flag ginac_error
75 dnl to yes.
76 AC_DEFUN([GINAC_ERROR],[
77 ginac_error_txt="$ginac_error_txt
78 ** $1
79 "
80 ginac_error=yes])
81
82 dnl Usage: GINAC_WARNING(message)
83 dnl This macro displays the warning "message" and sets the flag ginac_warning
84 dnl to yes.
85 AC_DEFUN([GINAC_WARNING],[
86 ginac_warning_txt="$ginac_warning_txt
87 == $1
88 "
89 ginac_warning=yes])
90
91 dnl Usage: GINAC_CHECK_ERRORS
92 dnl (must be put at end of configure.in, because it exits on error)
93 dnl This macro displays a warning message if GINAC_ERROR or GINAC_WARNING 
94 dnl has occured previously.
95 AC_DEFUN([GINAC_CHECK_ERRORS],[
96 if test "x${ginac_error}" = "xyes"; then
97     echo "**** The following problems have been detected by configure."
98     echo "**** Please check the messages below before running \"make\"."
99     echo "**** (see the section 'Common Problems' in the INSTALL file)"
100     echo "$ginac_error_txt"
101     if test "x${ginac_warning_txt}" != "x"; then
102         echo "${ginac_warning_txt}"
103     fi
104     if test "x$cache_file" != "x/dev/null"; then
105         echo "deleting cache ${cache_file}"
106         rm -f $cache_file
107     fi
108     exit 1
109 else 
110     if test "x${ginac_warning}" = "xyes"; then
111         echo "=== The following minor problems have been detected by configure."
112         echo "=== Please check the messages below before running \"make\"."
113         echo "=== (see the section 'Common Problems' in the INSTALL file)"
114         echo "$ginac_warning_txt"
115     fi
116     echo "Configuration of GiNaC $VERSION done. Now type \"make\"."
117 fi])
118
119 AC_DEFUN([GINAC_HAVE_RUSAGE],
120 [AC_CACHE_CHECK([whether struct rusage is declared in <sys/resource.h>],
121 ac_cv_have_rusage,
122  [AC_TRY_COMPILE([#include <sys/times.h>
123                   #include <sys/resource.h>],
124                   [struct rusage resUsage;
125                    getrusage(RUSAGE_SELF, &resUsage);
126                    return 0;],
127                  [ac_cv_have_rusage=yes],
128                  [ac_cv_have_rusage=no])
129 ])
130 CONFIG_RUSAGE="no"
131 if test "$ac_cv_have_rusage" = yes; then
132   CONFIG_RUSAGE="yes"
133   AC_DEFINE(HAVE_RUSAGE,,[define if struct rusage declared in <sys/resource.h>])
134 fi
135 AC_SUBST(CONFIG_RUSAGE)
136 ])