AC_INIT(gsearchtool)
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(gnome-utils, 2.8.1)

AM_MAINTAINER_MODE

AC_PROG_INTLTOOL([0.29])

AC_ISC_POSIX
AC_PROG_CXX
AC_PROG_CC
AC_PROG_CPP
AC_STDC_HEADERS
AC_PROG_YACC
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET

GNOME_COMPILE_WARNINGS

AC_PATH_XTRA

dnl *****************************************
dnl pkg-config check time
dnl *****************************************

GTK_REQUIRED=2.3.2
LIBGNOME_DESKTOP_REQUIRED=2.2.0
LIBGNOME_REQUIRED=2.5.0
LIBGNOMEUI_REQUIRED=2.5.0
LIBGLADE_REQUIRED=2.3.0
LIBBONOBOUI_REQUIRED=2.1.0
GNOMEVFS_REQUIRED=2.3.0
LIBPANEL_APPLET_REQUIRED=2.3.0

dnl *****************************************
dnl libgnome, libgnomeui needed for all utils
dnl *****************************************

PKG_CHECK_MODULES(GNOME_UTILS, gtk+-2.0 >= $GTK_REQUIRED libgnome-2.0 >= $LIBGNOME_REQUIRED libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED)
AC_SUBST(GNOME_UTILS_CFLAGS)
AC_SUBST(GNOME_UTILS_LIBS)

dnl *****************************************
dnl floppy-buddy needs libglade
dnl *****************************************
PKG_CHECK_MODULES(LIBGLADE, libglade-2.0 >= $LIBGLADE_REQUIRED)
AC_SUBST(LIBGLADE_CFLAGS)
AC_SUBST(LIBGLADE_LIBS)

dnl *****************************
dnl popt is needed for most utils
dnl *****************************

