dnl Process this file with autoconf to produce a configure script.
AC_INIT(configure.in)

AM_INIT_AUTOMAKE(synaptic, 0.61)
AM_CONFIG_HEADER(config.h)
AM_MAINTAINER_MODE

dnl Checks for programs.
AC_ISC_POSIX
AC_PROG_CC
AM_PROG_CC_STDC
AC_HEADER_STDC
AC_PROG_CXX
AC_PROG_MAKE_SET
AC_PROG_RANLIB

dnl i18n
ALL_LINGUAS="ar pt_BR es eu fr gl de tr zh_CN zh_TW ru nl ja be be@latin it pl cs hu sr sr@Latn da he ca ko bg no nb sl pt lt el xh mk ro hi sv fi th"
AM_GLIB_GNU_GETTEXT
GETTEXT_PACKAGE=synaptic
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE",[description])
AC_PROG_INTLTOOL([0.23])
synapticlocaledir='${prefix}/${DATADIRNAME}/locale'
AC_SUBST(synapticlocaledir)
     

dnl ask for wings
dnl AC_ARG_WITH(wings,
dnl 	[--with-wings   build with WINGs gui (obsolete)],
dnl	[AC_CHECK_PROG(WINGS, get-wings-flags, yes, no)
dnl	if test x"$WINGS" == xno; then
dnl	   AC_MSG_ERROR([WINGs is not installed])
dnl	fi
dnl	]
dnl )
dnl if test x"$WINGS" = xyes; then
dnl	BUILD_wings="wings"
dnl 	WINGS_LIBS=`get-wings-flags --ldflags`
dnl	WINGS_LIBS="$GUI_LIBS `get-wings-flags --libs`"
dnl	WINGS_HDRS=`get-wings-flags --cflags`
dnl	AC_SUBST(WINGS_LIBS)
dnl	AC_SUBST(WINGS_HDRS)
dnl fi
dnl AC_SUBST(BUILD_wings)


dnl Checks for gtk
dnl if test -z "$BUILD_wings" ; then
	pkg_modules="gtk+-2.0 >= 2.4.0, libglade-2.0 >= 2.0.0, pango >= 1.0.0, glib-2.0"
	PKG_CHECK_MODULES(PACKAGE, [$pkg_modules])
	BUILD_gtk="gtk"	
dnl fi

AC_SUBST(PACKAGE_CFLAGS)
AC_SUBST(PACKAGE_LIBS)
AC_SUBST(BUILD_gtk)

dnl if test x"$WINGS" = xno; then
if test x"$GTK" = xno; then
	AC_MSG_ERROR([ Gtk is not installed, you need to install it to get a GUI])
fi
dnl fi




dnl Check for rpm version 
dnl =====================
rpm_version="none"
AC_MSG_CHECKING(RPM version)
SAVE_LIBS="$LIBS"
SAVE_CPPFLAGS="$CPPFLAGS"

RPM_HDRS=""
LIBS="$SAVE_LIBS -lrpmio -lrpmdb -lpopt"
CPPFLAGS="$SAVE_CPPFLAGS -I/usr/include/rpm"
AC_CHECK_HEADER(rpm/rpmlib.h,
      [AC_CHECK_LIB(rpm,rpmdbInitIterator,
        [AC_DEFINE(HAVE_RPM, 1, [whether RPM is present]) 
         RPM_LIBS="-lrpm -lrpmio -lrpmdb -lpopt"
         SAVE_CPPFLAGS="$SAVE_CPPFLAGS -I/usr/include/rpm"
	 RPM_HDRS="-I/usr/include/rpm"
         rpm_version="4"])])

if test $rpm_version = "none"; then
LIBS="$SAVE_LIBS -lpopt"
CPPFLAGS="$SAVE_CPPFLAGS -I/usr/include/rpm"
AC_CHECK_HEADER(rpm/rpmlib.h,
      [AC_CHECK_LIB(rpm,rpmdbOpen,
        [AC_DEFINE(HAVE_RPM, 1, [wheter RPM is present]) 
         RPM_LIBS="-lrpm -lpopt"
         SAVE_CPPFLAGS="$SAVE_CPPFLAGS -I/usr/include/rpm"
	 RPM_HDRS="-I/usr/include/rpm"
         rpm_version="3"])])
fi

