]> www.ginac.de Git - ginac.git/blob - ginac.m4
* Fix incompatibilities with recent versions of libreadline by having
[ginac.git] / ginac.m4
1 # Configure paths for GiNaC
2 # Richard Kreckel 12/12/2000
3 # borrowed from Christian Bauer
4 # stolen from Sam Lantinga
5 # stolen from Manish Singh
6 # stolen back from Frank Belew
7 # stolen from Manish Singh
8 # Shamelessly stolen from Owen Taylor
9
10 dnl AM_PATH_GINAC([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
11 dnl Test for GiNaC, and define GINACLIB_CPPFLAGS and GINACLIB_LIBS
12 dnl
13 AC_DEFUN(AM_PATH_GINAC,
14 [dnl 
15 dnl Get the cppflags and libraries from the ginac-config script
16 dnl
17 AC_ARG_WITH(ginac-prefix,[  --with-ginac-prefix=PFX Prefix where GiNaC is installed (optional)],
18             ginac_prefix="$withval", ginac_prefix="")
19 AC_ARG_WITH(ginac-exec-prefix,[  --with-ginac-exec-prefix=PFX Exec prefix where GiNaC is installed (optional)],
20             ginac_exec_prefix="$withval", ginac_exec_prefix="")
21 AC_ARG_ENABLE(ginactest, [  --disable-ginactest     Do not try to compile and run a test GiNaC program],
22               , enable_ginactest=yes)
23
24 if test x$ginac_exec_prefix != x ; then
25     ginac_args="$ginac_args --exec-prefix=$ginac_exec_prefix"
26     if test x${GINACLIB_CONFIG+set} != xset ; then
27         GINACLIB_CONFIG=$ginac_exec_prefix/bin/ginac-config
28     fi
29 fi
30 if test x$ginac_prefix != x ; then
31     ginac_args="$ginac_args --prefix=$ginac_prefix"
32     if test x${GINACLIB_CONFIG+set} != xset ; then
33         GINACLIB_CONFIG=$ginac_prefix/bin/ginac-config
34     fi
35 fi
36
37 AC_PATH_PROG(GINACLIB_CONFIG, ginac-config, no)
38 ginac_min_version=ifelse([$1], ,0.7.0,$1)
39 AC_MSG_CHECKING(for GiNaC - version >= $ginac_min_version)
40 if test "$GINACLIB_CONFIG" = "no" ; then
41     AC_MSG_RESULT(no)
42     echo "*** The ginac-config script installed by GiNaC could not be found"
43     echo "*** If GiNaC was installed in PREFIX, make sure PREFIX/bin is in"
44     echo "*** your path, or set the GINACLIB_CONFIG environment variable to the"
45     echo "*** full path to ginac-config."
46     ifelse([$3], , :, [$3])
47 else
48 dnl Parse required version and the result of ginac-config.
49     ginac_min_major_version=`echo $ginac_min_version | \
50             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
51     ginac_min_minor_version=`echo $ginac_min_version | \
52             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
53     ginac_min_micro_version=`echo $ginac_min_version | \
54             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
55     GINACLIB_CPPFLAGS=`$GINACLIB_CONFIG $ginac_args --cppflags`
56     GINACLIB_LIBS=`$GINACLIB_CONFIG $ginac_args --libs`
57     ginac_config_major_version=`$GINACLIB_CONFIG $ginac_args --version | \
58             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
59     ginac_config_minor_version=`$GINACLIB_CONFIG $ginac_args --version | \
60             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
61     ginac_config_micro_version=`$GINACLIB_CONFIG $ginac_args --version | \
62             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
63 dnl Check if the installed GiNaC is sufficiently new according to ginac-config.
64     if test \( $ginac_config_major_version -lt $ginac_min_major_version \) -o \
65             \( $ginac_config_major_version -eq $ginac_min_major_version -a $ginac_config_minor_version -lt $ginac_min_minor_version \) -o \
66             \( $ginac_config_major_version -eq $ginac_min_major_version -a $ginac_config_minor_version -eq $ginac_min_minor_version -a $ginac_config_micro_version -lt $ginac_min_micro_version \); then
67         echo -e "\n*** 'ginac-config --version' returned $ginac_config_major_version.$ginac_config_minor_version.$ginac_config_micro_version, but the minimum version"
68         echo "*** of GiNaC required is $ginac_min_major_version.$ginac_min_minor_version.$ginac_min_micro_version. If ginac-config is correct, then it is"
69         echo "*** best to upgrade to the required version."
70         echo "*** If ginac-config was wrong, set the environment variable GINACLIB_CONFIG"
71         echo "*** to point to the correct copy of ginac-config, and remove the file"
72         echo "*** config.cache before re-running configure."
73         ifelse([$3], , :, [$3])
74     else
75 dnl The versions match so far.  Now do a sanity check: Does the result of ginac-config
76 dnl match the version of the headers and the version built into the library, too?
77         no_ginac=""
78         if test "x$enable_ginactest" = "xyes" ; then
79             ac_save_CPPFLAGS="$CPPFLAGS"
80             ac_save_LIBS="$LIBS"
81             CPPFLAGS="$CPPFLAGS $GINACLIB_CPPFLAGS"
82             LIBS="$LIBS $GINACLIB_LIBS"
83             rm -f conf.ginactest
84             AC_TRY_RUN([
85 #include <stdio.h>
86 #include <string.h>
87 #include <ginac/version.h>
88
89 /* we do not #include <stdlib.h> because autoconf in C++ mode inserts a
90    prototype for exit() that conflicts with the one in stdlib.h */
91 extern "C" int system(const char *);
92
93 int main(void)
94 {
95     int major, minor, micro;
96     char *tmp_version;
97
98     system("touch conf.ginactest");
99
100     if ((GINACLIB_MAJOR_VERSION != $ginac_config_major_version) ||
101         (GINACLIB_MINOR_VERSION != $ginac_config_minor_version) ||
102         (GINACLIB_MICRO_VERSION != $ginac_config_micro_version)) {
103         printf("\n*** 'ginac-config --version' returned %d.%d.%d, but the header file I found\n", $ginac_config_major_version, $ginac_config_minor_version, $ginac_config_micro_version);
104         printf("*** corresponds to %d.%d.%d. This mismatch suggests your installation of GiNaC\n", GINACLIB_MAJOR_VERSION, GINACLIB_MINOR_VERSION, GINACLIB_MICRO_VERSION);
105         printf("*** is corrupted or you have specified some wrong -I compiler flags.\n");
106         printf("*** Please inquire and consider reinstalling GiNaC.\n");
107         return 1;
108     }
109     if ((GiNaC::version_major != $ginac_config_major_version) ||
110         (GiNaC::version_minor != $ginac_config_minor_version) ||
111         (GiNaC::version_micro != $ginac_config_micro_version)) {
112         printf("\n*** 'ginac-config --version' returned %d.%d.%d, but the library I found\n", $ginac_config_major_version, $ginac_config_minor_version, $ginac_config_micro_version);
113         printf("*** corresponds to %d.%d.%d. This mismatch suggests your installation of GiNaC\n", GiNaC::version_major, GiNaC::version_minor, GiNaC::version_micro);
114         printf("*** is corrupted or you have specified some wrong -L compiler flags.\n");
115         printf("*** Please inquire and consider reinstalling GiNaC.\n");
116         return 1;
117     }
118     return 0;
119 }
120 ],, no_ginac=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
121             CPPFLAGS="$ac_save_CPPFLAGS"
122             LIBS="$ac_save_LIBS"
123         fi
124         if test "x$no_ginac" = x ; then
125             AC_MSG_RESULT([yes, `$GINACLIB_CONFIG $ginac_args --version`])
126             ifelse([$2], , :, [$2])
127         else
128             AC_MSG_RESULT(no)
129             if test ! -f conf.ginactest ; then
130                 echo "*** Could not run GiNaC test program, checking why..."
131                 CPPFLAGS="$CFLAGS $GINACLIB_CPPFLAGS"
132                 LIBS="$LIBS $GINACLIB_LIBS"
133                 AC_TRY_LINK([
134 #include <stdio.h>
135 #include <ginac/version.h>
136 ],              [ return 0; ],
137                 [ echo "*** The test program compiled, but did not run. This usually means"
138                   echo "*** that the run-time linker is not finding GiNaC or finding the wrong"
139                   echo "*** version of GiNaC. If it is not finding GiNaC, you'll need to set your"
140                   echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
141                   echo "*** to the installed location. Also, make sure you have run ldconfig if that"
142                   echo "*** is required on your system."],
143                 [ echo "*** The test program failed to compile or link. See the file config.log for the"
144                   echo "*** exact error that occured. This usually means GiNaC was incorrectly installed"
145                   echo "*** or that you have moved GiNaC since it was installed. In the latter case, you"
146                   echo "*** may want to edit the ginac-config script: $GINACLIB_CONFIG." ])
147                 CPPFLAGS="$ac_save_CPPFLAGS"
148                 LIBS="$ac_save_LIBS"
149             fi
150             GINACLIB_CPPFLAGS=""
151             GINACLIB_LIBS=""
152             ifelse([$3], , :, [$3])
153         fi
154     fi
155 fi
156 AC_SUBST(GINACLIB_CPPFLAGS)
157 AC_SUBST(GINACLIB_LIBS)
158 rm -f conf.ginactest
159 ])