AC_CHECK_LIB(popt, poptHelpOptions,, AC_MSG_ERROR([popt is required to build gnome-utils. You can download the latest version from ftp://people.redhat.com/sopwith/popt/]))

dnl *********************************************
dnl gnome-vfs/mime-data is need for gsearchtool
dnl *********************************************

PKG_CHECK_MODULES(GNOMEVFS, gnome-vfs-2.0 >= $GNOMEVFS_REQUIRED gnome-vfs-module-2.0 >= $GNOMEVFS_REQUIRED)
AC_SUBST(GNOMEVFS_CFLAGS)
AC_SUBST(GNOMEVFS_LIBS)

dnl *********************************************
dnl gnome-desktop is need for gsearchtool
dnl *********************************************

PKG_CHECK_MODULES(GNOMEDESKTOP, gnome-desktop-2.0 >= $LIBGNOME_DESKTOP_REQUIRED)
AC_SUBST(GNOMEDESKTOP_CFLAGS)
AC_SUBST(GNOMEDESKTOP_LIBS)

dnl *********************************************
dnl for anything which calls gconftool-2 correctly
dnl *********************************************


AC_PATH_PROG(GCONFTOOL, gconftool-2, no)

if test x"$GCONFTOOL" = xno; then
  AC_MSG_ERROR([gconftool-2 executable not found in your path - should be installed with GConf])
fi

AM_GCONF_SOURCE_2


dnl *******************************
dnl Applet checks
dnl *******************************

PKG_CHECK_MODULES(APPLET, libpanelapplet-2.0 >= $LIBPANEL_APPLET_REQUIRED)
AC_SUBST(APPLET_LIBS)
AC_SUBST(APPLET_CFLAGS)

dnl ***************************************************************
dnl Other miscellaneous checks 
dnl ***************************************************************

AC_ARG_ENABLE(console-helper,
  [  --enable-console-helper=[no/yes]  	Enable PAM console helper [ default=no ]],,
  enable_console_helper=no)

dnl ***********
dnl PAM prefix
dnl ***********

dnl  ***************Checking for availability of IPv6************ 
AC_MSG_CHECKING([whether to enable IPv6])
AC_ARG_ENABLE(ipv6,
  [ --enable-ipv6=[yes/no] enables compilation of IPv6 code]
   , ,enable_ipv6=yes)
if test $enable_ipv6 = yes; then
  AC_TRY_COMPILE([
   #include <sys/socket.h>
   #include <sys/types.h>], [
   struct sockaddr_storage ss;
   socket(AF_INET6, SOCK_STREAM, 0)
   ],
   have_ipv6=yes,
   have_ipv6=no
  )
fi

if test $have_ipv6 = yes; then
  have_getaddrinfo=no
  AC_CHECK_FUNC(getaddrinfo, have_getaddrinfo=yes)
  if test $have_getaddrinfo != yes; then
    for lib in bsd socket inet; do
      AC_CHECK_LIB($lib,getaddrinfo,["LIBS=$LIBS -l$lib";have_getaddrinfo=yes;break])
    done
  fi

  if test $have_getaddrinfo = yes; then
    AC_DEFINE(ENABLE_IPV6)
  fi
fi

dnl  ************************end IPv6 checks*********************

withval=""
AC_ARG_WITH(pam-prefix,
[      --with-pam-prefix=<prefix>   specify where pam files go],[
if test x$withval != x; then
   AC_MSG_RESULT("PAM files will be installed in prefix ${withval}.")
fi])
if test x$withval != x; then
	PAM_PREFIX_UNEXPANDED="$withval"
	PAM_PREFIX=`eval echo $PAM_PREFIX_UNEXPANDED`
else
	PAM_PREFIX="\$(sysconfdir)"
fi
AC_SUBST(PAM_PREFIX)
    
AC_PATH_PROG(CONSOLE_HELPER,consolehelper,no)
if test "x$CONSOLE_HELPER" = "xno" -a "x$enable_console_helper" = "xyes" ; then
	AC_MSG_ERROR(Console helper requested but consolehelper binary not found)
fi

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

AC_C_CONST
AC_C_INLINE
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_STRUCT_ST_RDEV
AC_HEADER_TIME
AC_STRUCT_TM
AC_TYPE_UID_T

dnl *****************************
dnl Checks for library functions.
dnl *****************************

AC_FUNC_ALLOCA
AC_FUNC_MMAP
AC_TYPE_SIGNAL
AC_FUNC_STRFTIME
AC_CHECK_FUNCS(getcwd gettimeofday getwd putenv strdup strtoul uname logf)

dnl *****************************************************************
dnl Allow users to run logview using the console helper 
dnl PAM stuff.
dnl *****************************************************************

if test "x$enable_console_helper" = "xyes"; then
  AM_CONDITIONAL(CONSOLE_HELPER, true)
else
  AM_CONDITIONAL(CONSOLE_HELPER, false)
fi

dnl ************************************************
dnl X development libraries check
dnl ************************************************

if $PKG_CONFIG --exists pangoxft ; then
  PANGO_PACKAGES="pangox pangoxft"
else
  PANGO_PACKAGES="pangox"
fi

x_libs="`$PKG_CONFIG --libs $PANGO_PACKAGES`"
case x_libs in
  *-lX11*) pango_omitted_x_deps=no ;;
  *)       pango_omitted_x_deps=yes ;;
esac

if test $pango_omitted_x_deps = yes ; then
  AC_PATH_XTRA

  if test x$no_x = xyes ; then
    AC_MSG_ERROR([X development libraries not found])
  else
    X_LIBS="$X_PRE_LIBS $X_LIBS -lX11 $X_EXTRA_LIBS"
  fi
fi

AC_SUBST(X_LIBS)

dnl strftime extension checks

AC_TRY_RUN([#include <time.h>
                int main ()
                {
                  char buf[100];
                  struct tm tm = {0};
                  tm.tm_year = 99;
                  if (strftime(buf, 100, "%EY", &tm) == 4 &&
		      strcmp (buf, "1999")==0)
                    return 0;
                  return 1;
                }
            ],
	    AC_DEFINE(HAVE_STRFTIME_EXTENSION, 1, [Define if strftime supports %E and %O modifiers.])
            )

dnl *************************************************
dnl Individual gnome-utils checks 
dnl *************************************************


dnl ******************** 
dnl gfloppy checks
dnl ********************

build_gfloppy=true
AC_CHECK_HEADER(linux/fd.h, AC_DEFINE(HAVE_LINUX_FD_H),
		build_gfloppy=false
                AC_MSG_WARN([*** gfloppy will not be built.]))
# Check for the ext2fs library
AC_CHECK_LIB(ext2fs, ext2fs_mkdir, x_libs="-lext2fs",
  build_gfloppy=false
  AC_MSG_WARN([
*** libext2fs not found. You need e2fsprogs and e2fsprogs-devel installed to build gfloppy.]))
# check for ext2fs header specific includes
AC_CHECK_HEADERS([et/com_err.h])
AC_CHECK_HEADER([ext2fs/ext2_io.h], [],
  [build_gfloppy=false
  AC_MSG_WARN([
*** ext2fs/ext2_io.h not found.  You need e2fsprogs-devel installed.])],
  [#include <string.h>
#if HAVE_ET_COM_ERR_H
#include <et/com_err.h>
#endif
])
AM_CONDITIONAL(BUILD_GFLOPPY, test "$build_gfloppy" = true)


dnl ********************
dnl logview checks
dnl ********************

dnl This is where the binary actually resides,
dnl not the console helper link
if test "x$enable_console_helper" = "xyes"; then
	LOGVIEWDIR_TMP="$sbindir"
else
	LOGVIEWDIR_TMP="$bindir"
fi
EXPANDED_LOGVIEWDIR=`eval echo $LOGVIEWDIR_TMP`
AC_SUBST(EXPANDED_LOGVIEWDIR)


dnl ********************
dnl scrollkeeper checks 
dnl ********************

AC_PATH_PROG(SCROLLKEEPER_CONFIG, scrollkeeper-config,no)
if test x$SCROLLKEEPER_CONFIG = xno; then
  AC_MSG_ERROR(Couldn't find scrollkeeper-config. Please install the scrollkeeper package)
fi


dnl *******************************
dnl Internationalization
dnl ******************************* 

ALL_LINGUAS="am ar az be bg bn bs ca cs cy da de el en_CA en_GB es et eu fa fi fr ga gl gu he hi hr hu id it ja ko lt lv mk ml mn ms nb ne nl nn no pa pl pt pt_BR ro ru sk sl sq sr sr@Latn sv ta th tr uk vi wa zh_CN zh_TW"
GETTEXT_PACKAGE=gnome-utils-2.0
AC_SUBST(GETTEXT_PACKAGE)
AM_GLIB_GNU_GETTEXT

# AM_GLIB_GNU_GETTEXT above substs $DATADIRNAME
# this is the directory where the *.{mo,gmo} files are installed
gnomeutilslocaledir='${prefix}/${DATADIRNAME}/locale'
AC_SUBST(gnomeutilslocaledir)

AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE")

AC_DEFINE_UNQUOTED(GNOME_ICONDIR, "${prefix}/share/pixmaps")

AC_OUTPUT([
Makefile
gnome-utils.spec
po/Makefile.in
logview/Makefile
logview/gnome-system-log-security
logview/help/Makefile
logview/help/C/Makefile
logview/help/de/Makefile
logview/help/es/Makefile
logview/help/fr/Makefile
logview/help/it/Makefile
logview/help/sv/Makefile
logview/help/ja/Makefile
logview/help/ko/Makefile
logview/help/zh_CN/Makefile
logview/help/zh_TW/Makefile
gsearchtool/Makefile
gsearchtool/help/Makefile
gsearchtool/help/C/Makefile
gsearchtool/help/es/Makefile
gsearchtool/help/fr/Makefile
gsearchtool/help/it/Makefile
gsearchtool/help/sv/Makefile
gsearchtool/help/ja/Makefile
gsearchtool/help/ko/Makefile
gsearchtool/help/zh_CN/Makefile
gsearchtool/help/zh_HK/Makefile
gsearchtool/help/zh_TW/Makefile
gdictsrc/Makefile
gdictsrc/help/Makefile
gdictsrc/help/C/Makefile
gdictsrc/help/ja/Makefile
gfloppy/Makefile
gfloppy/doc/Makefile
gfloppy/doc/C/Makefile
gfloppy/doc/ja/Makefile
gfloppy/src/Makefile
])

dnl <= Configuration summary =>

echo ""
echo "gnome-utils configuration summary:"
echo "=================================="
echo ""

dnl <= CFLAGS and LDFLAGS =>
echo "CFLAGS : $CFLAGS"
echo "LDFLAGS : $LDFLAGS"
echo "X_LIBS : $X_LIBS"
echo ""

dnl <= Prefixes =>
echo "prefix : $prefix"
echo "sysconf dir : "`eval echo $sysconfdir`
echo "bin dir : "`eval echo $bindir`
echo "sbin dir : "`eval echo $sbindir`
echo "PAM prefix : $PAM_PREFIX"
echo "data dir : "`eval echo $datadir`
echo ""

echo ""
echo "The following will be built -"
echo "============================="
echo ""
dnl <= Console Helper =>
if test "x$enable_console_helper" = "xyes"; then
	echo "Console helper (logview)          : YES"
else
	echo "Console helper (logview)          : NO"
fi

dnl <= message file =>
echo "Logview default message file      : $messages_file"

dnl <= gfloppy =>
if test "x$build_gfloppy" = "xtrue"; then
	echo "Build gfloppy                     : YES"
else
	echo "Build gfloppy                     : NO"
fi

echo ""
dnl <= End of configuration summary =>
