dnl
dnl Custom autoconf macros for vserver.
dnl
dnl $Id: aclocal.m4,v 1.12 2006/08/23 16:31:17 mickey Exp $
dnl ==========================================================================


dnl
dnl AC_VCHAT_DEPEND_CHECK
dnl

AC_DEFUN(AC_VCHAT_DEPEND_CHECK,
[
	AC_MSG_CHECKING(how to retrieve source dependencies)

	# Try the dependency generator tools in order of preference.

	DEPOUT="> .depend"

	if test ! -z "$MKDEP"; then
		DEPOUT=""
	elif test "$ac_cv_c_compiler_gnu" = yes; then
		MKDEP="$CC -MM"
	elif test "$SunWorkShop" = yes; then
		MKDEP="$CC -xM"
	elif test ! -z "$MAKEDEPEND"; then
		MKDEP="$MAKEDEPEND -f-"
	fi

	# Show the result of our test.

	if test ! -z "$MKDEP"; then
		AC_MSG_RESULT($MKDEP ... $DEPOUT)
	else
		AC_MSG_RESULT([indeterminate - please check manually])
		MKDEP=":"
	fi

	AC_SUBST(MKDEP)
	AC_SUBST(DEPOUT)
])

dnl
dnl AC_VCHAT_CFLAGS_CHECK
dnl

AC_DEFUN(AC_VCHAT_CFLAGS_CHECK,
[
	AC_MSG_CHECKING(for predefined CFLAGS)

	# When CFLAGS are already set, don't touch them.

	cfset=${CFLAGS+set}

	if test "$cfset" != set; then

		# CFLAGS are not set. Try to get make's idea of global CFLAGS.
		# This will only work with pmake, not with gmake.

		mkcf=`make -V CFLAGS 2>/dev/null`

		if test $? -eq 0 -a ! -z "${mkcf}"; then

			# Use global make CFLAGS.

			CFLAGS=${mkcf}

			AC_MSG_RESULT('${CFLAGS}' (make global))
		else

			AC_MSG_RESULT(none)

		fi

	else

		AC_MSG_RESULT('${CFLAGS}' (environment))

	fi
])

dnl
dnl AC_VCHAT_GCC_WALL_CHECK
dnl

AC_DEFUN(AC_VCHAT_GCC_WALL_CHECK,
[
	# When running gcc, add "-Wall" to CFLAGS.
	
	AC_MSG_CHECKING(whether to add '-Wall' to CFLAGS)
	if test "$ac_cv_c_compiler_gnu" = yes; then
		CFLAGS="-Wall $CFLAGS"
		AC_MSG_RESULT(yes)
	else
		AC_MSG_RESULT(no)
	fi
])

dnl
dnl AC_VCHAT_OSTYPE_CHECK
dnl

AC_DEFUN(AC_VCHAT_OSTYPE_CHECK,
[
	AC_MSG_CHECKING(for appropriate OS_TYPE string)

	if test ! -z "$UNAME"; then
		ostype=`($UNAME -s) 2>/dev/null` || ostype="unknown"
		osvers=`($UNAME -r) 2>/dev/null` || osvers="unknown"
	else
		ostype="unknown"
		osvers="unknown"
	fi

	case "${ostype}" in
		unknown)				OSTP="????"
							;;
		FreeBSD)				OSTP="FBSD"
							;;
		OpenBSD)				OSTP="OBSD"
							;;
		NetBSD)					OSTP="NBSD"
							;;
		BSD/386|BSD/OS)				OSTP="BSDI"
							;;
		Linux)					OSTP="LINU"
							;;
		IRIX*)					OSTP="IRIX"
							;;
		AIX)					OSTP="AIX-"
							;;
		SunOS)					OSTP="SUNO"
							;;
		HP-UX)					OSTP="HPUX"
							;;
		ULTRIX*)				OSTP="ULTX"
							;;
		OSF1)					OSTP="OSF1"
							;;
		OpenVMS)				OSTP="OVMS"
							;;
		ConvexOS)				OSTP="COVX"
							;;
		CYGWIN)					OSTP="CYGW"
							;;
		MINGW32_NT-4.0)				OSTP="WNT4"
							osvers="0"
							;;
		MINGW32_NT-5.0)				OSTP="WNT5"
							osvers="0"
							;;
		MINGW32_NT-6.0)				OSTP="WNT6"
							osvers="0"
							;;
		MINGW)					OSTP="MIGW"
							;;
		LynxOS)					OSTP="LYNX"
							;;
		SINIX-*)				OSTP="SNIX"
							;;
		A/UX)					OSTP="A/UX"
							;;
		BeOS)					OSTP="BeOS"
							;;
		SUPER-UX)				OSTP="SUUX"
							;;
		QNX)					OSTP="QNX-"
							;;
		POSIX*)					OSTP="PSIX"
							;;
		TENEX)					OSTP="TNEX"
							;;
		NEXT|NeXT)				OSTP="NEXT"
							;;
		Windows_95|Windows_98|Windows_NT)	OSTP="W32-"
							;;
		*[dD][aA][rR][wW][iI][nN]*)		OSTP="DRWN"
							;;
		*[bB][sS][dD]*)				OSTP="?BSD"
							;;
		*)					OSTP="`echo ${ostype} | head -c 5`"
							;;
	esac

	case ${osvers} in
		unknown)				OSVS="?"
							;;
		*)					OSVS="`echo ${osvers} | head -c 1`"
							;;
	esac
	
	OSTP="${OSTP}${OSVS}"

	AC_MSG_RESULT($OSTP)

	AC_DEFINE_UNQUOTED(OS_TYPE, "${OSTP}",The appropriate operating system type string.)
])

