*** empty log message ***
[gnutls.git] / opencdk.m4
blob31d7df3045f3df197e23fcaaa0fb39ecd293809b
1 dnl Autoconf macros for opencdk
2 dnl $id$
4 # Configure paths for LIBOPENCDK
5 # Shamelessly stolen from the one of XDELTA by Owen Taylor
6 # Werner Koch   99-12-09
7 # Modified for OpenCDK
8 # Timo Schulz   02-04-06
10 dnl AM_PATH_LIBOPENCDK([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
11 dnl Test for libopencdk, and define CDK_CFLAGS and CDK_LIBS
12 dnl
13 AC_DEFUN(AM_PATH_LIBOPENCDK,
14 [dnl
15 dnl Get the cflags and libraries from the opencdk-config script
16 dnl
17 AC_ARG_WITH(libopen-prefix,
18           [  --with-libopencdk-prefix=PFX   Prefix where libopencdk is installed (optional)],
19           libopencdk_config_prefix="$withval", libopencdk_config_prefix="")
20 AC_ARG_ENABLE(libopencdktest,
21           [  --disable-libopencdktest    Do not try to compile and run a test libopencdk program],
22           , enable_libopencdktest=yes)
24   if test x$libopencdk_config_prefix != x ; then
25      libopencdk_config_args="$libopencdk_config_args --prefix=$libopencdk_config_prefix"
26      if test x${LIBOPENCDK_CONFIG+set} != xset ; then
27         LIBOPENCDK_CONFIG=$libopencdk_config_prefix/bin/opencdk-config
28      fi
29   fi
31   AC_PATH_PROG(LIBOPENCDK_CONFIG, opencdk-config, no)
32   min_libopencdk_version=ifelse([$1], ,1.1.0,$1)
33   AC_MSG_CHECKING(for libopencdk - version >= $min_libopencdk_version)
34   no_libopencdk=""
35   if test "$LIBOPENCDK_CONFIG" = "no" ; then
36     no_libopencdk=yes
37   else
38     LIBOPENCDK_CFLAGS=`$LIBOPENCDK_CONFIG $libopencdk_config_args --cflags`
39     LIBOPENCDK_LIBS=`$LIBOPENCDK_CONFIG $libopencdk_config_args --libs`
40     libopencdk_config_version=`$LIBOPENCDK_CONFIG $libopencdk_config_args --version`
41     if test "x$enable_libopencdktest" = "xyes" ; then
42       ac_save_CFLAGS="$CFLAGS"
43       ac_save_LIBS="$LIBS"
44       CFLAGS="$CFLAGS $LIBOPENCDK_CFLAGS"
45       LIBS="$LIBS $LIBOPENCDK_LIBS"
46 dnl
47 dnl Now check if the installed libopencdk is sufficiently new. Also sanity
48 dnl checks the results of opencdk-config to some extent
49 dnl
50       rm -f conf.libopencdktest
51       AC_TRY_RUN([
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <string.h>
55 #include <opencdk.h>
57 int
58 main ()
60     system ("touch conf.libopencdktest");
62     if( strcmp( cdk_check_version(NULL), "$libopencdk_config_version" ) )
63     {
64       printf("\n*** 'opencdk-config --version' returned %s, but LIBOPENCDK (%s)\n",
65              "$libopencdk_config_version", cdk_check_version(NULL) );
66       printf("*** was found! If opencdk-config was correct, then it is best\n");
67       printf("*** to remove the old version of LIBOPENCDK. You may also be able to fix the error\n");
68       printf("*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing\n");
69       printf("*** /etc/ld.so.conf. Make sure you have run ldconfig if that is\n");
70       printf("*** required on your system.\n");
71       printf("*** If opencdk-config was wrong, set the environment variable LIBOPENCDK_CONFIG\n");
72       printf("*** to point to the correct copy of opencdk-config, and remove the file config.cache\n");
73       printf("*** before re-running configure\n");
74     }
75     else if ( strcmp(cdk_check_version(NULL), OPENCDK_VERSION ) )
76     {
77       printf("\n*** LIBOPENCDK header file (version %s) does not match\n", OPENCDK_VERSION);
78       printf("*** library (version %s)\n", cdk_check_version(NULL) );
79     }
80     else
81     {
82       if ( cdk_check_version( "$min_libopencdk_version" ) )
83       {
84         return 0;
85       }
86      else
87       {
88         printf("no\n*** An old version of LIBOPENCDK (%s) was found.\n",
89                 cdk_check_version(NULL) );
90         printf("*** You need a version of LIBOPENCDK newer than %s. The latest version of\n",
91                "$min_libopencdk_version" );
92         printf("*** LIBOPENCDK is always available from ftp://ftp.gnupg.org/pub/libopencdk/gnupg.\n");
93         printf("*** (It is distributed along with GnuPG).\n");
94         printf("*** \n");
95         printf("*** If you have already installed a sufficiently new version, this error\n");
96         printf("*** probably means that the wrong copy of the opencdk-config shell script is\n");
97         printf("*** being found. The easiest way to fix this is to remove the old version\n");
98         printf("*** of LIBOPENCDK, but you can also set the LIBOPENCDK_CONFIG environment to point to the\n");
99         printf("*** correct copy of opencdk-config. (In this case, you will have to\n");
100         printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
101         printf("*** so that the correct libraries are found at run-time))\n");
102       }
103     }
104   return 1;
106 ],, no_libopencdk=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
107        CFLAGS="$ac_save_CFLAGS"
108        LIBS="$ac_save_LIBS"
109      fi
110   fi
111   if test "x$no_libopencdk" = x ; then
112      AC_MSG_RESULT(yes)
113      ifelse([$2], , :, [$2])
114   else
115      if test -f conf.libopencdktest ; then
116         :
117      else
118         AC_MSG_RESULT(no)
119      fi
120      if test "$LIBOPENCDK_CONFIG" = "no" ; then
121        echo "*** The opencdk-config script installed by LIBOPENCDK could not be found"
122        echo "*** If LIBOPENCDK was installed in PREFIX, make sure PREFIX/bin is in"
123        echo "*** your path, or set the LIBOPENCDK_CONFIG environment variable to the"
124        echo "*** full path to opencdk-config."
125      else
126        if test -f conf.libopencdktest ; then
127         :
128        else
129           echo "*** Could not run libopencdk test program, checking why..."
130           CFLAGS="$CFLAGS $LIBOPENCDK_CFLAGS"
131           LIBS="$LIBS $LIBOPENCDK_LIBS"
132           AC_TRY_LINK([
133 #include <stdio.h>
134 #include <stdlib.h>
135 #include <string.h>
136 #include <opencdk.h>
137 ],      [ return !!cdk_check_version(NULL); ],
138         [ echo "*** The test program compiled, but did not run. This usually means"
139           echo "*** that the run-time linker is not finding LIBOPENCDK or finding the wrong"
140           echo "*** version of LIBOPENCDK. If it is not finding LIBOPENCDK, you'll need to set your"
141           echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
142           echo "*** to the installed location  Also, make sure you have run ldconfig if that"
143           echo "*** is required on your system"
144           echo "***"
145           echo "*** If you have an old version installed, it is best to remove it, although"
146           echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"
147           echo "***" ],
148         [ echo "*** The test program failed to compile or link. See the file config.log for the"
149           echo "*** exact error that occured. This usually means LIBOPENCDK was incorrectly installed"
150           echo "*** or that you have moved LIBOPENCDK since it was installed. In the latter case, you"
151           echo "*** may want to edit the opencdk-config script: $LIBOPENCDK_CONFIG" ])
152           CFLAGS="$ac_save_CFLAGS"
153           LIBS="$ac_save_LIBS"
154        fi
155      fi
156      LIBOPENCDK_CFLAGS=""
157      LIBOPENCDK_LIBS=""
158      ifelse([$3], , :, [$3])
159   fi
160   AC_SUBST(LIBOPENCDK_CFLAGS)
161   AC_SUBST(LIBOPENCDK_LIBS)
162   rm -f conf.libopencdktest
165 dnl *-*wedit:notab*-*  Please keep this as the last line.