1fcfd9267Selricdnl Id
2f59d82ffSelricdnl
3*e0895134Schristosdnl rk_TEST_PACKAGE(package,program,libraries,extra libs,
4f59d82ffSelricdnl			default locations, conditional, config-program, headers)
5f59d82ffSelric
6f59d82ffSelricAC_DEFUN([rk_TEST_PACKAGE],[
7f59d82ffSelricAC_ARG_WITH($1,
8f59d82ffSelric	AS_HELP_STRING([--with-$1=dir],[use $1 in dir]))
9f59d82ffSelricAC_ARG_WITH($1-lib,
10f59d82ffSelric	AS_HELP_STRING([--with-$1-lib=dir],[use $1 libraries in dir]),
11f59d82ffSelric[if test "$withval" = "yes" -o "$withval" = "no"; then
12f59d82ffSelric  AC_MSG_ERROR([No argument for --with-$1-lib])
13f59d82ffSelricelif test "X$with_$1" = "X"; then
14f59d82ffSelric  with_$1=yes
15f59d82ffSelricfi])
16f59d82ffSelricAC_ARG_WITH($1-include,
17f59d82ffSelric	AS_HELP_STRING([--with-$1-include=dir],[use $1 headers in dir]),
18f59d82ffSelric[if test "$withval" = "yes" -o "$withval" = "no"; then
19f59d82ffSelric  AC_MSG_ERROR([No argument for --with-$1-include])
20f59d82ffSelricelif test "X$with_$1" = "X"; then
21f59d82ffSelric  with_$1=yes
22f59d82ffSelricfi])
23f59d82ffSelricAC_ARG_WITH($1-config,
24f59d82ffSelric	AS_HELP_STRING([--with-$1-config=path],[config program for $1]))
25f59d82ffSelric
26f59d82ffSelricm4_ifval([$6],
27f59d82ffSelric	m4_define([rk_pkgname], $6),
28f59d82ffSelric	m4_define([rk_pkgname], AS_TR_CPP($1)))
29f59d82ffSelric
30f59d82ffSelricAC_MSG_CHECKING(for $1)
31f59d82ffSelric
32f59d82ffSelriccase "$with_$1" in
33f59d82ffSelricyes|"") d='$5' ;;
34f59d82ffSelricno)	d= ;;
35f59d82ffSelric*)	d="$with_$1" ;;
36f59d82ffSelricesac
37f59d82ffSelric
38f59d82ffSelricheader_dirs=
39f59d82ffSelriclib_dirs=
40f59d82ffSelricfor i in $d; do
41f59d82ffSelric	if test "$with_$1_include" = ""; then
42f59d82ffSelric		if test -d "$i/include/$1"; then
43f59d82ffSelric			header_dirs="$header_dirs $i/include/$1"
44f59d82ffSelric		fi
45f59d82ffSelric		if test -d "$i/include"; then
46f59d82ffSelric			header_dirs="$header_dirs $i/include"
47f59d82ffSelric		fi
48f59d82ffSelric	fi
49f59d82ffSelric	if test "$with_$1_lib" = ""; then
50f59d82ffSelric		if test -d "$i/lib$abilibdirext"; then
51f59d82ffSelric			lib_dirs="$lib_dirs $i/lib$abilibdirext"
52f59d82ffSelric		fi
53f59d82ffSelric	fi
54f59d82ffSelricdone
55f59d82ffSelric
56f59d82ffSelricif test "$with_$1_include"; then
57f59d82ffSelric	header_dirs="$with_$1_include $header_dirs"
58f59d82ffSelricfi
59f59d82ffSelricif test "$with_$1_lib"; then
60f59d82ffSelric	lib_dirs="$with_$1_lib $lib_dirs"
61f59d82ffSelricfi
62f59d82ffSelric
63f59d82ffSelricif test "$with_$1_config" = ""; then
64f59d82ffSelric	with_$1_config='$7'
65f59d82ffSelricfi
66f59d82ffSelric
67f59d82ffSelric$1_cflags=
68f59d82ffSelric$1_libs=
69f59d82ffSelric
70f59d82ffSelriccase "$with_$1_config" in
71f59d82ffSelricyes|no|""|"$7")
72f59d82ffSelric	if test -f $with_$1/bin/$7 ; then
73f59d82ffSelric		with_$1_config=$with_$1/bin/$7
74f59d82ffSelric	fi
75f59d82ffSelric	;;
76f59d82ffSelricesac
77f59d82ffSelric
78f59d82ffSelriccase "$with_$1_config" in
79f59d82ffSelricyes|no|"")
80f59d82ffSelric	;;
81f59d82ffSelric*)
82f59d82ffSelric	$1_cflags="`$with_$1_config --cflags 2>&1`"
83f59d82ffSelric	$1_libs="`$with_$1_config --libs 2>&1`"
84f59d82ffSelric	;;
85f59d82ffSelricesac
86f59d82ffSelric
87f59d82ffSelricfound=no
88f59d82ffSelricif test "$with_$1" != no; then
89f59d82ffSelric	save_CFLAGS="$CFLAGS"
90f59d82ffSelric	save_LIBS="$LIBS"
91f59d82ffSelric	if test "$[]$1_cflags" -a "$[]$1_libs"; then
92f59d82ffSelric		CFLAGS="$[]$1_cflags $save_CFLAGS"
93f59d82ffSelric		LIBS="$[]$1_libs $save_LIBS"
94f59d82ffSelric		m4_ifval([$8],[AC_CHECK_HEADERS([[$8]])])
95f59d82ffSelric		AC_LINK_IFELSE([AC_LANG_PROGRAM([[$2]],[[]])],[
96f59d82ffSelric			INCLUDE_$1="$[]$1_cflags"
97f59d82ffSelric			LIB_$1="$[]$1_libs"
98f59d82ffSelric			AC_MSG_RESULT([from $with_$1_config])
99f59d82ffSelric			found=yes])
100f59d82ffSelric	fi
101f59d82ffSelric	if test "$found" = no; then
102f59d82ffSelric		ires= lres=
103f59d82ffSelric		for i in $header_dirs; do
104f59d82ffSelric			CFLAGS="-I$i $save_CFLAGS"
105f59d82ffSelric			m4_ifval([$8],[AC_CHECK_HEADERS([[$8]])])
106f59d82ffSelric			AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[$2]],[[]])],[ires=$i;break])
107f59d82ffSelric		done
108f59d82ffSelric		for i in $lib_dirs; do
109f59d82ffSelric			LIBS="-L$i $3 $4 $save_LIBS"
110f59d82ffSelric			AC_LINK_IFELSE([AC_LANG_PROGRAM([[$2]],[[]])],[lres=$i;break])
111f59d82ffSelric		done
112f59d82ffSelric		if test "$ires" -a "$lres" -a "$with_$1" != "no"; then
113f59d82ffSelric			INCLUDE_$1="-I$ires"
114f59d82ffSelric			LIB_$1="-L$lres $3 $4"
115f59d82ffSelric			found=yes
116f59d82ffSelric			AC_MSG_RESULT([headers $ires, libraries $lres])
117f59d82ffSelric		fi
118f59d82ffSelric	fi
119f59d82ffSelric	CFLAGS="$save_CFLAGS"
120f59d82ffSelric	LIBS="$save_LIBS"
121f59d82ffSelricfi
122f59d82ffSelric
123f59d82ffSelricif test "$found" = yes; then
124f59d82ffSelric	AC_DEFINE_UNQUOTED(rk_pkgname, 1, [Define if you have the $1 package.])
125f59d82ffSelric	with_$1=yes
126f59d82ffSelricelse
127f59d82ffSelric	with_$1=no
128f59d82ffSelric	INCLUDE_$1=
129f59d82ffSelric	LIB_$1=
130f59d82ffSelric	AC_MSG_RESULT(no)
131f59d82ffSelricfi
132f59d82ffSelric
133f59d82ffSelricAC_SUBST(INCLUDE_$1)
134f59d82ffSelricAC_SUBST(LIB_$1)
135f59d82ffSelric])
136