dnl Process this file with autoconf to produce a configure script.

dnl Copyright (c) 2003 Morgan Stanley Dean Witter and Co. All rights reserved.
dnl See .../src/LICENSE for terms of distribution. 


AC_INIT(src/dap/BcdPack.c)
AC_CONFIG_AUX_DIR(config)
AM_INIT_AUTOMAKE(aplus-fsf,4.20)
AM_MAINTAINER_MODE
AC_PREREQ([2.50])

dnl Checks for programs.
AC_PROG_CC
AC_PROG_CXX

AM_PROG_LIBTOOL 
AC_SUBST(LIBTOOL_DEPS)

AC_PROG_INSTALL

dnl Checks for libraries.
LIBS="$LIBS -lm" 
AC_CHECK_LIB(  dl, main, LIBS="-ldl $LIBS") 
AC_CHECK_LIB( nsl, main, LIBS="-lnsl $LIBS") 
AC_CHECK_LIB( pthread, main, LIBS="-lpthread $LIBS") 
 
dnl Checks for library functions.
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MEMCMP
AC_FUNC_MMAP
AC_TYPE_SIGNAL
AC_FUNC_STRFTIME
AC_FUNC_VFORK
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(getcwd gethostname gettimeofday getwd mktime putenv regcomp select sigaction socket strcspn strdup strerror strstr strtod strtol strtoul)

dnl Future replacement for nsl/socket 
dnl AC_SEARCH_LIBS(gethostbyname, nsl) 
dnl AC_CHECK_FUNC(socket, , [ 
dnl    AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket", [ 
dnl        AC_CHECK_LIB(nsl, socket, LIBS="$LIBS -lsocket -lnsl", , -lsocket) 
dnl    ], "$LIBS") 
dnl ]) 

dnl Checks for X headers and libs.
AC_PATH_X([X11], [X11/Xlib.h], [XOpenDisplay(NULL)])
if test "x$no_x" = "x"; then
   X_INCLUDES="-I$x_includes"
   X_LIBS="-L$x_libraries -lX11"
else
   X_INCLUDES=""
   X_LIBS=""
fi
AC_SUBST(X_INCLUDES)
AC_SUBST(X_LIBS)

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(fcntl.h limits.h malloc.h strings.h sys/file.h sys/ioctl.h sys/time.h syslog.h unistd.h fp_class.h ieeefp.h math.h float.h)

dnl Checks for standard C++ headers
AC_LANG_PUSH(C++)
AC_CHECK_HEADERS(new iostream iomanip fstream sstream iosfwd)
AC_LANG_POP(C++)

