dnl $Id: configure.in,v 1.5 1999/06/09 06:26:28 boyns Exp $
dnl
dnl Process this file with autoconf to produce a configure script.
dnl

AC_INIT(rplayd/rplayd.c)
AC_CONFIG_HEADER(include/config.h)

dnl
dnl Figure what version of rplay this is.
dnl

export srcdir
RPLAY_VERSION=`$srcdir/version`

echo configuring rplay version $RPLAY_VERSION
AC_SUBST(RPLAY_VERSION)
AC_DEFINE_UNQUOTED(RPLAY_VERSION, "$RPLAY_VERSION")

# We want these before the checks, so the checks can modify their values.
test -z "$CFLAGS" && CFLAGS=-g auto_cflags=1

AC_PROG_CC

# If we're using gcc and the user hasn't specified CFLAGS, add -O to CFLAGS.
test -n "$GCC" && test -n "$auto_cflags" && CFLAGS="$CFLAGS -O"

AC_SUBST(CFLAGS)dnl
AC_SUBST(LDFLAGS)dnl

AC_ARG_ENABLE(rplayd-user, [  --enable-rplayd-user=USER], RPLAYD_USER=$enableval)
AC_ARG_ENABLE(rplayd-group, [  --enable-rplayd-group=GROUP], RPLAYD_GROUP=$enableval)
if test -n "$RPLAYD_USER"
then
AC_DEFINE_UNQUOTED(RPLAYD_USER, "$RPLAYD_USER")
fi
if test -n "$RPLAYD_GROUP"
then
AC_DEFINE_UNQUOTED(RPLAYD_GROUP, "$RPLAYD_GROUP")
fi


dnl Programs
AC_ISC_POSIX
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_RANLIB
AC_CHECK_PROGS(ETAGS, etags, true)
AC_CHECK_PROGS(MAKEDEPEND, makedepend, true)
AC_CHECK_PROGS(MAKEINFO, makeinfo, true)
AC_CHECK_PROGS(TEXI2DVI, texi2dvi, true)
AC_CHECK_PROGS(TEXI2HTML, texi2html, true)
AC_CHECK_PROGS(DVIPS, dvips, true)

dnl Check for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_TIME
dnl AC_PATH_XTRA
AC_CHECK_HEADERS(fcntl.h sys/file.h sys/ioctl.h sys/time.h stdlib.h unistd.h memory.h string.h strings.h utime.h limits.h gsm.h gsm/gsm.h rxposix.h rx/rxposix.h)
AC_HEADER_SYS_WAIT

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

dnl Check for library functions.
AC_FUNC_MMAP
AC_FUNC_MEMCMP
AC_FUNC_VPRINTF
AC_TYPE_SIGNAL
AC_CHECK_FUNCS(getcwd gethostname mkdir re_comp regcomp select snprintf socket strdup strerror strstr fstat fchmod fchown utime utimes memmove sigset vsnprintf waitpid random srandom)
AC_CHECK_LIB(socket, socket, [LIBS="$LIBS -lsocket"])
AC_CHECK_LIB(nsl, t_accept, [LIBS="$LIBS -lnsl"])

AC_CHECK_LIB(readline, readline, [RL_LIBS="-lreadline"])
AC_SUBST(RL_LIBS)

AC_CHECK_LIB(gsm, gsm_decode, [HAVE_GSM="yes"])
if test "$HAVE_GSM" = "yes"; then
    GSM_LIBS="-lgsm"
    GSM_INCS=""
else
    GSM_LIBS="-L../gsm -lgsm"
    GSM_INCS="-I\${srcdir}/../gsm"
fi
AC_SUBST(GSM_LIBS)
AC_SUBST(GSM_INCS)

AC_CHECK_LIB(rx, regncomp, [HAVE_RX="yes"])
if test "$HAVE_RX" = "yes"; then
    RX_LIBS="-lrx"
    RX_INCS=""
else
    RX_LIBS="-L../rx -lrx"
    RX_INCS="-I\${srcdir}/../rx"
fi
AC_SUBST(RX_LIBS)
AC_SUBST(RX_INCS)

RPLAY_TOP=`pwd`
AC_SUBST(RPLAY_TOP)

dnl
dnl First check if target is already defined.
dnl
if test -n "$target" -a "$target" != "NONE"; then
	RPLAY_TARGET=$target
	echo "using specified $RPLAY_TARGET configuration"
fi

dnl
dnl Check for Sun
dnl
if test -z "$RPLAY_TARGET"; then
AC_MSG_CHECKING(for sun)
AC_EGREP_CPP(yes,
[
#ifdef sun
  yes
#endif
], is_sun=yes, is_sun=no)
AC_MSG_RESULT($is_sun)
if test $is_sun = "yes"; then
	RPLAY_TARGET="sun"
