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