Autoconf: Use AC_CACHE_CHECK
[openafs.git] / src / cf / test_package.m4
1 AC_DEFUN([OPENAFS_TEST_PACKAGE],[
2 AC_ARG_WITH($1,
3 [  --with-$1=dir                use $1 in dir])
4 AC_ARG_WITH($1-lib,
5 [  --with-$1-lib=dir            use $1 libraries in dir],
6 [if test "$withval" = "yes" -o "$withval" = "no"; then
7   AC_MSG_ERROR([No argument for --with-$1-lib])
8 elif test "X$with_$1" = "X"; then
9   with_$1=yes
10 fi])
11 AC_ARG_WITH($1-include,
12 [  --with-$1-include=dir        use $1 headers in dir],
13 [if test "$withval" = "yes" -o "$withval" = "no"; then
14   AC_MSG_ERROR([No argument for --with-$1-include])
15 elif test "X$with_$1" = "X"; then
16   with_$1=yes
17 fi])
18
19 AC_MSG_CHECKING(for $1)
20
21 case "$with_$1" in
22 yes) ;;
23 no)  ;;
24 "")  ;;
25 *)   if test "$with_$1_include" = ""; then
26         with_$1_include="$with_$1/include"
27         fi
28         if test "$with_$1_lib" = ""; then
29            with_$1_lib="$with_$1/lib$abilibdirext"
30            fi
31            ;;
32 esac
33 header_dirs=
34 lib_dirs=
35 d='$5'
36 for i in $d; do
37     header_dirs="$header_dirs $i/include"
38     lib_dirs="$lib_dirs $i/lib$abilibdirext"
39 done
40
41 case "$with_$1_include" in
42 yes) ;;
43 no)  ;;
44 *)   header_dirs="$with_$1_include $header_dirs";;
45 esac
46 case "$with_$1_lib" in
47 yes) ;;
48 no)  ;;
49 *)   lib_dirs="$with_$1_lib $lib_dirs";;
50 esac
51
52 save_CFLAGS="$CFLAGS"
53 save_LIBS="$LIBS"
54 ires= lres=
55 for i in $header_dirs; do
56     CFLAGS="-I$i $save_CFLAGS"
57     AC_TRY_COMPILE([$2],,ires=$i;break)
58 done
59 for i in $lib_dirs; do
60     LIBS="-L$i $3 $4 $save_LIBS"
61     AC_TRY_LINK([$2],,lres=$i;break)
62 done
63 CFLAGS="$save_CFLAGS"
64 LIBS="$save_LIBS"
65
66 if test "$ires" -a "$lres" -a "$with_$1" != "no"; then
67    $1_includedir="$ires"
68    $1_libdir="$lres"
69    INCLUDE_$1="-I$$1_includedir"
70    LIB_$1="-L$$1_libdir $3"
71    AC_DEFINE_UNQUOTED(m4_toupper($1),1,[Define if you have the $1 package.])
72    AC_DEFINE_UNQUOTED(m4_toupper(HAVE_$1),1,[Define if you have the $1 package.])
73    with_$1=yes
74    AC_MSG_RESULT([headers $ires, libraries $lres])
75 else
76         INCLUDE_$1=
77         LIB_$1=
78         with_$1=no
79         AC_MSG_RESULT($with_$1)
80 fi
81 AC_SUBST(INCLUDE_$1)
82 AC_SUBST(LIB_$1)
83 ])