]> www.ginac.de Git - cln.git/blob - cln.m4
some minor fixes with respect to RPM package building
[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_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   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 $cln_config_args --cppflags`
45     LIBCLN_LIBS=`$CLN_CONFIG $cln_config_args --libs`
46     cln_config_major_version=`$CLN_CONFIG $cln_config_args --version | \
47            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
48     cln_config_minor_version=`$CLN_CONFIG $cln_config_args --version | \
49            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
50     cln_config_micro_version=`$CLN_CONFIG $cln_config_args --version | \
51            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
52     if test "x$enable_clntest" = "xyes" ; then
53       ac_save_CPPFLAGS="$CPPFLAGS"
54       ac_save_LIBS="$LIBS"
55       CPPFLAGS="$CPPFLAGS $LIBCLN_CPPFLAGS"
56       LIBS="$LIBS $LIBCLN_LIBS"
57 dnl
58 dnl Now check if the installed CLN is sufficiently new. (Also sanity
59 dnl checks the results of cln-config to some extent
60 dnl
61       rm -f conf.clntest
62       AC_TRY_RUN([
63 #include <stdio.h>
64 #include <string.h>
65 #include <cln/config.h>
66
67 /* we do not #include <stdlib.h> because autoconf in C++ mode inserts a
68    prototype for exit() that conflicts with the one in stdlib.h */
69 extern "C" int system(const char *);
70
71 char* my_strdup (char *str)
72 {
73   char *new_str;
74
75   if (str) {
76     new_str = new char[(strlen (str) + 1) * sizeof(char)];
77     strcpy (new_str, str);
78   } else
79     new_str = NULL;
80
81   return new_str;
82 }
83
84 int main()
85 {
86   int major, minor, micro;
87   char *tmp_version;
88
89   system("touch conf.clntest");
90
91   /* HP/UX 9 (%@#!) writes to sscanf strings */
92   tmp_version = my_strdup("$min_cln_version");
93   if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
94      printf("%s, bad version string\n", "$min_cln_version");
95      return 1;
96   }
97
98   if (($cln_config_major_version > major) ||
99      (($cln_config_major_version == major) && ($cln_config_minor_version > minor)) ||
100      (($cln_config_major_version == major) && ($cln_config_minor_version == minor) && ($cln_config_micro_version >= micro))) {
101     if ((CL_VERSION_MAJOR == $cln_config_major_version) &&
102         (CL_VERSION_MINOR == $cln_config_minor_version) &&
103         (CL_VERSION_PATCHLEVEL == $cln_config_micro_version)) {
104       return 0;
105     } else {
106       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);
107       printf("*** corresponds to %d.%d.%d. This mismatch suggests your installation of CLN\n", CL_VERSION_MAJOR, CL_VERSION_MINOR, CL_VERSION_PATCHLEVEL);
108       printf("*** is corrupted. Please inquire and consider reinstalling CLN.\n");
109       return 1;
110     }
111   } else {
112     printf("\n*** 'cln-config --version' returned %d.%d.%d, but the minimum version\n", $cln_config_major_version, $cln_config_minor_version, $cln_config_micro_version);
113     printf("*** of CLN required is %d.%d.%d. If cln-config is correct, then it is\n", major, minor, micro);
114     printf("*** best to upgrade to the required version.\n");
115     printf("*** If cln-config was wrong, set the environment variable CLN_CONFIG\n");
116     printf("*** to point to the correct copy of cln-config, and remove the file\n");
117     printf("*** config.cache before re-running configure\n");
118     return 1;
119   }
120 }
121 ],, no_cln=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
122        CPPFLAGS="$ac_save_CPPFLAGS"
123        LIBS="$ac_save_LIBS"
124      fi
125   fi
126   if test "x$no_cln" = x ; then
127      AC_MSG_RESULT([yes, `$CLN_CONFIG --version`])
128      ifelse([$2], , :, [$2])     
129   else
130      AC_MSG_RESULT(no)
131      if test "$CLN_CONFIG" = "no" ; then
132        echo "*** The cln-config script installed by CLN could not be found"
133        echo "*** If CLN was installed in PREFIX, make sure PREFIX/bin is in"
134        echo "*** your path, or set the CLN_CONFIG environment variable to the"
135        echo "*** full path to cln-config."
136      else
137        if test -f conf.clntest ; then
138         :
139        else
140           echo "*** Could not run CLN test program, checking why..."
141           CPPFLAGS="$CFLAGS $LIBCLN_CPPFLAGS"
142           LIBS="$LIBS $LIBCLN_LIBS"
143           AC_TRY_LINK([
144 #include <stdio.h>
145 #include <cln/cln.h>
146 ],      [ return 0; ],
147         [ echo "*** The test program compiled, but did not run. This usually means"
148           echo "*** that the run-time linker is not finding CLN or finding the wrong"
149           echo "*** version of CLN. If it is not finding CLN, you'll need to set your"
150           echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
151           echo "*** to the installed location  Also, make sure you have run ldconfig if that"
152           echo "*** is required on your system"
153           echo "***"
154           echo "*** If you have an old version installed, it is best to remove it, although"
155           echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
156         [ echo "*** The test program failed to compile or link. See the file config.log for the"
157           echo "*** exact error that occured. This usually means CLN was incorrectly installed"
158           echo "*** or that you have moved CLN since it was installed. In the latter case, you"
159           echo "*** may want to edit the cln-config script: $CLN_CONFIG" ])
160           CPPFLAGS="$ac_save_CPPFLAGS"
161           LIBS="$ac_save_LIBS"
162        fi
163      fi
164      LIBCLN_CPPFLAGS=""
165      LIBCLN_LIBS=""
166      ifelse([$3], , :, [$3])
167   fi
168   AC_SUBST(LIBCLN_CPPFLAGS)
169   AC_SUBST(LIBCLN_LIBS)
170   rm -f conf.clntest
171 ])