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

AC_PREREQ([2.13])

AC_INIT(include/dpkg.h.in)
AC_CONFIG_HEADER(config.h)

DSELECTDIR="dselect"
AC_ARG_WITH(dselect,
[  --with-dselect          the dselect package-management frontend],
[case "$withval" in
  "false" | "no" )
    DSELECTDIR=""
    ;;
 esac])
AC_SUBST(DSELECTDIR)

USE_START_STOP_DAEMON="true"
AC_ARG_WITH(start-stop-daemon,
[  --with-start-stop-daemon
                          start and stop system daemons],
[case "$withval" in
  "false" | "no" )
    USE_START_STOP_DAEMON=""
    ;;
 esac])
AC_SUBST(USE_START_STOP_DAEMON)
if test "$USE_START_STOP_DAEMON" != ""; then
    AC_DEFINE(USE_START_STOP_DAEMON)
fi

USE_SGML_DOC="true"
AC_ARG_WITH(sgml-doc,
[  --with-sgml-doc         SGML documentation converted to HTML],
[case "$withval" in
  "false" | "no" )
    USE_SGML_DOC=""
    ;;
 esac])
AC_SUBST(USE_SGML_DOC)

admindir="$libdir/db"
AC_ARG_WITH(admindir,
[  --with-admindir=DIR     store dpkg database in DIR [LIBDIR/db]],
[case "$withval" in
  "" )
    AC_MSG_ERROR(invalid admindir specified)
    ;;
  * )
    admindir="$withval"
    ;;
 esac])
AC_SUBST(admindir)

AC_CHECK_TOOL_PREFIX
AC_CANONICAL_SYSTEM

AC_CHECK_TOOL(CC, gcc)
AC_PROG_CC
AC_PROG_CXX
AM_CONDITIONAL(HAVE_CPLUSPLUS, [test "$CXX" != ""])

AC_CHECK_TOOL(LD, ld, ld)

PACKAGE=dpkg
AC_SUBST(PACKAGE)
VERSION=`cat $srcdir/version-nr`
AC_SUBST(VERSION)

dnl test to see if srcdir already configured
if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then
  AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
fi
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])
AC_REQUIRE([AC_ARG_PROGRAM])
AC_REQUIRE([AC_PROG_MAKE_SET])

AC_MSG_CHECKING(dpkg version)
AC_MSG_RESULT($VERSION)

AC_PREFIX_DEFAULT(/usr)

dpkg_archset=''
AC_MSG_CHECKING(Debian architecture)
dpkg_archset="`awk '$1 == "'$target_cpu-$target_os'" { print $2 }' $srcdir/archtable`"
# Finish off
if test "x$dpkg_archset" = "x"; then
 AC_MSG_RESULT([$target_cpu-$target_os, but not found in archtable])
 dpkg_archset=$target_cpu-$target_os
 else
 AC_MSG_RESULT($dpkg_archset)
fi
AC_DEFINE_UNQUOTED(ARCHITECTURE, "${dpkg_archset}")

dnl gettext

ALL_LINGUAS="cs de en es fr gl it nl ja pl pt_BR ru sv"
AM_GNU_GETTEXT

dnl Other stuff

AC_STDC_HEADERS
AC_PROG_RANLIB
AC_PROG_LN_S
AC_CHECK_PROG(RM,rm,rm -f)
AC_CHECK_PROG(SED,sed,sed)
AC_PROG_INSTALL
AC_PATH_PROG(PERL,perl,/usr/bin/perl)
dnl Default in case EMACS == no
lispdir="\$(datadir)/emacs/site-lisp/"
AC_MODE_T
AC_PID_T
AC_SIZE_T
AC_VPRINTF
AC_C_CONST
AC_C_BIGENDIAN
AC_C_INLINE
AC_CHECK_SIZEOF(unsigned long)
AC_CHECK_SIZEOF(unsigned int)
AC_CHECK_TYPE(ptrdiff_t,int)
AC_CHECK_FUNCS(unsetenv alphasort scandir strerror strsignal strtoul)
AC_CHECK_FUNCS(vsnprintf lchown snprintf)
AC_CHECK_HEADERS(sys/cdefs.h syslog.h stddef.h)
AC_CHECK_HEADERS(error.h)
AC_SYS_SIGLIST_DECLARED

AC_CHECK_LIB(ihash, ihash_create, SSD_LIBS="-lihash $SSD_LIBS")
AC_CHECK_LIB(ps, proc_stat_list_create, SSD_LIBS="-lps $SSD_LIBS")
AC_CHECK_LIB(shouldbeinlibc, fmt_past_time, SSD_LIBS="-lshouldbeinlibc $SSD_LIBS")
AC_CHECK_LIB(kvm, kvm_openfiles, SSD_LIBS="-lkvm $SSD_LIBS")
AC_SUBST(SSD_LIBS)

