dnl 
dnl configure.in for gnome-utils, process with autoconf >= 2.13
dnl

AC_INIT(gtt)

dnl
dnl Due to the sed scripts being split on 90 line
dnl blocks, this macro needs to be right at the beggining.
dnl
AM_PROG_XML_I18N_TOOLS

dnl
dnl a start of some nicer configure.in stuff
dnl
GDK_PIXBUF_REQUIRED=0.7.0
GCONF_REQUIRED=0.12
OAF_REQUIRED=0.6.5


AM_CONFIG_HEADER(config.h)
AC_CANONICAL_SYSTEM

AM_INIT_AUTOMAKE(gnome-utils, 1.4.1.1)

dnl 
dnl only useful for maintainers
dnl
AM_MAINTAINER_MODE

AM_ACLOCAL_INCLUDE(macros)

# find the actual value for $prefix that we'll end up with
REAL_PREFIX=
if test "x$prefix" = "xNONE"; then
  REAL_PREFIX=$ac_default_prefix
else
  REAL_PREFIX=$prefix
fi
old_prefix=$prefix
prefix=$REAL_PREFIX

REAL_EXEC_PREFIX=
if test "x$exec_prefix" = "xNONE"; then
  REAL_EXEC_PREFIX=$prefix
else
  REAL_EXEC_PREFIX=$exec_prefix
fi
old_exec_prefix=$exec_prefix
exec_prefix=$REAL_EXEC_PREFIX


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

dnl 
dnl  Test whether jw is installed
dnl
AC_PATH_PROG(JW,jw,no)
if test x$JW = xno; then
  HAVE_JW="no"
else
  HAVE_JW="yes"
fi
AM_CONDITIONAL(HAVE_JW, test "x$HAVE_JW" = "xyes")
AC_SUBST(HAVE_JW)

dnl
dnl PAM prefix
dnl
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

GNOME_INIT(applets)

AC_ISC_POSIX
AC_PROG_CXX
AC_PROG_CC
AC_PROG_CPP
AC_STDC_HEADERS
AC_ARG_PROGRAM
dnl AM_PROG_LIBTOOL
AM_PROG_LEX
AC_PROG_YACC
dnl AC_DECL_YYTEXT
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
GNOME_COMPILE_WARNINGS

GNOME_X_CHECKS

# so that people on places like solaris can set where the rgb.txt file is
XLIBDIR=$x_libraries
if test x$XLIBDIR = xNONE ; then
	XLIBDIR="/usr/X11R6/lib/"
fi
AC_SUBST(XLIBDIR)

dnl Check for new enough gnome-libs
CFLAGS_save=$CFLAGS
LIBS_save=$LIBS
CFLAGS=`gnome-config --cflags gnomeui`
LIBS=`gnome-config --libs gnomeui`

AC_CHECK_LIB(gnomeui, gnome_window_icon_set_default_from_file, ,[
AC_MSG_ERROR(gnome-libs 1.0.59 or higher is required.)])

CFLAGS=$CFLAGS_save
LIBS=$LIBS_save

dnl PROGRAMS_GNCAL="gncal"
dnl AC_SUBST(PROGRAMS_GNCAL)

GNOME_CHECK_OBJC
if test "$OBJECTIVE_C" = yes; then
  GNOME_INIT_OBJC
fi

dnl Checks for typedefs, structures, and compiler characteristics.
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 Checks for library functions.
AC_FUNC_ALLOCA
AC_FUNC_MMAP
AC_TYPE_SIGNAL
AC_FUNC_STRFTIME
AC_CHECK_FUNCS(getcwd gettimeofday getwd putenv strdup strtoul uname)

dnl nl_langinfo used for printing i18n time string formats
dnl check for nl_langinfo(D_FMT) which is missing on FreeBSD
LANGINFO_D_FMT_CHECK

dnl Allow users to run logview and gshutdown using the console helper 
dnl PAM stuff.
if test "x$enable_console_helper" = "xyes"; then
  AM_CONDITIONAL(CONSOLE_HELPER, true)
else
  AM_CONDITIONAL(CONSOLE_HELPER, false)
fi

