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