dnl Additional m4 macros
dnl test for socklen_t
AC_DEFUN(AC_TYPE_SOCKLEN_T,
  [AC_CACHE_CHECK([for socklen_t], ac_cv_type_socklen_t,
  [
    AC_TRY_COMPILE(
    [#include <sys/types.h>
#include <sys/socket.h>],
    [socklen_t len = 42; return len;],
    ac_cv_type_socklen_t=yes,
    ac_cv_type_socklen_t=no)
  ])
    if test $ac_cv_type_socklen_t = yes; then
	AC_DEFINE(HAVE_SOCKLEN_T, 1, [Whether you have socklen_t]) 
    fi
  ])

dnl test for SVR4 defines
AC_DEFUN(AC_DEFINE_SVR4,
  [AC_CACHE_CHECK([for SVR4 defines], ac_cv_define_svr4,
  [
    AC_TRY_COMPILE(
    [],
    [
#if defined(_SYSTYPE_SVR4) || defined(__SYSTYPE_SVR4) || defined(_SVR4) || defined(__SVR4)
     return 1;
#else 
     foobar
#endif
    ],
    ac_cv_define_svr4=yes,
    ac_cv_define_svr4=no)
  ])
    if test $ac_cv_define_svr4 = yes; then
	AC_DEFINE(HAVE_SVR4, 1, [Whether is SVR4]) 
    fi
  ])

dnl HP-UX 11.00 does not have finite but does have isfinite as a macro
AC_CHECK_FUNCS(fpclassify, ,
  [AC_MSG_CHECKING(for fpclassify with <math.h>)
    AC_TRY_LINK([#include <math.h>], [float f = 0.0; fpclassify(f)],
      AC_MSG_RESULT(yes)
      AC_DEFINE(HAVE_FPCLASSIFY), AC_MSG_RESULT(no))])
AC_CHECK_FUNCS(finite, ,
  [AC_CHECK_FUNCS(isfinite, ,
    [AC_MSG_CHECKING(for isfinite with <math.h>)
    AC_TRY_LINK([#include <math.h>], [float f = 0.0; isfinite(f)],
      AC_MSG_RESULT(yes)
      AC_DEFINE(HAVE_ISFINITE), AC_MSG_RESULT(no))])])
AC_CHECK_FUNCS(isinf, ,
  [AC_MSG_CHECKING(for isinf with <math.h>)
    AC_TRY_LINK([#include <math.h>], [float f = 0.0; isinf(f)],
      AC_MSG_RESULT(yes)
      AC_DEFINE(HAVE_ISINF), AC_MSG_RESULT(no))])

dnl determine how to get IEEE math working
dnl AC_IEEE(MESSAGE, set rd_cv_ieee_[var] variable, INCLUDES,
dnl   FUNCTION-BODY, [ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]])

AC_DEFUN(AC_IEEE, 
AC_MSG_CHECKING([if IEEE math works $1])
AC_CACHE_VAL([rd_cv_ieee_$2],
[AC_TRY_RUN([$3

#if HAVE_MATH_H
#  include <math.h>
#endif

#if HAVE_FLOAT_H
#  include <float.h>  
#endif

#if HAVE_IEEEFP_H
#  include <ieeefp.h>
#endif

#if HAVE_FP_CLASS_H
#  include <fp_class.h>
#endif

/* Solaris */
#if (! defined(HAVE_ISINF) && defined(HAVE_FPCLASS))
#  define HAVE_ISINF 1
#  define isinf(a) (fpclass(a) == FP_NINF || fpclass(a) == FP_PINF)
#endif

/* Digital UNIX */
#if (! defined(HAVE_ISINF) && defined(HAVE_FP_CLASS) && defined(HAVE_FP_CLASS_H))
#  define HAVE_ISINF 1
#  define isinf(a) (fp_class(a) == FP_NEG_INF || fp_class(a) == FP_POS_INF)
#endif 

/* AIX */
#if (! defined(HAVE_ISINF) && defined(HAVE_CLASS))
#  define HAVE_ISINF 1
#  define isinf(a) (class(a) == FP_MINUS_INF || class(a) == FP_PLUS_INF)
#endif

#if (! defined(HAVE_ISINF) && defined(HAVE_FPCLASSIFY) && defined(FP_PLUS_INF) && defined(FP_MINUS_INF))
#  define HAVE_ISINF 1
#  define isinf(a) (fpclassify(a) == FP_MINUS_INF || fpclassify(a) == FP_PLUS_INF)
#endif

#if (! defined(HAVE_ISINF) && defined(HAVE_FPCLASSIFY) && defined(FP_INFINITE))
#  define HAVE_ISINF 1
#  define isinf(a) (fpclassify(a) == FP_INFINITE)
#endif

/* IRIX */
#if (! defined(isinf) && defined(HAVE_FINITE))
#  define HAVE_ISINF 1
#  define isinf(a) (!finite(a))
#endif

#include <stdio.h>
int main(void){
    double nan,inf,c,zero;
    $4;
    /* some math to see if we get a floating point exception */
    zero=sin(0.0); /* don't let the compiler optimize us away */
    nan=0.0/zero; /* especially here */
    inf=1.0/zero; /* and here. I want to know if it can do the magic */
		  /* at run time without sig fpe */
    c = inf + nan;
    c = inf / nan;
    if (! isnan(nan)) {printf ("not isnan(NaN) ... "); return 1;}
    if (nan == nan) {printf ("nan == nan ... "); return 1;}
    if (! isinf(inf)) {printf ("not isinf(oo) ... "); return 1;}
    if (! isinf(-inf)) {printf ("not isinf(-oo) ... "); return 1;}
    if (! inf > 0) {printf ("not inf > 0 ... "); return 1;}
    if (! -inf < 0) {printf ("not -inf < 0 ... "); return 1;}
    return 0;
 }],

rd_cv_ieee_$2=yes,
rd_cv_ieee_$2=no,
:)])
dnl these we run regardles is cached or not
if test x${rd_cv_ieee_$2} = "xyes"; then
 AC_MSG_RESULT(yes)
 $5
else
 AC_MSG_RESULT(no)
 $6
fi

)

_cxxflags=${CXXFLAGS}
_cflags=${CFLAGS}
AC_IEEE([out of the box], works, , , ,
  [CXXFLAGS="$_cxxflags -ieee" CFLAGS="$_cflags -ieee"
  AC_IEEE([with the -ieee switch], switch, , , ,
    [CXXFLAGS="$_cxxflags -qfloat=nofold" CFLAGS="$_cflags -qfloat=nofold"
    AC_IEEE([with the -qfloat=nofold switch], nofold, , , ,
      [CXXFLAGS="$_cxxflags -w -qflttrap=enable:zerodivide" CFLAGS="$_cflags -w -qflttrap=enable:zerodivide"
      AC_IEEE([with the -w -qflttrap=enable:zerodivide], flttrap, , , ,
       [CXXFLAGS="$_cxxflags -mieee" CFLAGS="$_cflags -mieee"
       AC_IEEE([with the -mieee switch], mswitch, , , ,
         [CXXFLAGS="$_cxxflags -q float=rndsngl" CFLAGS="$_cflags -q float=rndsngl"
         AC_IEEE([with the -q float=rndsngl switch], qswitch, , , ,
           [CXXFLAGS="$_cxxflags -OPT:IEEE_comparisons=ON" CFLAGS="$_cflags -OPT:IEEE_comparisons=ON"
           AC_IEEE([with the -OPT:IEEE_comparisons=ON switch], ieeecmpswitch, , , ,
             [CXXFLAGS=$_cxxflags CFLAGS=$_cflags
             AC_IEEE([with fpsetmask(0)], mask,
               [#include <floatingpoint.h>], [fpsetmask(0)], ,
               [AC_IEEE([with signal(SIGFPE,SIG_IGN)], sigfpe,
                 [#include <signal.h>], [signal(SIGFPE,SIG_IGN)], ,
                 AC_MSG_ERROR([
Your Compiler does not do propper IEEE math ... Please find out how to
make IEEE math work with your compiler and let me know (oetiker@ee.ethz.ch).
Check config.log to see what went wrong ...
]))])])])])])])])])

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_STRUCT_ST_BLKSIZE
AC_STRUCT_ST_BLOCKS
AC_STRUCT_ST_RDEV
AC_HEADER_TIME
AC_STRUCT_TM
AC_STRUCT_TIMEZONE
AC_TYPE_UID_T
AC_TYPE_SOCKLEN_T
AC_DEFINE_SVR4

AC_OUTPUT(\
	Makefile \
	config/Makefile \
	src/Makefile \
	src/IPC/Makefile \
	src/cxs/Makefile \
	src/cxb/Makefile \
	src/AplusGUI/Makefile \
	src/cxsys/Makefile \
	src/cxc/Makefile \
	src/esf/Makefile \
	src/a/Makefile \
	src/app-defaults/Makefile \
	src/dap/Makefile \
	src/MSGUI/Makefile \
	src/MSIPC/Makefile \
	src/MSTypes/Makefile \
	src/main/Makefile \
	src/lisp.0/Makefile \
	src/fonts/Makefile \
	src/fonts/TrueType/Makefile \
	src/fonts/X11/Makefile \
	src/fonts/X11/bdf/Makefile \
	src/fonts/X11/pcf/Makefile \
        src/contrib/Makefile \
        src/scripts/Makefile \
        src/lisp.1/Makefile )

