dnl Autoconfigure file for Mondo Rescue v2.0x
dnl Mondo by Mondo dev team
dnl This script by Joshua Oreman
dnl
dnl Process this file with autoconf >=2.53 to produce a configure script.
dnl
dnl $Id: configure.in 561 2006-05-20 15:51:21Z bcornec $
dnl
define(MONDO_VER,m4_normalize(esyscmd(cat VERSION)))
define(MONDO_REV,m4_normalize(esyscmd(cat REVISION | awk '{print r$1}')))
define(MONDO_TAG,MONDO_VER-MONDO_REV)
AC_INIT([Mondo Rescue],MONDO_TAG,[mondo-devel@lists.sourceforge.net])
AC_CONFIG_SRCDIR([mondo/mondoarchive/main.c])
AM_CONFIG_HEADER(config.h)

AC_CANONICAL_HOST
AC_CANONICAL_TARGET
AC_ARG_PROGRAM

AM_INIT_AUTOMAKE([mondo], MONDO_VER)
AM_MAINTAINER_MODE

AC_PROG_CXX
AC_PROG_AWK
AC_PROG_CC
AC_PROG_RANLIB
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET

AM_GNU_GETTEXT([external])
ALL_LINGUAS="fr"

dnl --with/--enable stuff
do_static_mr=
AC_ARG_ENABLE(static-mr, AS_HELP_STRING(--enable-static-mr,Link mondorestore statically), do_static_mr=$withval, do_static_mr= )
AC_ARG_ENABLE(debug, AS_HELP_STRING(--enable-debug,Add debugging flags), CFLAGS="$CFLAGS -g", )
AC_ARG_WITH(max-noof-media, AS_HELP_STRING(--with-max-noof-media=NUM,Compile for a certain maximum number of media (default 50)), max_noof_media=$withval, max_noof_media=50)
AC_ARG_WITH(tape-block-size, AS_HELP_STRING(--with-tape-block-size=NUM,Set tape block size in kilobytes (default 131072)), exttape=${withval:=131072}, exttape=131072)
if test x$do_static_mr = xyes; then
	MONDORESTORE_STATIC=-static
else
	MONDORESTORE_STATIC=
fi
AC_SUBST(MONDORESTORE_STATIC)
AC_DEFINE_UNQUOTED(MAX_NOOF_MEDIA, $max_noof_media, [Maximum number of media])
AC_DEFINE_UNQUOTED(EXTTAPE, $exttape, [Tape blocksize])

# ( which automake 2>/dev/null >/dev/null && ( automake --version 2>&1 | grep -q 1.5 || automake --version 2>&1 | grep -q 1.7 || AC_MSG_ERROR([Automake must be version 1.5 or 1.7, if you have it at all]) ) )

# Checks for libraries.
dnl AC_CHECK_LIB([dl], [main])
AC_CHECK_LIB([newt], [newtInit])
standardthread=0;

case $build in
	*freebsd*)
		standardthread=0
		AC_ARG_ENABLE(standard-pthreads, AS_HELP_STRING(--enable-standard-pthreads,(FreeBSD only) Compile with FreeBSD "standard" pthreads instead of LinuxThreads -- *MAY BE UNSTABLE*), standardthread=1, standardthread=0)
		if test $standardthread -eq 0; then
			CPPFLAGS=$CPPFLAGS -D_THREAD_SAFE -D_REENTRANT -I/usr/local/include/pthread/linuxthreads
			PTHREAD="-L/usr/local/lib -llthread -llgcc_r";
			if ! test -f /usr/local/include/pthread/linuxthreads/pthread.h; then
				echo "*** Cannot find pthread.h: are you SURE you have linuxthreads installed?"
				exit 1
			fi
			AC_CHECK_LIB(lthread, pthread_create, true, [echo "*** Cannot find -llthread."; echo "*** Please install linuxthreads from /usr/ports/devel/linuxthreads."; exit 1], [-L/usr/local/lib -llgcc_r])
		else
			PTHREAD="-lc_r"
		fi
		;;
	*linux*)
		AC_CHECK_LIB(pthread, pthread_create, true, [echo "*** Cannot find -lpthread."; echo "*** Please make sure you have the linuxthreads glibc add-on installed."; exit 1])
		PTHREAD="-lpthread"
		CFLAGS="$CFLAGS -Wall -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_REENTRANT"
		;;
	*)
		echo "*** Sorry, only Linux and FreeBSD are supported at this time. Want to help?"
		;;
esac

if test "$host_cpu" != "$target_cpu"; then
	host_cpu=$target_cpu
fi
case "$host_cpu" in
	i?86*)
		ARCH=i386
		CPPFLAGS="$CPPFLAGS -D__IA32__ -Wall"
		;;
	x86_64*)
		ARCH=x86-64
		CPPFLAGS="$CPPFLAGS -D__X86_64__ -Wall"
		;;
	ia64*)
		ARCH=ia64
		CPPFLAGS="$CPPFLAGS -D__IA64__ -Wall"
		;;
	*)
		echo "*** Sorry, only Intel Architectures (ia32, x86-64, ia64) are supported at this time." 
		echo "If you Want to help send a mail to bcornec@users.berlios.de" 
		;;
esac
AC_SUBST(ARCH)

LIBS="$LIBS $PTHREAD"
AC_SUBST(LIBS)

# Checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([fcntl.h stddef.h stdlib.h string.h sys/ioctl.h sys/param.h sys/time.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_OFF_T
AC_TYPE_PID_T

# Checks for library functions.
AC_FUNC_CHOWN
AC_FUNC_FORK
AC_PROG_GCC_TRADITIONAL
AC_FUNC_LSTAT
AC_FUNC_MALLOC
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([bzero getcwd memmove memset mkdir mkfifo setenv strcasecmp strchr strerror strrchr strstr getline asprintf trunc vasprintf])

AC_OUTPUT([Makefile mondo/Makefile mondo/common/Makefile mondo/mondoarchive/Makefile mondo/mondorestore/Makefile mondo/restore-scripts/Makefile mondo/restore-scripts/mondo/Makefile mondo/restore-scripts/usr/Makefile mondo/restore-scripts/usr/bin/Makefile mondo/post-nuke.sample/Makefile mondo/post-nuke.sample/usr/Makefile mondo/post-nuke.sample/usr/bin/Makefile po/Makefile.in m4/Makefile])