dnl
dnl GdkPixBuf
dnl
AC_MSG_CHECKING(for GdkPixbuf library >= $GDK_PIXBUF_REQUIRED)
PIXBUF_CFLAGS=`$GNOME_CONFIG --cflags gdk_pixbuf`
PIXBUF_LIBS=`$GNOME_CONFIG --libs gdk_pixbuf`
if test "x$PIXBUF_CFLAGS" != x ; then
    vers=`gdk-pixbuf-config --version | awk 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
    if test "$vers" -ge 0007000; then
        AC_MSG_RESULT(found)
    else
       AC_MSG_ERROR(You need at least GdkPixbuf version 0.7.0 for gnome-utils)
    fi
else
    AC_MSG_ERROR(Did not find GdkPixbuf installed)
fi
AC_SUBST(PIXBUF_CFLAGS)
AC_SUBST(PIXBUF_LIBS)
AC_SUBST(GDK_PIXBUF_REQUIRED)

dnl *******************************
dnl Internationalization
dnl ******************************* 
ALL_LINGUAS="az ca cs da de el en_GB es et fi fr ga gl hu it ja ko lt lv nl nn no pl pt pt_BR ro ru sk sl sv ta tr uk wa zh_TW zh_CN.GB2312"
AM_GNOME_GETTEXT

dnl *******************************
dnl Guile checks
dnl *******************************
GNOME_CHECK_GUILE

dnl *******************************
dnl gnome-print checks
dnl *******************************
if test "x$enable_gnome_print" = "xyes"; then
  AM_PATH_GNOME_PRINT(0.12.0)
  AC_DEFINE(HAVE_GNOME_PRINT)
fi

build_gtt=true

dnl *******************************
dnl LibGlade
dnl glade is needed to build gtt
dnl *******************************
AC_MSG_CHECKING(for Glade libraries >= 0.11)
if gnome-config --libs libglade > /dev/null 2>&1; then
    vers=`gnome-config --modversion libglade | awk 'BEGIN { FS = "."; } { print $1 * 1000 + $2;}'`
    if test "$vers" -ge 11; then
        AC_MSG_RESULT(found)
    else
	AC_MSG_ERROR(You need at least libglade 0.11 for this version of gnome-utils)
    fi
else
    AC_MSG_ERROR(Did not find libGlade installed)
fi
GLADE_LIBS=`gnome-config --libs libglade`
GLADE_CFLAGS=`gnome-config --cflags libglade`
AC_SUBST(GLADE_LIBS)
AC_SUBST(GLADE_CFLAGS)

dnl *******************************
dnl gtkhtml
dnl gtkhtml is needed to build gtt
dnl *******************************
GTKHTML_LIBS=`$GNOME_CONFIG --libs gtkhtml`
GTKHTML_CFLAGS=`$GNOME_CONFIG --cflags gtkhtml`

AC_MSG_CHECKING(for GtkHTML)
if gnome-config --libs gtkhtml > /dev/null 2>&1; then
    AC_MSG_RESULT(found)
else
    AC_MSG_WARN([Cannot find gtkhtml. See config.log for more info.])
    AC_MSG_WARN([*** gtt will not be built.])
    build_gtt=false
fi

# check for gtkhtml and enable it via HAVE_LIBGTKHTML
# if found
# AC_CHECK_LIB(gtkhtml, gtk_html_new,
#             GNOMEBUILDLIBS="${GNOMEBUILDLIBS} gtkhtml"
#             AC_DEFINE(HAVE_LIBGTKHTML),
#             AC_MSG_WARN([Cannot find gtkhtml. See config.log for more info.])
#	     AC_MSG_WARN([*** gtt will not be built.]),
#             $GTKHTML_LIBS)

AC_SUBST(GTKHTML_LIBS)
AC_SUBST(GTKHTML_CFLAGS)

dnl *******************************
dnl sched.h
dnl sched.h is needed to build gtt
dnl *******************************

AC_CHECK_HEADER(sched.h,,build_gtt=false
                AC_MSG_WARN([*** gtt will not be built.]))

AM_CONDITIONAL(BUILD_GTT, test "$build_gtt" = true)

dnl ******************** 
dnl libxml
dnl The gnome-xml library is required to build the stripchart and 
dnl gtt programs.
dnl ********************

GNOME_XML_CHECK
AM_CONDITIONAL(HAVE_LIBXML, test "x$GNOME_XML_LIB" != "x")
AC_SUBST(HAVE_LIBXML)

dnl ******************** 
dnl gfloppy
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_HEADER(ext2fs/ext2_io.h, ,
  build_gfloppy=false
  AC_MSG_WARN([
*** ext2fs/ext2_io.h not found.  You need e2fsprogs-devel installed.]))
AM_CONDITIONAL(BUILD_GFLOPPY, test "$build_gfloppy" = true)

dnl ********************
dnl logview
dnl ********************
withval=""

AC_ARG_WITH(messages,
[      --with-messages=<filename>   specify messages log file],[
if test x$withval != x; then
   AC_MSG_RESULT("Setting messages logfile as specified $withval.")
   AC_DEFINE_UNQUOTED(PATH_MESSAGES, "$withval")
fi])

messages_file="$withval"

if test x$withval = x; then
AC_MSG_CHECKING([for /var/adm/messages])
if test -f /var/adm/messages; then
  AC_MSG_RESULT([found])
  AC_DEFINE(PATH_MESSAGES, "/var/adm/messages")
  messages_file="/var/adm/messages"
else
  AC_MSG_RESULT([not found])
  AC_MSG_CHECKING([for /var/log/messages])
  if test -f /var/log/messages; then
    AC_MSG_RESULT([found])
    AC_DEFINE(PATH_MESSAGES, "/var/log/messages")
    messages_file="/var/log/messages"
  else
    AC_MSG_RESULT([not found])
    AC_MSG_ERROR([Cannot find messages log file, you should specify one in --wit
h-messages=<filename>.])
  fi
fi
fi

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 gshutdown
dnl ********************

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

dnl ******************** 
dnl gsu
dnl ********************
AC_CHECK_LIB(pam, pam_authenticate, [
	AC_DEFINE(USE_PAM)
	AC_CHECK_LIB(pam_misc, pam_misc_setenv,
	[PAM_LIBS="-ldl -lpam -lpam_misc"], [PAM_LIBS="-ldl -lpam"],
	-ldl -lpam)
], [PAM_LIBS=], -ldl)
AC_SUBST(PAM_LIBS)

AC_CHECK_FUNCS(endgrent endpwent)
dnl ********************
dnl idetool
dnl ********************
mu_idetool=
AC_CHECK_HEADERS(linux/hdreg.h,[mu_idetool=idetool])
AM_CONDITIONAL(MU_IDETOOL,test "$mu_idetool" = idetool)

dnl Needed on SysV for shadow passwords.
AC_CHECK_LIB(sec, main)

dnl Needed on Linux for shadow passwords.
AC_CHECK_LIB(shadow, main)

AC_EGREP_HEADER(sp_pwdp, shadow.h,
		AC_CHECK_FUNC(getspnam, AC_DEFINE(HAVE_SHADOW_H)))

AC_CHECK_FUNCS(crypt)
if test $ac_cv_func_crypt = no; then
  # SCO-ODT-3.0 is reported to need this library for crypt.
  AC_CHECK_LIB(ufc, crypt, LIBS="$LIBS -lufc",
    [# NetBSD needs this library for crypt.
    AC_CHECK_LIB(crypt, crypt)])
fi

dnl gsu end.

dnl Some nice conditional
AM_CONDITIONAL(FALSE, test x = y)

dnl Check for libgtop
GNOME_INIT_LIBGTOP

dnl gdialog
AC_CHECK_CURSES
dnl gdialog end

AM_PATH_OAF($OAF_REQUIRED)
AC_SUBST(OAF_REQUIRED)

AM_PATH_GCONF($GCONF_REQUIRED,,,gconf-gtk)
AC_SUBST(GCONF_REQUIRED)

AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)

dnl guname
AC_ARG_ENABLE(guname-capplet,
[  --disable-guname-capplet  Use guname-capplet to build guname with control center applet support[default=yes]], enable_guname_capplet="$enableval", enable_guname_capplet=yes)

AM_CONDITIONAL(GUNAME_CAPPLET, test x$enable_guname_capplet = xno)
dnl guname end

dnl If logf() is available, stripchart will use it in preference 
dnl to the presumably slower log() function.
AC_CHECK_FUNCS(logf)

dnl If the Gnome applet libraries are available, define HAVE_GNOME_APPLET.
dnl This will allow both an applet and an application version of          
dnl stripchart and gcolorsel to be built.
AM_CONDITIONAL(HAVE_GNOME_APPLET, test "x$GNOME_APPLETS_LIBS" != "x")

if test "x$GNOME_APPLETS_LIBS" != "x"; then
  AC_ARG_ENABLE(stripchart-applet,
  [  --enable-stripchart-applet  Build a stripchart applet [default=yes]],
  enable_stripchart_applet="$enableval", enable_stripchart_applet=yes)

  AC_ARG_ENABLE(gcolorsel-applet,
  [  --enable-gcolorsel-applet  Build a gcolorsel applet [default=yes]],
  enable_gcolorsel_applet="$enableval", enable_gcolorsel_applet=yes) 
fi
AM_CONDITIONAL(BUILD_STRIPCHART_APPLET, test $enable_stripchart_applet = yes)
AM_CONDITIONAL(BUILD_GCOLORSEL_APPLET, test $enable_gcolorsel_applet = yes)

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

AC_OUTPUT([
Makefile
gnome-utils.spec
po/Makefile.in
intl/Makefile
macros/Makefile
idl/Makefile
cromagnon/Makefile
gcalc/Makefile
gcalc/doc/Makefile
gcalc/doc/C/Makefile
gcalc/doc/it/Makefile
gcalc/doc/es/Makefile
gcalc/doc/de/Makefile
gdiskfree/Makefile
gdiskfree/doc/Makefile
gdiskfree/doc/C/Makefile
gdiskfree/doc/es/Makefile
gdiskfree/doc/it/Makefile
logview/Makefile
logview/logview-security
logview/pixmaps/Makefile
logview/doc/Makefile
logview/doc/C/Makefile
gcharmap/Makefile
gcharmap/src/Makefile
gcharmap/pixmaps/Makefile
gcharmap/doc/Makefile
gcharmap/doc/C/Makefile
gsearchtool/Makefile
gsearchtool/help/Makefile
gsearchtool/help/C/Makefile
gsearchtool/help/it/Makefile
gsearchtool/help/es/Makefile
gtt/Makefile
gtt/doc/Makefile
gtt/doc/C/Makefile
gtt/doc/C/man/Makefile
gtt/doc/de/Makefile
gtt/doc/es/Makefile
gtt/glade/Makefile
gtt/ghtml/Makefile
gtt/ghtml/C/Makefile
gdialog/Makefile
gdialog/doc/Makefile
gdialog/doc/C/Makefile
splash/Makefile
stripchart/Makefile
stripchart/doc/Makefile
stripchart/doc/C/Makefile
stripchart/doc/es/Makefile
gdictsrc/Makefile
gdictsrc/doc/Makefile
gdictsrc/doc/C/Makefile
gdictsrc/doc/es/Makefile
mini-utils/Makefile
mini-utils/gless/Makefile
mini-utils/gless/doc/Makefile
mini-utils/gless/doc/C/Makefile
mini-utils/gshutdown/Makefile
mini-utils/gshutdown/gshutdown-security
mini-utils/gshutdown/doc/Makefile
mini-utils/gshutdown/doc/C/Makefile
mini-utils/gshutdown/doc/es/Makefile
mini-utils/guname/Makefile
mini-utils/guname/doc/Makefile
mini-utils/guname/doc/C/Makefile
mini-utils/gw/Makefile
mini-utils/gw/doc/Makefile
mini-utils/gw/doc/C/Makefile
mini-utils/idetool/Makefile
mini-utils/idetool/doc/Makefile
mini-utils/idetool/doc/C/Makefile
mini-utils/gfontsel/Makefile
mini-utils/gfontsel/help/Makefile
mini-utils/gfontsel/help/C/Makefile
mini-utils/gfontsel/help/es/Makefile
mini-utils/gcolorsel/Makefile
mini-utils/gcolorsel/glade/Makefile
mini-utils/gcolorsel/doc/Makefile
mini-utils/gcolorsel/doc/C/Makefile
gfloppy/Makefile
gfloppy/doc/Makefile
gfloppy/doc/C/Makefile
gfloppy/doc/es/Makefile
gfloppy/doc/ja/Makefile
gfloppy/src/Makefile
meat-grinder/Makefile
meat-grinder/help/Makefile
meat-grinder/help/C/Makefile
exe-handler/Makefile
exe-handler/help/Makefile
exe-handler/help/C/Makefile
omf-install/Makefile])

#mini-utils/gsu/Makefile
#mini-utils/gpenguin/Makefile

dnl <= Configuration summary =>

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

dnl <= CFLAGS and LDFLAGS =>
echo "CFLAGS : $CFLAGS"
echo "LDFLAGS : $LDFLAGS"
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 "X libraries dir : $XLIBDIR"
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

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

dnl <= idetool =>
if test "x$mu_idetool" = "xidetool"; then
	echo "Build idetool                     : YES"
else
	echo "Build idetool                     : NO"
fi

dnl <= guname capplet =>
if test "x$enable_guname_capplet" = "xyes"; then
	echo "guname capplet                    : YES"
else
	echo "guname capplet                    : NO"
fi

dnl <= gcolorsel applet =>
if test "x$enable_gcolorsel_applet" = "xyes"; then
	echo "gcolorsel applet                  : YES"
else
	echo "gcolorsel applet                  : NO"
fi

dnl <= stripchart applet =>
if test "x$enable_stripchart_applet" = "xyes"; then
	echo "stripchart applet                 : YES"
else
	echo "stripchart applet                 : NO"
fi

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

