dnl
dnl

AC_PREREQ(2.50)

AC_INIT(org.eclipse.ptp.debug.sdm, [6.0.3.201211112147])
AC_CONFIG_SRCDIR(src/master/startup.c)

AM_INIT_AUTOMAKE([subdir-objects])

AM_CONFIG_HEADER(config.h)
AC_CANONICAL_BUILD

dnl
dnl Eclipse adds version number to end of package when deploying via update site
dnl

VERSION="_$PACKAGE_VERSION"
if test `expr "$VERSION" : "_@@<:@^@@:>@*@"` -gt 0 ; then
	VERSION=
fi
UTILS="`echo ../org.eclipse.ptp.utils${VERSION}`"
if test ! -d $UTILS; then
	UTILS="`echo ../../core/org.eclipse.ptp.utils${VERSION}`"
	if test ! -d $UTILS; then
		AC_MSG_ERROR([utils directory not found])
	fi
fi
PROXY="`echo ../org.eclipse.ptp.proxy${VERSION}`"
if test ! -d $PROXY; then
	PROXY="`echo ../../core/org.eclipse.ptp.proxy${VERSION}`"
	if test ! -d $PROXY; then
		AC_MSG_ERROR([proxy directory not found])
	fi
fi

dnl
dnl Check for programs.
dnl

AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_RANLIB

os=`uname -s`
if test "x$os" = "xAIX" ; then
        CFLAGS="$CFLAGS -qinfo=gen -qcpluscmt"
else
        CFLAGS="$CFLAGS -Wall"
fi

CFLAGS="$CFLAGS -I$UTILS/include -I$PROXY/include"
LIBS="$LIBS -L$UTILS -L$PROXY"

dnl
dnl Check for libraries.
dnl

AC_CHECK_LIB(nsl, gethostbyname)
AC_CHECK_LIB(socket, socket)
AC_SEARCH_LIBS(openpty, [util],
	[AC_DEFINE(HAVE_OPENPTY, 1, [System has openpty() function.])])dnl

AC_CHECK_LIB(utils, bitset_new)
AC_CHECK_LIB(proxysvr, proxy_svr_init, [SVR_LIBS="$SVR_LIBS -lproxysvr"])
AC_SUBST([SVR_LIBS])
AC_CHECK_LIB(proxyclnt, proxy_clnt_init, [CLNT_LIBS="$CLNT_LIBS -lproxyclnt"])
AC_SUBST([CLNT_LIBS])

dnl Check for posix4
AC_CHECK_LIB(posix4, clock_gettime)
if test "$ac_cv_lib_posix4_clock_gettime" = yes; then
	AC_DEFINE(POSIX, 1, [Enable POSIX support in Guard.])
	LIBS="$LIBS -lposix4"
fi

dnl
dnl Check for header files.
dnl

AC_HEADER_STDC
AC_CHECK_HEADERS(strings.h sys/time.h unistd.h)
AC_CHECK_HEADERS(jni.h)

dnl
dnl Check for typedefs, structures, and compiler characteristics.
dnl

AC_HEADER_TIME
AC_STRUCT_TM

dnl
dnl Check for library functions.
dnl

AC_FUNC_MEMCMP
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(gethostname select strdup strstr strtoul sigset sighold sigrelse)

dnl
dnl Enable X10 backend
dnl
AC_ARG_ENABLE([x10], 
	[AS_HELP_STRING([--disable-x10],
		[Disable x10 support (default is no)])], 
	[case "${enableval}" in
       yes) X10_BACKEND=1 ;;
       no)  X10_BACKEND=0 ;;
       *) AC_MSG_ERROR([bad value ${enableval} for --enable-x10]) ;;
	esac], 
	[X10_BACKEND=1])
AC_DEFINE_UNQUOTED([X10_BACKEND], [$X10_BACKEND], [Enable X10 support])
AM_CONDITIONAL([X10_BACKEND], [test "$X10_BACKEND" = 1])

AH_VERBATIM([DEBUG],
[#define DEBUG
#ifdef DEBUG
extern int debug_level;
extern void debug_printf(int, char *, ...);
extern void debug_printargs(int, char *, int, char **);
#define DEBUG_LEVEL_NONE		0x00
#define DEBUG_LEVEL_ALL			0xff
#define DEBUG_LEVEL_STARTUP		0x01
#define DEBUG_LEVEL_MESSAGES	0x02
#define DEBUG_LEVEL_ROUTING		0x04
#define DEBUG_LEVEL_MASTER		0x08
#define DEBUG_LEVEL_SERVER		0x10
#define DEBUG_LEVEL_BACKEND		0x20
#define DEBUG_LEVEL_PROTOCOL	0x40
#define TEST_DEBUG_LEVEL(level)			((debug_level&(level))==(level))
#define DEBUG_PRINTF(level,format,...)	debug_printf((level),(format),__VA_ARGS__)
#define DEBUG_PRINTS(level,str)			debug_printf((level),"%s",(str))
#define DEBUG_PRINTA(level,str,n,args)	debug_printargs((level),(str),(n),(args))
#else /* DEBUG */
#define DEBUG_PRINTF(level,format,...)
#define DEBUG_PRINTS(level,str)
#define DEBUG_PRINTA(level,str,n,args)
#endif /* DEBUG */])

AC_CONFIG_FILES([Makefile])
AC_CONFIG_SUBDIRS([libaif libmi])
AC_OUTPUT
