AC_INIT(README)

if test -d /usr/share/games ; then
    OBVDIR="/usr/share/games/acm"
else
    OBVDIR=\$\(prefix\)/games/acm
fi
AC_SUBST(OBVDIR)

rand=0
random=0

if test "$OPENWINHOME" = "" ; then
	ow=/usr/openwin
else
	ow=$OPENWINHOME
fi

# Solaris special handling ...
SOLARIS=0
if uname -sr | grep '^SunOS 5' >/dev/null ; then
	LIBS="$LIBS -R/usr/ucblib -L/usr/ucblib -lucb"
	SOLARIS=1
fi

# Linux ?
LINUX=0
if uname -s | grep -i linux > /dev/null ; then
	LINUX=1
fi 

AC_PROG_CC

AC_CHECK_LIB(nsl, xdr_free, [LIBS="$LIBS -lnsl"])

if test "$LINUX" = "0" ; then
	AC_CHECK_LIB(elf, elf_end, [LIBS="$LIBS -lelf"])
fi

AC_DEFUN(AC_M_PI_LONG_DOUBLE,
[AC_CACHE_CHECK(for M_PI casted to long double, ac_cv_m_pi_long_double,
[AC_TRY_RUN([#include <math.h>
#ifndef M_PI
#define M_PI 3.1415926
#endif
  int main() {
  exit(sizeof(double) < sizeof(M_PI)); }],
  ac_cv_m_pi_long_double=no, ac_cv_m_pi_long_double=yes,
  ac_cv_m_pi_long_double=no)
  ])
  if test $ac_cv_m_pi_long_double = yes; then
	AC_DEFINE(M_PI_LONG_DOUBLE)
  fi
])   

AC_DEFUN(AC_HAVE_STRUCT_SIGACTION,
[AC_CACHE_CHECK(for sigaction structure, ac_cv_struct_sigaction,
[AC_TRY_COMPILE([#include <signal.h>
#include <sys/signal.h>],[ struct sigaction s; ],
  ac_cv_struct_sigaction=yes, ac_cv_struct_sigaction=no)
  ])
  if test $ac_cv_struct_sigaction = yes; then
        AC_DEFINE(HAVE_STRUCT_SIGACTION)
  fi
])  

AC_PROG_INSTALL
AC_PROG_RANLIB
AC_HEADER_STDC
AC_CHECK_HEADERS(stdlib.h malloc.h unistd.h)
if test "$LINUX" = "0" ; then
	AC_CHECK_HEADER(elf.h, AC_DEFINE(SVR4) LIBS="$LIBS -lelf")
fi
AC_TYPE_SIGNAL
AC_HAVE_STRUCT_SIGACTION
AC_M_PI_LONG_DOUBLE

AC_PATH_X

test "$x_includes" != "NONE" -a "$x_includes" != "" && CFLAGS="$CFLAGS -I${x_includes}"
test "$x_libraries" != "NONE" -a "$x_libraries" != "" && LIBS="$LIBS -L${x_libraries}"

LIBS="$LIBS -lX11"

AC_SUBST(VLIB_EXTRA_C_FILES)
AC_SUBST(VLIB_EXTRA_O_FILES)
AC_CHECK_LIB(Xext, XdbeSwapBuffers, 
  [ echo "Found X11 double buffering extension"; 
    LIBS="$LIBS -lXext";
    VLIB_EXTRA_C_FILES="Vdbe.c";
    VLIB_EXTRA_O_FILES="Vdbe.o";
    AC_DEFINE(HAVE_X11_DBE) ])

AC_SUBST(SRC_EXTRA_C_FILES)
AC_SUBST(SRC_EXTRA_O_FILES)
AC_CHECK_LIB(X11, XInitImage, 
  [echo "Found X11R6 XInitImage"],
  [ SRC_EXTRA_C_FILES="ImUtil.c";
    SRC_EXTRA_O_FILES="ImUtil.o" ])

AC_MSG_CHECKING(should the IEEE 1278 DIS protocol be used...)
AC_ARG_ENABLE(dis,
[  --enable-dis             broadcast IEEE 1278 DIS packets],
[if test "$enableval" = yes; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(HAVE_DIS)
else
  AC_MSG_RESULT(no)
fi], AC_DEFINE(HAVE_DIS) AC_MSG_RESULT(yes))

AC_MSG_CHECKING(if DIS debugging should be compiled-in)
AC_ARG_ENABLE(dis-debug,
[  --enable-dis-debug       compile-in DIS debugging messages],
[if test "$enableval" = yes; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(DIS_DEBUG)
else
  AC_MSG_RESULT(no)
fi], AC_MSG_RESULT(no))

AC_MSG_CHECKING(should DIS experimental request/grant control be used...)
AC_ARG_ENABLE(request-control,
[  --enable-request-control use experimental DIS request control protocol],
[if test "$enableval" = yes; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(USE_REQUEST_CONTROL)
else
  AC_MSG_RESULT(no)
fi], AC_DEFINE(USE_REQUEST_CONTROL) AC_MSG_RESULT(yes))


AC_CHECKING(checking for an ACM-compatible audio library ...)
unset ac_cv_lib_audio
AC_CHECK_LIB(audio, AuCloseServer, [echo "Found NCD Netaudio libraries"; 
  LIBS="$LIBS -lXt -laudio -lm"; AC_DEFINE(NETAUDIO)],,-lXt -lm)
if test "$ac_cv_lib_audio" = "no"; then
unset ac_cv_lib_audio
AC_CHECK_LIB(audio, ACloseAudio, [echo "Found HP audio libraries"; 
  LIBS="$LIBS -laudio"; AC_DEFINE(HPAUDIO)])
    if test "$ac_cv_lib_audio" = "no"; then
	AC_MSG_WARN(No ACM-compatible audio library was found -- ACM will compile anyway)
    fi
fi
unset ac_cv_lib_audio

AC_CHECK_LIB(socket, bind, [LIBS="$LIBS -lsocket"])
AC_CHECK_LIB(dnet_stub, main, [LIBS="$LIBS -ldnet_stub"])

if uname -srv | grep '^AIX 2 3' >/dev/null ; then
    :
else
	AC_CHECK_LIB(bsd, main, [LIBS="$LIBS -lbsd"])
fi

LIBS="$LIBS -lm"

AC_REPLACE_FUNCS(strdup)

AC_CHECK_FUNC(rand, AC_DEFINE(HAVE_RAND),
  AC_CHECK_FUNC(random, AC_DEFINE(HAVE_RANDOM),
    [AC_MSG_ERROR(Hmm. Your system does not support either random() or rand().)
      exit 1]))

AC_CHECK_FUNC(isnan, AC_DEFINE(HAVE_ISNAN),
  AC_CHECK_FUNC(_isnan, [AC_DEFINE(HAVE_ISNAN) AC_DEFINE(isnan,_isnan)]))

AC_CHECK_FUNC(sigvec, AC_DEFINE(HAVE_SIGVEC),
  AC_CHECK_FUNC(sigvector, AC_DEFINE(HAVE_SIGVECTOR)))

# Solaris has the copysign function in libc but provides no
# prototype when compiling with gcc in __GCC__ mode.

if test "$SOLARIS" = "0" ; then
	AC_CHECK_FUNC(copysign, AC_DEFINE(HAVE_COPYSIGN))
fi

AC_CONFIG_SUBDIRS(dis dxf2obj gedit)

AC_OUTPUT(Makefile src/Makefile V/Makefile V/lib/Makefile V/test/Makefile objects/Makefile)