dnl
dnl AC_VCHAT_UXDOMAIN_CHECK
dnl

AC_DEFUN(AC_VCHAT_UXDOMAIN_CHECK,
[
	AC_CACHE_CHECK(wheter unix domain sockets are supported, ac_cv_uxdomain,
	[AC_COMPILE_IFELSE([AC_LANG_SOURCE(
[[/* check for struct sockaddr_un */
#include <stdio.h>
#if HAVE_STDLIB_H
  #include <stdlib.h>
#endif
#if HAVE_SYS_TYPES_H
  #include <sys/types.h>
#endif
#if HAVE_SYS_SOCKET_H
  #include <sys/socket.h>
#endif
#if HAVE_SYS_UN_H
  #include <sys/un.h>
#endif
int main(int argc, char *argv[])
{
	struct sockaddr_un harbl;
	return 0;
}]])], [ac_cv_uxdomain=yes uxsock=1], [ac_cv_uxdomain=no uxsock=0])])

	if test "$ac_cv_uxdomain" = "yes"; then

		vsprogs="vserver vchatctl"

		AC_CHECK_MEMBERS([struct sockaddr_un.sun_family,
			struct sockaddr_un.sun_path,
			struct sockaddr_un.sun_len],,,[
#if HAVE_STDLIB_H
  #include <stdlib.h>
#endif
#if HAVE_SYS_TYPES_H
  #include <sys/types.h>
#endif
#if HAVE_SYS_SOCKET_H
  #include <sys/socket.h>
#endif
#if HAVE_SYS_UN_H
  #include <sys/un.h>
#endif
		])

	else
		vsprogs="vserver"
	fi

	AC_DEFINE_UNQUOTED(HAVE_UNIX_SOCKETS, $uxsock, Wheter the system supports unix domain sockets)
	AC_SUBST(vsprogs)
])

AC_DEFUN([AC_DEFINE_DIR], [
	prefix_NONE=
	exec_prefix_NONE=
	test "x$prefix" = xNONE && prefix_NONE=yes && prefix=$ac_default_prefix
	test "x$exec_prefix" = xNONE && exec_prefix_NONE=yes && exec_prefix=$prefix
dnl In Autoconf 2.60, ${datadir} refers to ${datarootdir}, which in turn
dnl refers to ${prefix}.  Thus we have to use `eval' twice.
	eval ac_define_dir="\"[$]$2\""
	eval ac_define_dir="\"$ac_define_dir\""
	AC_SUBST($1, "$ac_define_dir")
	AC_DEFINE_UNQUOTED($1, "$ac_define_dir", [$3])
	test "$prefix_NONE" && prefix=NONE
	test "$exec_prefix_NONE" && exec_prefix=NONE
])

AC_DEFUN([AC_VCHAT_BASEDIR_CHECK], [

	default_basedir="${sysconfdir}/vchat/"

	AC_DEFINE_DIR([DEFAULT_BASEDIR], [default_basedir], [The default vserver base directory.])
])

dnl
dnl AC_VCHAT_READLINE_CHECK
dnl

AC_DEFUN([AC_VCHAT_READLINE_CHECK], [

	READLINE_LIBS=""
	lrl=0

	AC_SUBST(READLINE_LIBS)

	AC_CHECK_LIB(readline, readline,
	[
		AC_CHECK_HEADERS([readline.h readline/readline.h],
		[
			READLINE_LIBS="-lreadline"
			lrl=1
		])
	])

	AC_DEFINE_UNQUOTED(HAVE_LIB_READLINE, $lrl, Whether the GNU readline library is installed.)
])


syntax highlighted by Code2HTML, v. 0.9.1