]> www.ginac.de Git - cln.git/blob - cln.m4
* cln.m4: Fixed typo.
[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_major_version=`$CLN_CONFIG $cln_config_args --version | \
58             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
59     cln_config_minor_version=`$CLN_CONFIG $cln_config_args --version | \
60             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
61     cln_config_micro_version=`$CLN_CONFIG $cln_config_args --version | \
62             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
63 dnl Check if the installed CLN is sufficiently new according to cln-config.
64     if test \( $cln_config_major_version -lt $cln_min_major_version \) -o \
65             \( $cln_config_major_version -eq $cln_min_major_version -a $cln_config_minor_version -lt $cln_min_minor_version \) -o \
66             \( $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
67         echo -e "\n*** 'cln-config --version' returned $cln_config_major_version.$cln_config_minor_version.$cln_config_micro_version, but the minimum version"
68         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"
69         echo "*** best to upgrade to the required version."
70         echo "*** If cln-config was wrong, set the environment variable CLN_CONFIG"
71         echo "*** to point to the correct copy of cln-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 cln-config
76 dnl match the version of the headers and the version built into the library, too?
77         no_cln=""
78         if test "x$enable_clntest" = "xyes" ; then
79             ac_save_CPPFLAGS="$CPPFLAGS"
80             ac_save_LIBS="$LIBS"
81             CPPFLAGS="$CPPFLAGS $CLN_CPPFLAGS"
82             LIBS="$LIBS $CLN_LIBS"
83             rm -f conf.clntest
84             AC_TRY_RUN([
85 #include <stdio.h>
86 #include <string.h>
87 #include <cln/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.clntest");
99
100     if ((CL_VERSION_MAJOR != $cln_config_major_version) ||
101         (CL_VERSION_MINOR != $cln_config_minor_version) ||
102         (CL_VERSION_PATCHLEVEL != $cln_config_micro_version)) {
103         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);
104         printf("*** corresponds to %d.%d.%d. This mismatch suggests your installation of CLN\n", CL_VERSION_MAJOR, CL_VERSION_MINOR, CL_VERSION_PATCHLEVEL);
105         printf("*** is corrupted or you have specified some wrong -I compiler flags.\n");
106         printf("*** Please inquire and consider reinstalling CLN.\n");
107         return 1;
108     }
109     if ((cln::version_major != $cln_config_major_version) ||
110         (cln::version_minor != $cln_config_minor_version) ||
111         (cln::version_patchlevel != $cln_config_micro_version)) {
112         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);
113         printf("*** corresponds to %d.%d.%d. This mismatch suggests your installation of CLN\n", cln::version_major, cln::version_minor, cln::version_patchlevel);
114         printf("*** is corrupted or you have specified some wrong -L compiler flags.\n");
115         printf("*** Please inquire and consider reinstalling CLN.\n");
116         return 1;
117     }
118     return 0;
119 }
120 ],, no_cln=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_cln" = x ; then
125             AC_MSG_RESULT([yes, `$CLN_CONFIG $cln_config_args --version`])
126             ifelse([$2], , :, [$2])
127         else
128             AC_MSG_RESULT(no)
129             if test ! -f conf.clntest ; then
130                 echo "*** Could not run CLN test program, checking why..."
131                 CPPFLAGS="$CFLAGS $CLN_CPPFLAGS"
132                 LIBS="$LIBS $CLN_LIBS"
133                 AC_TRY_LINK([
134 #include <stdio.h>
135 #include <cln/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 CLN or finding the wrong"
139                   echo "*** version of CLN. If it is not finding CLN, 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 CLN was incorrectly installed"
145                   echo "*** or that you have moved CLN since it was installed. In the latter case, you"
146                   echo "*** may want to edit the cln-config script: $CLN_CONFIG." ])
147                 CPPFLAGS="$ac_save_CPPFLAGS"
148                 LIBS="$ac_save_LIBS"
149             fi
150             CLN_CPPFLAGS=""
151             CLN_LIBS=""
152             ifelse([$3], , :, [$3])
153         fi
154     fi
155 fi
156 AC_SUBST(CLN_CPPFLAGS)
157 AC_SUBST(CLN_LIBS)
158 rm -f conf.clntest
159 ])