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

AC_INIT(twkalc/kcalc.h)

dnl where to find stuff needed by 'configure'
AC_CONFIG_AUX_DIR(admin)
	
dnl set this package name and version
PACKAGE=[$1]
AC_SUBST(PACKAGE)
VERSION=[$2]
AC_SUBST(VERSION)

AC_CANONICAL_SYSTEM

dnl create config.h
AM_CONFIG_HEADER(config.h)

dnl set language for tests: C
AC_LANG_C

dnl Checks for C, C++, make, install and other needed programs.
AC_PROG_CC
AC_PROG_CXX
AC_PROG_MAKE_SET
AC_PROG_INSTALL

dnl FIXME This is truly gross.
missing_dir=`cd $ac_aux_dir && pwd`
AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)

dnl Checks for header files.
AC_ARG_PROGRAM
AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h)

AC_CHECK_HEADERS(Tw/Tw.h)
if test "$ac_cv_header_Tw_Tw_h" = "no"; then
  AC_MSG_ERROR([your system is missing Tw/Tw.h header!
Check, if you installed the libTw header files correctly.])
fi

AC_CHECK_HEADERS(Tw/Tw++.h)
if test "$ac_cv_header_Tw_Twpp_h" = "no"; then
  AC_MSG_ERROR([your system is missing Tw/Tw++.h header!
Check, if you installed the libTw header files correctly.])
fi


dnl Checks for libraries.

AC_CHECK_LIB(Tw, Tw_Open)
if test "$ac_cv_lib_Tw_Tw_Open" = "no"; then
  AC_MSG_ERROR([your system fails linking a small libTw application!
Check, if your compiler is installed correctly and if you have used the
same compiler to compile libTw as you did use now])
fi

AC_CHECK_LIB(m, sqrt)
AC_CHECK_LIB(m, isinf, [
AC_DEFINE_UNQUOTED(HAVE_FUNC_ISINF)
])



dnl Checks for typedefs, structures, and compiler characteristics.
dnl do not check for `const' and `inline', they are standard in C++
dnl AC_C_CONST
dnl AC_C_INLINE



AC_DEFUN(AC_my_C_LONG_DOUBLE,
[AC_CACHE_CHECK(for long double, ac_cv_c_long_double,
[AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main() {
/* The Stardent Vistra knows sizeof(long double), but does not support it.  */
long double foo = 1.0;
char buffer[10];
/* On Ultrix 4.3 cc, long double is 4 and double is 8.  */
int result = (sizeof(long double) < sizeof(double));
/* the following is needed for a broken printf in glibc2 */
if (!result) {
    foo = foo * 3;
    sprintf(buffer,"%0.0Lf",foo);
    result = strcmp(buffer, "3");
/* and now something mean ;-) */
    foo = fabsl(foo);
}
exit(result); }],
ac_cv_c_long_double=yes, ac_cv_c_long_double=no)
])

if test $ac_cv_c_long_double = yes; then
  AC_DEFINE(HAVE_LONG_DOUBLE)
fi
])
AC_my_C_LONG_DOUBLE


AC_DEFUN(AC_my_C_BOOL,
[
	AC_MSG_CHECKING([for bool])
        AC_CACHE_VAL(ac_cv_have_bool,
        [
		AC_LANG_CPLUSPLUS
          	AC_TRY_COMPILE([],
                 [bool aBool = true;],
                 [ac_cv_have_bool="yes"],
                 [ac_cv_have_bool="no"])
        ]) dnl end AC_CHECK_VAL
        AC_MSG_RESULT($ac_cv_have_bool)
        if test "$ac_cv_have_bool" = "yes"; then
        	AC_DEFINE(HAVE_BOOL) 
        fi 
])
AC_my_C_BOOL


dnl output files
topdir=`pwd`
AC_SUBST(topdir)

AC_OUTPUT(Makefile admin/Makefile twkalc/Makefile)

