1dnl _AM_TRY_CHECK(MINIMUM-VERSION, EXTRA-CFLAGS, EXTRA-LIBS, CHECK-LIB-NAME
2dnl               [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
3dnl Test for check, and define CHECK_CFLAGS and CHECK_LIBS
4dnl Done this way because of the brokenness that is
5dnl https://launchpad.net/distros/ubuntu/+source/check/+bug/5840
6dnl
7
8AC_DEFUN([_AM_TRY_CHECK],
9[
10  min_check_version=$1
11  extra_cflags=$2
12  extra_libs=$3
13  check_lib_name=$4
14
15  CHECK_CFLAGS="$extra_cflags"
16  CHECK_LIBS="$extra_libs -l$check_lib_name"
17
18  ac_save_CFLAGS="$CFLAGS"
19  ac_save_LIBS="$LIBS"
20
21  CFLAGS="$CFLAGS $CHECK_CFLAGS"
22  LIBS="$CHECK_LIBS $LIBS"
23
24  AC_MSG_CHECKING(for check named $check_lib_name  - version >= $min_check_version)
25
26  rm -f conf.check-test
27  dnl unset no_check, since in our second run it would have been set to yes
28  dnl before
29  no_check=
30  AC_TRY_RUN([
31#include <stdio.h>
32#include <stdlib.h>
33
34#include <check.h>
35
36int main ()
37{
38  int major, minor, micro;
39  char *tmp_version;
40
41  system ("touch conf.check-test");
42
43  /* HP/UX 9 (%@#!) writes to sscanf strings */
44  tmp_version = strdup("$min_check_version");
45  if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
46     printf("%s, bad version string\n", "$min_check_version");
47     return 1;
48   }
49
50  if ((CHECK_MAJOR_VERSION != check_major_version) ||
51      (CHECK_MINOR_VERSION != check_minor_version) ||
52      (CHECK_MICRO_VERSION != check_micro_version))
53    {
54      printf("\n*** The check header file (version %d.%d.%d) does not match\n",
55	     CHECK_MAJOR_VERSION, CHECK_MINOR_VERSION, CHECK_MICRO_VERSION);
56      printf("*** the check library (version %d.%d.%d).\n",
57	     check_major_version, check_minor_version, check_micro_version);
58      return 1;
59    }
60
61  if ((check_major_version > major) ||
62      ((check_major_version == major) && (check_minor_version > minor)) ||
63      ((check_major_version == major) && (check_minor_version == minor) && (check_micro_version >= micro)))
64    {
65      return 0;
66    }
67  else
68    {
69      printf("\n*** An old version of check (%d.%d.%d) was found.\n",
70             check_major_version, check_minor_version, check_micro_version);
71      printf("*** You need a version of check being at least %d.%d.%d.\n", major, minor, micro);
72      printf("***\n");
73      printf("*** If you have already installed a sufficiently new version, this error\n");
74      printf("*** probably means that the wrong copy of the check library and header\n");
75      printf("*** file is being found. Rerun configure with the --with-check=PATH option\n");
76      printf("*** to specify the prefix where the correct version was installed.\n");
77    }
78
79  return 1;
80}
81],, no_check=yes, [echo $ac_n "cross compiling; assumed OK... $ac_c"])
82
83  CFLAGS="$ac_save_CFLAGS"
84  LIBS="$ac_save_LIBS"
85
86  if test "x$no_check" = x ; then
87    AC_MSG_RESULT(yes)
88    ifelse([$5], , :, [$5])
89  else
90    AC_MSG_RESULT(no)
91    if test -f conf.check-test ; then
92      :
93    else
94      echo "*** Could not run check test program, checking why..."
95      CFLAGS="$CFLAGS $CHECK_CFLAGS"
96      LIBS="$CHECK_LIBS $LIBS"
97      AC_TRY_LINK([
98#include <stdio.h>
99#include <stdlib.h>
100
101#include <check.h>
102], ,  [ echo "*** The test program compiled, but did not run. This usually means"
103        echo "*** that the run-time linker is not finding check. You'll need to set your"
104        echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
105        echo "*** to the installed location  Also, make sure you have run ldconfig if that"
106        echo "*** is required on your system"
107	echo "***"
108        echo "*** If you have an old version installed, it is best to remove it, although"
109        echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
110      [ echo "*** The test program failed to compile or link. See the file config.log for"
111        echo "*** the exact error that occured." ])
112
113      CFLAGS="$ac_save_CFLAGS"
114      LIBS="$ac_save_LIBS"
115    fi
116
117    CHECK_CFLAGS=""
118    CHECK_LIBS=""
119
120    rm -f conf.check-test
121    ifelse([$6], , AC_MSG_ERROR([check not found]), [$6])
122  fi
123])
124
125
126dnl AM_PATH_CHECK([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
127dnl Test for check, and define CHECK_CFLAGS and CHECK_LIBS
128dnl
129
130AC_DEFUN([AM_PATH_CHECK],
131[
132  AC_ARG_WITH(check,
133  [  --with-check=PATH       prefix where check is installed [default=auto]])
134
135  AC_ARG_WITH(checklibname,
136    AC_HELP_STRING([--with-check-lib-name=NAME],
137      [name of the PIC check library (default=check)]))
138
139  min_check_version=ifelse([$1], ,0.8.2,$1)
140
141  if test x$with_check = xno; then
142    AC_MSG_RESULT(disabled)
143    ifelse([$3], , AC_MSG_ERROR([disabling check is not supported]), [$3])
144  else
145    if test "x$with_check" != x; then
146      CHECK_EXTRA_CFLAGS="-I$with_check/include"
147      CHECK_EXTRA_LIBS="-L$with_check/lib"
148    else
149      CHECK_EXTRA_CFLAGS=""
150      CHECK_EXTRA_LIBS=""
151    fi
152
153    if test x$with_checklibname = x; then
154      _AM_TRY_CHECK($min_check_version, $CHECK_EXTRA_CFLAGS, $CHECK_EXTRA_LIBS,
155        check_pic, [have_check=true], [have_check=false])
156      if test x$have_check = xtrue; then
157        ifelse([$2], , :, [$2])
158      else
159        _AM_TRY_CHECK($min_check_version, $CHECK_EXTRA_CFLAGS, $CHECK_EXTRA_LIBS,
160          check, [have_check=true], [have_check=false])
161        if test x$have_check = xtrue; then
162          ifelse([$2], , :, [$2])
163        else
164          ifelse([$3], , AC_MSG_ERROR([check not found]), [$3])
165        fi
166      fi
167    else
168      _AM_TRY_CHECK($min_check_version, $CHECK_EXTRA_CFLAGS, $CHECK_EXTRA_LIBS,
169        $with_checklibname, [have_check=true], [have_check=false])
170      if test x$have_check = xtrue; then
171        ifelse([$2], , :, [$2])
172      else
173        ifelse([$3], , AC_MSG_ERROR([check not found]), [$3])
174      fi
175    fi
176
177    AC_SUBST(CHECK_CFLAGS)
178    AC_SUBST(CHECK_LIBS)
179    rm -f conf.check-test
180  fi
181])
182