# Original Author was Kalle@kde.org
# I lifted it in some mater. (Stephan Kulow)
# I used much code from Janos Farkas

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

AC_INIT(acinclude.m4) dnl a source file from your sub dir
dnl AC_MSG_WARN("This Code is alpha. It may not even compile.  Use at your own risk.")
AC_CANONICAL_SYSTEM 
AC_ARG_PROGRAM

dnl Automake doc recommends to do this only here. (Janos)
AM_INIT_AUTOMAKE(kdegames, 0.1) dnl searches for some needed programs

dnl make $KDEDIR the default for the installation
AC_PREFIX_DEFAULT(${KDEDIR:-/usr/local/kde})

dnl generate the config header
AM_CONFIG_HEADER(config.h) dnl at the distribution this done

dnl Checks for programs.
AC_CHECK_COMPILERS
KDE_PROG_LIBTOOL

dnl for NLS support. Call them in this order!
dnl WITH_NLS is for the po files
AM_KDE_WITH_NLS

dnl I need to check for libsocket before testing X
AC_CHECK_LIB(socket, socket, [LIBSOCKET="-lsocket -lnsl"]) dnl for Solaris
AC_SUBST(LIBSOCKET)
AC_PATH_KDE

AC_LANG_CPLUSPLUS
dnl Checks for libraries. 
AC_CHECK_LIB(compat, main, [LIBCOMPAT="-lcompat"]) dnl for FreeBSD
AC_SUBST(LIBCOMPAT)
AC_CHECK_LIB(crypt, main, [LIBCRYPT="-lcrypt"]) dnl for BSD
AC_SUBST(LIBCRYPT)
LIBKHTMLW="-lkhtmlw -ljscript" dnl this is somewhat historical, since jscript is ways needed
AC_SUBST(LIBKHTMLW)

AC_FIND_JPEG

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h sys/time.h unistd.h)
AC_CHECK_FUNCS(usleep)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_TIME

dnl check if the compiler has bool
AC_CHECK_BOOL

dnl Checks for library functions. MISCOBJS is for kdecore
AC_LANG_CPLUSPLUS
AC_CHECK_KSIZE_T
AC_CHECK_SETENV
KDE_ADD_INCLUDES

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

dnl Perform program name transformation
AC_ARG_PROGRAM


if test ! -s ./inst-apps && test -s ./SUBDIRS; then
 cp ./SUBDIRS ./inst-apps
fi

DO_NOT_COMPILE="$DO_NOT_COMPILE CVS debian"

if test ! -s ./inst-apps; then
  TOPSUBDIRS=""
# this needs a good find. But only developers should need this case, since
# distribution comes with SUBDIRS
  files=`ls -1`
  dirs=`for i in $files; do if test -d $i; then echo $i; fi; done`
  for i in $dirs; do 
    echo $i >> ./SUBDIRS
  done
  cp ./SUBDIRS ./inst-apps
fi    

if test -s ./inst-apps; then
  ac_topsubdirs="`cat ./inst-apps`"
fi  

for i in $ac_topsubdirs; do
  AC_MSG_CHECKING([if $i should be compiled])
  install_it="yes"
  for j in $DO_NOT_COMPILE; do 
    if test $i = $j; then
      install_it="no"
    fi
  done
  AC_MSG_RESULT($install_it)
  if test $install_it = "yes"; then 
    TOPSUBDIRS="$TOPSUBDIRS $i"
  fi
done

AC_SUBST(TOPSUBDIRS)

ac_output=`find $TOPSUBDIRS -name Makefile.in -print | sed -e 's/.in$//;' | sort`
AC_OUTPUT($ac_output Makefile)