AC_ARG_WITH(zlib,
[  --with-zlib             use zlib for decompression of some gzip files],
	[use_zlib=$withval],
	[uze_zlib=no])
if test "$use_zlib" = "no" ; then
	ZLIB_CFLAGS=
	ZLIB_LIBS=
else
	ZLIB_CFLAGS=-DUSE_ZLIB
	if test "$use_zlib" = "static"  ; then
		ZLIB_LIBS="-Wl,-Bstatic -lz -Wl,-Bdynamic"
	else
		ZLIB_LIBS=-lz
	fi
fi
AC_SUBST(ZLIB_CFLAGS)
AC_SUBST(ZLIB_LIBS)

AC_TRY_COMPILE([
#include <sys/types.h>
#include <dirent.h>
], alphasort, AC_DEFINE(HAVE_ALPHASORT_DECLARATION))

AC_TRY_COMPILE(,[
} inline int foo (int x) {], AC_DEFINE(HAVE_INLINE))

DPKG_CACHED_TRY_COMPILE(__attribute__((,,)),dpkg_cv_c_attribute_supported,,
 [extern int testfunction(int x) __attribute__((,,))],
 AC_MSG_RESULT(yes)
 AC_DEFINE(HAVE_GNUC25_ATTRIB)
  DPKG_CACHED_TRY_COMPILE(__attribute__((noreturn)),dpkg_cv_c_attribute_noreturn,,
   [extern int testfunction(int x) __attribute__((noreturn))],
   AC_MSG_RESULT(yes)
   AC_DEFINE(HAVE_GNUC25_NORETURN),
   AC_MSG_RESULT(no))
  DPKG_CACHED_TRY_COMPILE(__attribute__((const)),dpkg_cv_c_attribute_const,,
   [extern int testfunction(int x) __attribute__((const))],
   AC_MSG_RESULT(yes)
   AC_DEFINE(HAVE_GNUC25_CONST),
   AC_MSG_RESULT(no))
  DPKG_CACHED_TRY_COMPILE(__attribute__((format...)),dpkg_cv_attribute_format,,
   [extern int testfunction(char *y, ...) __attribute__((format(printf,1,2)))],
   AC_MSG_RESULT(yes)
   AC_DEFINE(HAVE_GNUC25_PRINTFFORMAT),
   AC_MSG_RESULT(no)),
 AC_MSG_RESULT(no))

AC_MSG_CHECKING(whether to use -Werror)
AC_ARG_WITH(Werror,
[  --with-Werror           use -Werror when compiling],
	[warn=-Werror]
	AC_MSG_RESULT(yes)
	DPKG_C_GCC_TRY_WARNS(-Werror, dpkg_cv_c_gcc_warn_error),
	[warn=all]
	AC_MSG_RESULT(no))

DPKG_C_GCC_TRY_WARNS(-Wall -Wno-implicit, dpkg_cv_c_gcc_warn_all)
DPKG_C_GCC_TRY_WARNS(-Wwrite-strings, dpkg_cv_c_gcc_warn_writestrings)
DPKG_C_GCC_TRY_WARNS(-Wpointer-arith, dpkg_cv_c_gcc_warn_pointerarith)
DPKG_C_GCC_TRY_WARNS(-Wimplicit -Wnested-externs, dpkg_cv_c_gcc_warn_implicit)
DPKG_C_GCC_TRY_WARNS(-Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations, dpkg_cv_c_gcc_prototypes)
AC_SUBST(CWARNS)

dnl Force this here so we can do the next step
test "x$prefix" = xNONE && prefix="$ac_default_prefix"
test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
LLIBDIR=`eval echo $libdir`
LLIBDIR=`eval echo $LLIBDIR`
LOCALSTATEDIR=`eval echo $localstatedir`
AC_DEFINE_UNQUOTED(LLIBDIR, "$LLIBDIR")
AC_DEFINE_UNQUOTED(LOCALSTATEDIR, "$LOCALSTATEDIR")

AC_OUTPUT(
Makefile.conf
Makefile
intl/Makefile
include/Makefile
dpkg-deb/Makefile
split/Makefile
lib/Makefile
optlib/Makefile
doc/Makefile
doc/fr/Makefile
doc/ja/Makefile
doc/sv/Makefile
scripts/Makefile
main/Makefile
dselect/Makefile
methods/Makefile
utils/Makefile
po/Makefile:po/Makefile.in.in)
