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