AC_SUBST(RPM_LIBS)
AC_SUBST(RPM_HDRS)
CPPFLAGS="$SAVE_CPPFLAGS"
LIBS="$SAVE_LIBS"
AC_MSG_RESULT("RPM version is $rpm_version")

AC_MSG_CHECKING(for --enable-scripts)
AC_ARG_ENABLE([scripts],
	      AC_HELP_STRING(--enable-scripts, enable the extension system),
	      [enable_scripts="$enableval"],[enable_scripts="no"])
if test "$enable_scripts" != "no"; then
  AC_MSG_RESULT(no)
  AC_DEFINE(WITH_LUA, 1, 
	    [Define if you want to enable the extension system.]) 
else
  AC_MSG_RESULT(yes)
fi
AM_CONDITIONAL(WITH_LUA, test "$enable_scripts" != "no")

DEB_HDRS=""
AC_SUBST(DEB_HDRS)
DEB_LIBS="-lapt-inst"
AC_SUBST(DEB_LIBS)

# launchpad integration
AC_ARG_WITH(launchpad-integration,
 	[--launchpad-integration   build with launchpad-integration],
	[PKG_CHECK_MODULES(LP, ["launchpad-integration"])
	 AC_DEFINE(WITH_LAUNCHPAD_INTEGRATION, 1, [build with launchpad-integration] )
	]
)
AC_SUBST(LP_CFLAGS)
AC_SUBST(LP_LIBS)


dnl Checks for header files.
AC_HEADER_STDC

AC_CHECK_HEADERS(unistd.h libintl.h iconv.h)

AC_LANG_CPLUSPLUS
AC_CHECK_HEADER(apt-pkg/configuration.h)

if test x$ac_cv_header_apt_pkg_configuration_h != xyes; then
	AC_ERROR([You need the apt-pkg headers installed to compile synaptic.])
fi

AC_LANG_C

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE



dnl Checks for library functions.
AC_FUNC_STRCOLL
AC_CHECK_FUNCS(regcomp strdup iconv)

AC_ARG_WITH(pkg-hold, 
	[--with-pkg-hold   build with experimental package "hold" feature],
        AC_DEFINE(SYNAPTIC_PKG_HOLD, 1, [build with package pin feature] )
)

AC_ARG_WITH(apt-authentication, 
	[--with-apt-authentication  build with support for apt authentication],
        AC_DEFINE(WITH_APT_AUTH, 1, [build with apt auth support] )
)

AC_ARG_WITH(nice-dpkg-status, 
	[--with-nice-dpkg-status build with support for dpkg progress bar],
	[pkg_modules="vte >= 0.10.11"
	PKG_CHECK_MODULES(VTE, [$pkg_modules])
        AC_DEFINE(WITH_DPKG_STATUSFD, 1, [build with dpkg progress bar] )
	]
)


AC_ARG_WITH(debtags, 
	[--with-debtags-support   build with experimental debtags support],
        [AC_DEFINE(HAVE_DEBTAGS, 1, [build with debtags support])
	LIBTAGCOLL_DEFS
	]
)

dnl check for libvte
AC_ARG_WITH(vte, 
	      [--with-vte  compile with libvte support (terminal output)], 
	      [pkg_modules="vte >= 0.10.11"
	      PKG_CHECK_MODULES(VTE, [$pkg_modules])
	      AC_DEFINE(HAVE_VTE, 1, [build with VTE as output terminal])
	      AC_DEFINE(HAVE_TERMINAL, 1, [build with a terminal widget]) 
	      AC_SUBST(VTE_CFLAGS)
	      AC_SUBST(VTE_LIBS)
	      ]
	      )

AC_LANG([C++])
AC_CHECK_HEADER(apt-pkg/cdrom.h, 
                AC_DEFINE(HAVE_APTPKG_CDROM, 1, 
		[whether apt-pkg/cdrom.h is present]) )


AC_OUTPUT([
common/Makefile 
gtk/Makefile
gtk/glade/Makefile
data/Makefile
man/Makefile
pixmaps/Makefile 
pixmaps/hicolor/Makefile 
pixmaps/hicolor/16x16/Makefile 
pixmaps/hicolor/24x24/Makefile 
po/Makefile.in
help/Makefile
help/C/Makefile
help/es/Makefile
help/sv/Makefile
doc/Makefile
doc/html/Makefile
doc/html/C/Makefile
doc/html/es/Makefile
doc/html/sv/Makefile
Makefile
],[sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile])


