dnl
dnl

AC_PREREQ([2.50])

AC_INIT([org.eclipse.ptp.slurm], [5.0.6.201203091926])
AC_CONFIG_SRCDIR([src/ptp_slurm_proxy.c])

AM_INIT_AUTOMAKE([-Wall -Werror foreign])

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 SLURM

dnl
dnl Check for SLURM installation
dnl

AC_PATH_PROG(SRUN, [srun], no)
if test "$ac_cv_path_SRUN" != no; then
	AC_DEFINE([HAVE_SRUN],[1],[Enable SLURM rms support.])
else
	AC_MSG_NOTICE([SLURM not installed, skipping...])
	AS_EXIT([1])
fi

AC_ARG_WITH([slurm], AS_HELP_STRING([--with-slurm],
	[Specify the top dir of installed SLURM rms.@<:@REQUIRED@:>@]),[],[with_slurm=no])

SLURMDIR=
AS_IF([test "x$with_slurm" != xno],[AC_SUBST([SLURMDIR],[$with_slurm])],
       AC_MSG_ERROR([The top installation directory of SLURM rms must be specified via "--with-slurm=DIR".]))


dnl
dnl Check for programs.
dnl

AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_RANLIB

CFLAGS="$CFLAGS -Wall -I$UTILS/include -I$PROXY/include -I$SLURMDIR/include -g -O0"
LIBS="$LIBS -L$UTILS -L$PROXY -L$SLURMDIR/lib"
CPPFLAGS="$CPPFLAGS -I$SLURMDIR/include"

dnl
dnl Check for libraries.
dnl

AC_CHECK_LIB([utils], [bitset_new])
AC_CHECK_LIB([proxysvr], [proxy_svr_init])
AC_CHECK_LIB([slurm],[slurm_ping],[],
			[AC_MSG_NOTICE([SLURM not installed, skipping...])
	 		 AS_EXIT
			])

dnl
dnl Check for header files.
dnl

AC_HEADER_STDC
AC_CHECK_HEADERS([slurm/slurm.h slurm/slurm_errno.h], [], 
	[AC_MSG_NOTICE([SLURM not installed, skipping...])
	 AS_EXIT
	])

dnl
dnl Check SLURM versions
dnl SLURM_VERSION_NUMBER is not defined before 2.1
dnl

SLURM_VERSION=""
AC_CHECK_DECL([SLURM_VERSION_NUMBER],[SLURM_VERSION="2.2"],[],[#include "slurm/slurm.h"])
if test x"$SLURM_VERSION" = x"2.2"; then
	AC_DEFINE([SLURM_VERSION_2_2], [1], 
				[Define to 1 if SLURM version is 2.2 or later])
fi				

dnl
dnl Check for types
dnl
AC_TYPE_SIGNAL

AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
