dnl CF_FIND_TDLIB version: 10 updated: 2012/09/04 04:17:32
dnl -------------
dnl Locate TD_LIB, which is available in one of these configurations:
dnl a) installed, with headers, library and include-file for make
dnl b) in a directory side-by-side with the current program's configure script
dnl c) in a subdirectory of this directory.
dnl
dnl Use (b) or (c) in preference
dnl to the installed version, to facilitate development.
dnl (b) is mainly useful for packaging.
dnl
dnl Sets:
dnl	TD_LIB_rules - actual path of td_lib.mk
dnl
AC_DEFUN([CF_FIND_TDLIB],
[
AC_MSG_CHECKING(for td_lib in side-by-side directory)
AC_CACHE_VAL(cf_cv_tdlib_devel,[
	cf_cv_tdlib_devel=no

	for cf_path in . ..
	do
		test -d $cf_path/td_lib &&
		test -d $cf_path/td_lib/include &&
		test -f $cf_path/td_lib/include/td_config.h &&
		test -d $cf_path/td_lib/lib &&
		test -f $cf_path/td_lib/lib/${LIB_PREFIX}td.a &&
		cf_cv_tdlib_devel=`CDPATH=; export CDPATH; cd $cf_path/td_lib;pwd` &&
		break
	done
])
AC_MSG_RESULT($cf_cv_tdlib_devel)

if test "$cf_cv_tdlib_devel" = no ; then
    CF_HEADER_PATH(cf_search,td)
    # get all matches, since we're including <ptypes.h> and <td/ptypes.h>
    for cf_incdir in $cf_search
    do
	test -f $cf_incdir/td/td_config.h && CFLAGS="$CFLAGS -I$cf_incdir"
    done
    CF_FIND_LIBRARY(td,td,[
#define TESTING_CONFIG_H
#include <td/ptypes.h>],[
        char *p = doalloc(0,1)],
        doalloc)
	if test -z "$cf_libdir" ; then
		CF_SUBDIR_PATH(cf_search,td,share)
		cf_libdir=/usr/local/lib
		cf_td_lib_rules=no
		for cf_libdir in $cf_search
		do
			if test -f $cf_libdir/td_lib.mk ; then
				cf_td_lib_rules=yes
				break
			fi
		done
	else
		cf_libdir=`echo "$cf_libdir" | sed -e 's,/lib[[^/]]*$,share,'`
		if test -f $cf_libdir/td_lib.mk ; then
			cf_td_lib_rules=yes
		fi
	fi
	test $cf_td_lib_rules = no && AC_MSG_ERROR(Cannot find td_lib.mk)
	TD_LIB_rules=$cf_libdir
else
	CPPFLAGS="$CPPFLAGS -I$cf_cv_tdlib_devel/include $CPPFLAGS"
	LIBS="-L$cf_cv_tdlib_devel/lib $LIBS"
	TD_LIB_rules=$cf_cv_tdlib_devel/support
fi

AC_SUBST(TD_LIB_rules)
])dnl
