No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / dist / heimdal / cf / test-package.m4
blob30d5eee518ef94f608fc71c04cb883db9e796c6e
1 dnl $Heimdal: test-package.m4 14166 2004-08-26 12:35:42Z joda $
2 dnl $NetBSD$
3 dnl
4 dnl rk_TEST_PACKAGE(package,headers,libraries,extra libs,
5 dnl                     default locations, conditional, config-program)
7 AC_DEFUN([rk_TEST_PACKAGE],[
8 AC_ARG_WITH($1,
9         AS_HELP_STRING([--with-$1=dir],[use $1 in dir]))
10 AC_ARG_WITH($1-lib,
11         AS_HELP_STRING([--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         AS_HELP_STRING([--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 AC_ARG_WITH($1-config,
25         AS_HELP_STRING([--with-$1-config=path],[config program for $1]))
27 m4_ifval([$6],
28         m4_define([rk_pkgname], $6),
29         m4_define([rk_pkgname], AS_TR_CPP($1)))
31 AC_MSG_CHECKING(for $1)
33 case "$with_$1" in
34 yes|"") d='$5' ;;
35 no)     d= ;;
36 *)      d="$with_$1" ;;
37 esac
39 header_dirs=
40 lib_dirs=
41 for i in $d; do
42         if test "$with_$1_include" = ""; then
43                 if test -d "$i/include/$1"; then
44                         header_dirs="$header_dirs $i/include/$1"
45                 fi
46                 if test -d "$i/include"; then
47                         header_dirs="$header_dirs $i/include"
48                 fi
49         fi
50         if test "$with_$1_lib" = ""; then
51                 if test -d "$i/lib$abilibdirext"; then
52                         lib_dirs="$lib_dirs $i/lib$abilibdirext"
53                 fi
54         fi
55 done
57 if test "$with_$1_include"; then
58         header_dirs="$with_$1_include $header_dirs"
60 if test "$with_$1_lib"; then
61         lib_dirs="$with_$1_lib $lib_dirs"
64 if test "$with_$1_config" = ""; then
65         with_$1_config='$7'
68 $1_cflags=
69 $1_libs=
71 case "$with_$1_config" in
72 yes|no|""|"$7")
73         if test -f $with_$1/bin/$7 ; then
74                 with_$1_config=$with_$1/bin/$7
75         fi
76         ;;
77 esac
79 case "$with_$1_config" in
80 yes|no|"")
81         ;;
83         $1_cflags="`$with_$1_config --cflags 2>&1`"
84         $1_libs="`$with_$1_config --libs 2>&1`"
85         ;;
86 esac
88 found=no
89 if test "$with_$1" != no; then
90         save_CFLAGS="$CFLAGS"
91         save_LIBS="$LIBS"
92         if test "$[]$1_cflags" -a "$[]$1_libs"; then
93                 CFLAGS="$[]$1_cflags $save_CFLAGS"
94                 LIBS="$[]$1_libs $save_LIBS"
95                 AC_LINK_IFELSE([AC_LANG_PROGRAM([[$2]],[[]])],[
96                         INCLUDE_$1="$[]$1_cflags"
97                         LIB_$1="$[]$1_libs"
98                         AC_MSG_RESULT([from $with_$1_config])
99                         found=yes])
100         fi
101         if test "$found" = no; then
102                 ires= lres=
103                 for i in $header_dirs; do
104                         CFLAGS="-I$i $save_CFLAGS"
105                         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[$2]],[[]])],[ires=$i;break])
106                 done
107                 for i in $lib_dirs; do
108                         LIBS="-L$i $3 $4 $save_LIBS"
109                         AC_LINK_IFELSE([AC_LANG_PROGRAM([[$2]],[[]])],[lres=$i;break])
110                 done
111                 if test "$ires" -a "$lres" -a "$with_$1" != "no"; then
112                         INCLUDE_$1="-I$ires"
113                         LIB_$1="-L$lres $3 $4"
114                         found=yes
115                         AC_MSG_RESULT([headers $ires, libraries $lres])
116                 fi
117         fi
118         CFLAGS="$save_CFLAGS"
119         LIBS="$save_LIBS"
122 if test "$found" = yes; then
123         AC_DEFINE_UNQUOTED(rk_pkgname, 1, [Define if you have the $1 package.])
124         with_$1=yes
125 else
126         with_$1=no
127         INCLUDE_$1=
128         LIB_$1=
129         AC_MSG_RESULT(no)
132 AC_SUBST(INCLUDE_$1)
133 AC_SUBST(LIB_$1)