test-package.m4 revision 102644
1dnl $Id: test-package.m4,v 1.11 2002/08/28 19:30:48 joda Exp $ 2dnl 3dnl rk_TEST_PACKAGE(package,headers,libraries,extra libs, 4dnl default locations, conditional, config-program) 5 6AC_DEFUN(rk_TEST_PACKAGE,[ 7AC_ARG_WITH($1, 8 AC_HELP_STRING([--with-$1=dir],[use $1 in dir])) 9AC_ARG_WITH($1-lib, 10 AC_HELP_STRING([--with-$1-lib=dir],[use $1 libraries in dir]), 11[if test "$withval" = "yes" -o "$withval" = "no"; then 12 AC_MSG_ERROR([No argument for --with-$1-lib]) 13elif test "X$with_$1" = "X"; then 14 with_$1=yes 15fi]) 16AC_ARG_WITH($1-include, 17 AC_HELP_STRING([--with-$1-include=dir],[use $1 headers in dir]), 18[if test "$withval" = "yes" -o "$withval" = "no"; then 19 AC_MSG_ERROR([No argument for --with-$1-include]) 20elif test "X$with_$1" = "X"; then 21 with_$1=yes 22fi]) 23AC_ARG_WITH($1-config, 24 AC_HELP_STRING([--with-$1-config=path],[config program for $1])) 25 26m4_ifval([$6], 27 m4_define([rk_pkgname], $6), 28 m4_define([rk_pkgname], AS_TR_CPP($1))) 29 30AC_MSG_CHECKING(for $1) 31 32case "$with_$1" in 33yes|"") d='$5' ;; 34no) d= ;; 35*) d="$with_$1" ;; 36esac 37 38header_dirs= 39lib_dirs= 40for i in $d; do 41 if test "$with_$1_include" = ""; then 42 if test -d "$i/include/$1"; then 43 header_dirs="$header_dirs $i/include/$1" 44 fi 45 if test -d "$i/include"; then 46 header_dirs="$header_dirs $i/include" 47 fi 48 fi 49 if test "$with_$1_lib" = ""; then 50 if test -d "$i/lib$abilibdirext"; then 51 lib_dirs="$lib_dirs $i/lib$abilibdirext" 52 fi 53 fi 54done 55 56if test "$with_$1_include"; then 57 header_dirs="$with_$1_include $header_dirs" 58fi 59if test "$with_$1_lib"; then 60 lib_dirs="$with_$1_lib $lib_dirs" 61fi 62 63if test "$with_$1_config" = ""; then 64 with_$1_config='$7' 65fi 66 67$1_cflags= 68$1_libs= 69 70case "$with_$1_config" in 71yes|no|"") 72 ;; 73*) 74 $1_cflags="`$with_$1_config --cflags 2>&1`" 75 $1_libs="`$with_$1_config --libs 2>&1`" 76 ;; 77esac 78 79found=no 80if test "$with_$1" != no; then 81 save_CFLAGS="$CFLAGS" 82 save_LIBS="$LIBS" 83 if test "$[]$1_cflags" -a "$[]$1_libs"; then 84 CFLAGS="$[]$1_cflags $save_CFLAGS" 85 LIBS="$[]$1_libs $save_LIBS" 86 AC_TRY_LINK([$2],,[ 87 INCLUDE_$1="$[]$1_cflags" 88 LIB_$1="$[]$1_libs" 89 AC_MSG_RESULT([from $with_$1_config]) 90 found=yes]) 91 fi 92 if test "$found" = no; then 93 ires= lres= 94 for i in $header_dirs; do 95 CFLAGS="-I$i $save_CFLAGS" 96 AC_TRY_COMPILE([$2],,ires=$i;break) 97 done 98 for i in $lib_dirs; do 99 LIBS="-L$i $3 $4 $save_LIBS" 100 AC_TRY_LINK([$2],,lres=$i;break) 101 done 102 if test "$ires" -a "$lres" -a "$with_$1" != "no"; then 103 INCLUDE_$1="-I$ires" 104 LIB_$1="-L$lres $3" 105 found=yes 106 AC_MSG_RESULT([headers $ires, libraries $lres]) 107 fi 108 fi 109 CFLAGS="$save_CFLAGS" 110 LIBS="$save_LIBS" 111fi 112 113if test "$found" = yes; then 114 AC_DEFINE_UNQUOTED(rk_pkgname, 1, [Define if you have the $1 package.]) 115 with_$1=yes 116else 117 with_$1=no 118 INCLUDE_$1= 119 LIB_$1= 120 AC_MSG_RESULT(no) 121fi 122 123AC_SUBST(INCLUDE_$1) 124AC_SUBST(LIB_$1) 125]) 126