# 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
AC_CANONICAL_SYSTEM 
AC_ARG_PROGRAM

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

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
libtool_enable_static=no
KDE_PROG_LIBTOOL

dnl find out some variables (not supported yet)
AC_AIX
AC_MINIX

dnl for NLS support. Call them in this order!
dnl WITH_NLS is for the po files, GNU_GETTEXT for the sources
AC_LANG_CPLUSPLUS
AM_KDE_WITH_NLS
AM_KDE_GNU_GETTEXT  

dnl Checks for header files.
AC_LANG_CPLUSPLUS
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h sys/time.h unistd.h sys/cdefs.h fnmatch.h sysent.h strings.h sys/stat.h sys/select.h)

dnl Checks for libraries.
AC_CHECK_LIB(socket, socket, [LIBSOCKET="-lsocket -lnsl"]) dnl for Solaris
AC_PATH_KDE
AC_CHECK_LIB(compat, main, [LIBCOMPAT="-lcompat"]) dnl for FreeBSD
AC_FIND_GIF
AC_FIND_JPEG

# configure would do this very late. Too late for us!
test "x$prefix" = xNONE && prefix=$ac_default_prefix
# Let make expand exec_prefix.
test "x$exec_prefix" = xNONE && exec_prefix='$(prefix)' 

AC_DEFINE_UNQUOTED(KDEDIR, "$prefix")

AC_DEFUN(AC_DEFINE_PATH,
[
  eval "tempdir=`echo "$2" | sed -e 's/\$(exec_prefix)/\$exec_prefix/' -e 's/\$(prefix)/\$prefix/'`"
  dnl I have to do this twice, since exec_prefix may be "$(prefix)"
  eval "tempdir=`echo "$tempdir" | sed -e 's/\$(prefix)/\$prefix/'`"
  AC_DEFINE_UNQUOTED($1, "$tempdir")
])

AC_DEFINE_PATH(KDE_HTMLDIR, $kde_htmldir)
AC_DEFINE_PATH(KDE_APPSDIR, $kde_appsdir)
AC_DEFINE_PATH(KDE_ICONDIR, $kde_icondir)
AC_DEFINE_PATH(KDE_MINIDIR, $kde_minidir)
AC_DEFINE_PATH(KDE_DATADIR, $kde_datadir)
AC_DEFINE_PATH(KDE_LOCALE, $kde_locale)
AC_DEFINE_PATH(KDE_CGIDIR, $kde_cgidir)
AC_DEFINE_PATH(KDE_MIMEDIR, $kde_mimedir)
AC_DEFINE_PATH(KDE_TOOLBARDIR, $kde_toolbardir)
AC_DEFINE_PATH(KDE_WALLPAPERDIR, $kde_wallpaperdir)
AC_DEFINE_PATH(KDE_BINDIR, $kde_bindir)
AC_DEFINE_PATH(KDE_PARTSDIR, $kde_partsdir)

ac_cpp_safe=$ac_cpp
ac_cpp='$CXXCPP $CPPFLAGS $X_INCLUDES'
AC_CHECK_HEADERS(X11/extensions/shape.h)
ac_cpp=$ac_cpp_safe

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

dnl check if the compiler has bool
AC_CHECK_BOOL
AC_CHECK_GNU_EXTENSIONS

dnl Checks for library functions. 
AC_CHECK_FUNCS(socket vsnprintf)
AC_CHECK_USLEEP
AC_CHECK_SETENV
AC_CHECK_GETDOMAINNAME
AC_CHECK_KSIZE_T

dnl Perform program name transformation
AC_ARG_PROGRAM

dnl output files
topdir=`pwd`
AC_SUBST(x_includes)
AC_SUBST(x_libraries)
AC_SUBST(topdir)
AC_SUBST(LIBSOCKET)
AC_SUBST(LIBCOMPAT)

AC_OUTPUT(Makefile kdecore/Makefile kdeui/Makefile khtmlw/Makefile kdetest/Makefile kdedoc/Makefile jscript/Makefile kfmlib/Makefile mediatool/Makefile po/Makefile doc/Makefile)
