]> www.ginac.de Git - cln.git/blob - cln.m4
* cln.m4: New file.
[cln.git] / cln.m4
1 # Configure paths for CLN
2 # Richard Kreckel 11/17/2000
3 # stolen 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_LIBCLN([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
11 dnl Test for installed CLN library, and define LIBCLN_CPPFLAGS and LIBCLN_LIBS
12 dnl
13 AC_DEFUN(AC_PATH_LIBCLN,
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_prefix="$withval", cln_prefix="")
19 AC_ARG_WITH(cln-exec-prefix,[  --with-cln-exec-prefix=PFX Exec prefix where CLN is installed (optional)],
20             cln_exec_prefix="$withval", cln_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_exec_prefix != x ; then
25      cln_args="$cln_args --exec-prefix=$cln_exec_prefix"
26      if test x${CLN_CONFIG+set} != xset ; then
27         CLN_CONFIG=$cln_exec_prefix/bin/cln-config
28      fi
29   fi
30   if test x$cln_prefix != x ; then
31      cln_args="$cln_args --prefix=$cln_prefix"
32      if test x${CLN_CONFIG+set} != xset ; then
33         CLN_CONFIG=$cln_prefix/bin/cln-config
34      fi
35   fi
36
37   AC_PATH_PROG(CLN_CONFIG, cln-config, no)
38   min_cln_version=ifelse([$1], ,1.1.0,$1)
39   AC_MSG_CHECKING(for CLN - version >= $min_cln_version)
40   no_cln=""
41   if test "$CLN_CONFIG" = "no" ; then
42     no_cln=yes
43   else
44     LIBCLN_CPPFLAGS=`$CLN_CONFIG $clnconf_args --cppflags`
45     LIBCLN_LIBS=`$CLN_CONFIG $clnconf_args --libs`
46
47     cln_major_version=`$CLN_CONFIG $cln_args --version | \
48            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
49     cln_minor_version=`$CLN_CONFIG $cln_args --version | \
50            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
51     cln_micro_version=`$CLN_CONFIG $cln_config_args --version | \
52            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
53     if test "x$enable_clntest" = "xyes" ; then
54       ac_save_CPPFLAGS="$CPPFLAGS"
55       ac_save_LIBS="$LIBS"
56       CPPFLAGS="$CPPFLAGS $LIBCLN_CPPFLAGS"
57       LIBS="$LIBS $LIBCLN_LIBS"
58 dnl
59 dnl Now check if the installed CLN is sufficiently new. (Also sanity
60 dnl checks the results of cln-config to some extent
61 dnl
62       rm -f conf.clntest
63       AC_TRY_RUN([
64 #include <stdio.h>
65 #include <stdlib.h>
66 #include <string.h>
67 #include <cln/config.h>
68
69 int main ()
70 {
71   int major, minor, micro;
72   char *tmp_version;
73
74   system("touch conf.clntest");
75
76   tmp_version = strdup("$min_cln_version");
77   if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
78      printf("%s, bad version string\n", "$min_cln_version");
79      exit(1);
80   }
81
82   if (($cln_major_version > major) ||
83      (($cln_major_version == major) && ($cln_minor_version > minor)) ||
84      (($cln_major_version == major) && ($cln_minor_version == minor) && ($cln_micro_version >= micro))) {
85     if ((CL_VERSION_MAJOR == $cln_major_version) &&
86         (CL_VERSION_MINOR == $cln_minor_version) &&
87         (CL_VERSION_PATCHLEVEL == $cln_micro_version)) {
88       return 0;
89     } else {
90       printf("\n*** 'cln-config --version' returned %d.%d.%d, but the header file I found\n", $cln_major_version, $cln_minor_version, $cln_micro_version);
91       printf("*** corresponds to %d.%d.%d. This mismatch suggests your installation of CLN\n", CL_VERSION_MAJOR, CL_VERSION_MINOR, CL_VERSION_PATCHLEVEL);
92       printf("*** is corrupted. Please inquire and consider reinstalling CLN.\n");
93       return 1;
94     }
95   } else {
96     printf("\n*** 'cln-config --version' returned %d.%d.%d, but the minimum version\n", $cln_major_version, $cln_minor_version, $cln_micro_version);
97     printf("*** of CLN required is %d.%d.%d. If cln-config is correct, then it is\n", major, minor, micro);
98     printf("*** best to upgrade to the required version.\n");
99     printf("*** If cln-config was wrong, set the environment variable CLN_CONFIG\n");
100     printf("*** to point to the correct copy of cln-config, and remove the file\n");
101     printf("*** config.cache before re-running configure\n");
102     return 1;
103   }
104 }
105 ],, no_cln=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
106        CPPFLAGS="$ac_save_CPPFLAGS"
107        LIBS="$ac_save_LIBS"
108      fi
109   fi
110   if test "x$no_cln" = x ; then
111      AC_MSG_RESULT(yes)
112      ifelse([$2], , :, [$2])     
113   else
114      AC_MSG_RESULT(no)
115      if test "$CLN_CONFIG" = "no" ; then
116        echo "*** The cln-config script installed by CLN could not be found"
117        echo "*** If CLN was installed in PREFIX, make sure PREFIX/bin is in"
118        echo "*** your path, or set the CLN_CONFIG environment variable to the"
119        echo "*** full path to cln-config."
120      else
121        if test -f conf.clntest ; then
122         :
123        else
124           echo "*** Could not run CLN test program, checking why..."
125           CPPFLAGS="$CFLAGS $LIBCLN_CPPFLAGS"
126           LIBS="$LIBS $LIBCLN_LIBS"
127           AC_TRY_LINK([
128 #include <stdio.h>
129 #include <cln/cln.h>
130 ],      [ return 0; ],
131         [ echo "*** The test program compiled, but did not run. This usually means"
132           echo "*** that the run-time linker is not finding CLN or finding the wrong"
133           echo "*** version of CLN. If it is not finding CLN, you'll need to set your"
134           echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
135           echo "*** to the installed location  Also, make sure you have run ldconfig if that"
136           echo "*** is required on your system"
137           echo "***"
138           echo "*** If you have an old version installed, it is best to remove it, although"
139           echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
140         [ echo "*** The test program failed to compile or link. See the file config.log for the"
141           echo "*** exact error that occured. This usually means CLN was incorrectly installed"
142           echo "*** or that you have moved CLN since it was installed. In the latter case, you"
143           echo "*** may want to edit the cln-config script: $CLN_CONFIG" ])
144           CPPFLAGS="$ac_save_CPPFLAGS"
145           LIBS="$ac_save_LIBS"
146        fi
147      fi
148      LIBCLN_CPPFLAGS=""
149      LIBCLN_LIBS=""
150      ifelse([$3], , :, [$3])
151   fi
152   AC_SUBST(LIBCLN_CPPFLAGS)
153   AC_SUBST(LIBCLN_LIBS)
154   rm -f conf.clntest
155 ])