fi
if test "$RPLAY_TARGET"; then
	AC_MSG_CHECKING(for solaris)
	if test ! -f /vmunix; then
		is_solaris=yes
		RPLAY_TARGET="solaris"
	else
		is_solaris=no
	fi
	AC_MSG_RESULT($is_solaris)
fi
fi

dnl
dnl Check for Linux
dnl
if test -z "$RPLAY_TARGET"; then
AC_MSG_CHECKING(for linux)
AC_EGREP_CPP(yes,
[
#ifdef linux
  yes
#endif
], is_linux=yes, is_linux=no)
AC_MSG_RESULT($is_linux)
if test $is_linux = "yes"; then
	RPLAY_TARGET="oss"
fi
fi

dnl
dnl Check for HP-UX
dnl
if test -z "$RPLAY_TARGET"; then
AC_MSG_CHECKING(for hpux)
AC_EGREP_CPP(yes,
[
#ifdef __hpux
  yes
#endif
], is_hpux=yes, is_hpux=no)
AC_MSG_RESULT($is_hpux)
if test $is_hpux = "yes"; then
	RPLAY_TARGET="hpux"
fi
fi

dnl
dnl Check for SGI
dnl
if test -z "$RPLAY_TARGET"; then
AC_MSG_CHECKING(for sgi)
AC_EGREP_CPP(yes,
[
#ifdef sgi
  yes
#endif
], is_sgi=yes, is_sgi=no)
AC_MSG_RESULT($is_sgi)
if test $is_sgi = "yes"; then
	RPLAY_TARGET="sgi"
	AC_MSG_CHECKING(for multimedia development kit)
	AC_CHECK_HEADERS(audio.h)
	if test $ac_cv_header_audio_h = "no"; then
		echo 'The multimedia development kit was not found.'
		echo 'Please read the README.sgi file.'
		exit -1
	fi
fi
fi

dnl
dnl Check for FreeBSD
dnl
if test -z "$RPLAY_TARGET"; then
AC_MSG_CHECKING(for FreeBSD)
AC_EGREP_CPP(yes,
[
#ifdef __FreeBSD__
  yes
#endif
], is_freebsd=yes, is_freebsd=no)
AC_MSG_RESULT($is_freebsd)
if test $is_freebsd = "yes"; then
	RPLAY_TARGET="FreeBSD"
fi
fi

dnl
dnl *** Add new systems before this line ***
dnl

dnl
dnl Now make sure the system type has been found.
dnl
if test -z "$RPLAY_TARGET"; then
	echo 'Sorry, I could not figure out what type of system you have.'
	echo -n 'Would you like to try the generic configuration? '
	read ans
	case "$ans" in
	y|Y|yes|Yes|YES|sure|ok|okay) RPLAY_TARGET="generic" ;;
	*) echo configuration aborted; exit 1;
	esac
fi

echo "using $RPLAY_TARGET configuration"
AC_SUBST(RPLAY_TARGET)

AC_LINK_FILES(rplayd/audio/audio_${RPLAY_TARGET}.c rplayd/audio/audio_${RPLAY_TARGET}.h, rplayd/audio.c rplayd/audio.h)

dnl
dnl Add special things to @DEFS@.
dnl
if test $RPLAY_TARGET = "solaris"; then
	AC_DEFINE(SVR4)
fi
AC_SUBST(DEFS)

dnl
dnl Add special things to @LIBS@.
dnl
if test $RPLAY_TARGET = "sgi"; then
	LIBS="$LIBS -laudio"
fi
AC_SUBST(LIBS)

BUILD_TARGETS="include lib adpcm"
if test "$HAVE_RX" != "yes"; then
    BUILD_TARGETS="$BUILD_TARGETS rx"
    AC_CONFIG_SUBDIRS(rx)
fi
if test "$HAVE_GSM" != "yes"; then
    BUILD_TARGETS="$BUILD_TARGETS gsm"
fi

BUILD_TARGETS="$BUILD_TARGETS librplay rplayd rplay rptp doc"

if test $RPLAY_TARGET = "oss"; then
    BUILD_TARGETS="$BUILD_TARGETS devrplay"
fi

AC_SUBST(BUILD_TARGETS)

AC_OUTPUT(Makefile.config Makefile include/Makefile lib/Makefile adpcm/Makefile gsm/Makefile librplay/Makefile rplayd/Makefile rplay/Makefile rptp/Makefile doc/Makefile devrplay/Makefile)
