#include "aclocal.m4"

AC_SUBST(SHELL)
AC_SUBST(YACC)
AC_SUBST(ARCH)
AC_SUBST(EXEEXT)
AC_SUBST(INSTALL_DX_EXE)
AC_SUBST(INSTALL_DX_CSH)

dnl Process this file with autoconf to produce a configure script.
AC_INIT(include/dx/arch.h)
AM_CONFIG_HEADER(include/dxconfig.h)
AM_INIT_AUTOMAKE(dx, 4.0)

AC_DEFINE(DXD_VERSION_STRING,   "04.01.0001")
AC_DEFINE_UNQUOTED(DXD_VERSION, 4)
AC_DEFINE_UNQUOTED(DXD_RELEASE, 1)
AC_DEFINE_UNQUOTED(DXD_MODIFICATION, 1)

DX_ARCHITECTURE
DX_STREAM_O2

AC_CHECK_PROG(HAVE_CSH, csh, 1, 0)

if test "$HAVE_CSH" = "1" ; then
    INSTALL_DX_EXE=
    INSTALL_DX_CSH="dx dx.workerscript"
else
    INSTALL_DX_EXE=dx
    INSTALL_DX_CSH=
fi

dnl Checks for programs.
AC_PROG_RANLIB
DX_PROG_CXX(-g)
DX_PROG_CC
DX_PROG_CPP
DX_CYGWIN
DX_EXEEXT

AC_PATH_X
if test "$x_includes" != "" ; then
    CFLAGS="$CFLAGS -I$x_includes"
    CXXFLAGS="$CXXFLAGS -I$x_includes"
fi
if test "$x_libraries" != "" ; then
    LIBS="-L$x_libraries $LIBS"
fi

AC_EGREP_CPP(yes,
[
#include <Xm/Xm.h>
#ifdef LESSTIF_VERSION
yes
#endif
],
[
    AC_DEFINE_UNQUOTED(USING_LESSTIF, 1)
],
[
    AC_DEFINE_UNQUOTED(USING_LESSTIF, 0)
])
if test "$ARCH" = "solaris" ; then
    OLDLIBS=$LIBS
    LIBS="-L/usr/openwin/lib $LIBS"
    AC_CHECK_LIB(dga, dga_draw_devfd, 
    [
	LIBS="$LIBS -ldga"
	AC_CHECK_LIB(Xmu, XmuAddInitializer, LIBS="$LIBS -lXmu")
    ], LIBS=$OLDLIBS, -lX11)
fi

AC_CHECK_LIB(gen, regex)

dnl A couple libs for cygwin
AC_CHECK_LIB(ICE, IceConnectionNumber)
AC_CHECK_LIB(SM, SmcSetProperties)
AC_CHECK_LIB(REXP, regcomp)
AC_CHECK_LIB(pthread, pthread_getspecific)

DX_CHECK_HEADERS(fcntl.h limits.h malloc.h strings.h sys/file.h sys/ioctl.h sys/time.h unistd.h sys/types.h sys/sysconfig.h sys/un.h values.h wait.h sys/wait.h sys/utsname.h signal.h sys/signal.h process.h sys/filio.h CC/osfcn.h CC/libc.h )
AC_CHECK_FUNCS(getcwd gethostname gettimeofday mkdir mkfifo mktime putenv re_comp regcmp select socket strcspn strdup strerror strspn strstr strtod strtol strtoul uname popen vfork trunc _popen spawnvp _spawnvp regcomp sysmp sysconf)

AC_TRY_LINK(
[
#include <sys/systemcfg.h>
],
[
int n = _system_configuration.ncpus;
],
[
AC_DEFINE_UNQUOTED(HAVE_SYSCONFIG_NCPUS)
echo yes
],
[
echo no
])

AC_EGREP_HEADER(sys_errlist, errno.h, AC_DEFINE(HAVE_SYS_ERRLIST))
AC_EGREP_HEADER(sys_errlist, stdio.h, AC_DEFINE(HAVE_SYS_ERRLIST))

