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

AC_INIT(aclocal.m4)
AC_CONFIG_HEADER(config.h)

dnl Check for optional features.
AC_ARG_ENABLE(debug, [  --enable-debug          turn on debugging [default=no]])
test yes = "$enable_debug" || : ${CFLAGS=""}

dnl Checks for programs.
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AM_PROG_LIBTOOL

if test yes = "$enable_debug"; then
CFLAGS="$CFLAGS -DDEBUG"
test "$GCC" && CFLAGS="$CFLAGS -Wall"
else
test "$GCC" && : ${CFLAGS:="-pipe -Wall -O2"}
fi

dnl I should use AC_TRY_COMPILE here, but it does not work.
my_CPPFLAGS=$CPPFLAGS
CPPFLAGS="$CPPFLAGS -pthread"
AC_CACHE_CHECK(whether $CC accepts -pthread, ac_cv_prog_cc_pthread,
AC_TRY_CPP(, ac_cv_prog_cc_pthread=yes, ac_cv_prog_cc_pthread=no))
CPPFLAGS=$my_CPPFLAGS

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

dnl Checks for library functions.
AC_CHECK_FUNCS(getcwd)

dnl Checks for libraries.
if test $ac_cv_prog_cc_pthread = yes; then
CFLAGS="$CFLAGS -pthread" LDFLAGS="$LDFLAGS -pthread"
else
AC_CHECK_LIB(pthread, pthread_create, PTHREAD=-lpthread)
if test $ac_cv_lib_pthread_pthread_create = no; then
AC_CHECK_LIB(pthreads, pthread_create, PTHREAD=-lpthreads)
fi
fi
AC_SUBST(PTHREAD)

AC_CHECK_LIB(socket, socket)
AC_CHECK_LIB(c, gethostbyname, :)
if test $ac_cv_lib_c_gethostbyname = no; then
AC_CHECK_LIB(nsl, gethostbyname)
fi

AC_CHECK_LIB(dl, dlopen)
AC_CHECK_LIB(Foundation, NSLog,,, -lobjc -lm $PTHREAD)
if test $ac_cv_lib_Foundation_NSLog = no; then
AC_CHECK_LIB(gnustep-base, NSLog,,, -lobjc -lm $PTHREAD)
fi

AC_OUTPUT(GToolKit/Makefile Examples/Makefile
	  Examples/calc/Makefile Examples/p/Makefile)