dnl Check yaccer.  Don't use standard AQC_PROG_YACC... We're going
dnl to create an -D as well as the make variable
AC_CHECK_PROG(yakker, bison, "bison", "yacc")
if test "$yakker" = "bison" ; then
    AC_DEFINE(USING_BISON)
    YACC="bison -y"
else
    YACC=yacc
fi

dnl Checks for libraries.
AC_CHECK_LIB(g++, main)
AC_CHECK_LIB(dl, main)
AC_CHECK_LIB(z, compress)
AC_CHECK_LIB(cdf, CDFlib)
AC_CHECK_LIB(df, Hopen)
AC_CHECK_LIB(netcdf, free_NC_attr)


AC_CHECK_LIB(cdf, main)
AC_CHECK_LIB(hdf, main)

dnl Checks for header files.
AC_PATH_X
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_MODE_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM

DX_HEADER_HAS_SYMBOL(math.h, M_PI)
DX_HEADER_HAS_SYMBOL(math.h, M_SQRT2)
DX_HEADER_HAS_SYMBOL(sys/stat.h, S_ISDIR)
DX_HEADER_HAS_SYMBOL(sys/sysmp.h, sysmp)

dnl Checks for library functions.
AC_FUNC_MEMCMP
AC_FUNC_SETVBUF_REVERSED
AC_TYPE_SIGNAL
AC_FUNC_VFORK
AC_FUNC_VPRINTF

AC_CHECK_TYPE(uint, unsigned int)

AC_CHECK_TYPE(byte, char)
AC_CHECK_TYPE(ubyte, unsigned char)
AC_CHECK_TYPE(short, short)
AC_CHECK_TYPE(ushort, unsigned short)
AC_CHECK_TYPE(ulong, unsigned long)

AC_CHECK_TYPE(int8, char)
AC_CHECK_TYPE(uint8, unsigned char)
AC_CHECK_TYPE(int16, short)
AC_CHECK_TYPE(uint16, unsigned short)
AC_CHECK_TYPE(int32, int)
AC_CHECK_TYPE(uint32, unsigned int)
AC_CHECK_TYPE(int64, long)
AC_CHECK_TYPE(uint64, unsigned long)
AC_CHECK_TYPE(uint, unsigned int)

AC_CHECK_TYPE(float32, float)
AC_CHECK_TYPE(float64, double)

AC_C_BIGENDIAN

AC_LANG_CPLUSPLUS
AC_TRY_LINK(
[
#include <signal.h>
extern "C" void foo(int bar, ...){}
],
[
signal(SIGBUS, foo);
],
[
echo Using alternate signal argument list in C++
AC_DEFINE_UNQUOTED(ALTERNATE_CXX_SIGNAL)
],
[
echo Using standard signal argument list in C++
])



AC_OUTPUT( bin/dx bin/Makefile src/ui++/ui/Makefile lib/Makefile src/exec/hwrender/gl/Makefile src/exec/hwrender/xgl/Makefile src/exec/hwrender/starbase/Makefile src/ui++/dxuilib/Makefile src/ui++/ui/Makefile src/exec/Makefile src/exec/dxexec/Makefile include/Makefile include/dx/Makefile src/exec/libdx/Makefile src/Makefile src/exec/dpexec/Makefile src/exec/dxmods/Makefile src/ui++/base/Makefile src/ui++/Makefile src/ui++/dxl/Makefile src/ui++/dxui/Makefile src/ui++/prompter/Makefile src/ui++/mb/Makefile src/ui++/widgets/Makefile src/ui++/startup/Makefile src/ui++/tutor/Makefile src/ui++/java/dx/protocol/server/Makefile src/ui++/java/dx/protocol/Makefile src/ui++/java/dx/Makefile src/ui++/java/dx/runtime/Makefile src/ui++/java/dx/client/Makefile src/ui++/java/dx/net/Makefile src/ui++/java/dx/applets/Makefile src/ui++/java/dx/server/Makefile src/ui++/java/Makefile src/exec/hwrender/opengl/Makefile src/exec/hwrender/Makefile Makefile help/Makefile html/Makefile man/catl/Makefile man/manl/Makefile man/Makefile fonts/Makefile doc/Makefile src/misc/Makefile)
