# Copyright (C) 2000, 2001, 2002, 2003 Cris van Pelt
# Copyright (C) 2003, 2004, 2005, 2006 Peter Palfrader
#
# $Id: configure.in 936 2012-06-30 18:44:52Z carsten $

dnl Process this file with autoconf to produce a configure script.
AC_INIT(src/deborphan.c)
AM_INIT_AUTOMAKE(deborphan, 1.7.28.8)
AM_CONFIG_HEADER(include/config.h)

AM_MAINTAINER_MODE

AC_DEFINE(STATUS_FILE, "/var/lib/dpkg/status", [Location of your statusfile])
AC_DEFINE(REG_FLAGS, REG_ICASE, [Bitwise or'd list of flags for regcomp()])

AC_PROG_CC
ALL_LINGUAS="ca cs da de es eu fr ja nl pl ru pt it vi"

AM_GNU_GETTEXT
AM_GNU_GETTEXT_VERSION(0.14.1)

AC_PROG_INSTALL
AC_STDC_HEADERS
AC_HAVE_HEADERS(string.h getopt.h errno.h)
AC_CHECK_FUNCS(getopt_long, ,AC_MSG_ERROR([You need getopt_long()]))
AC_C_INLINE

AC_MSG_CHECKING(wether to use xalloc)
AC_ARG_WITH(xalloc,
[  --without-xalloc        Disable safe memory allocation. ],
[if [[ "$withval" = "no" ]]; then
  xalloc=0
  AC_MSG_RESULT(no)
else
  xalloc=1
  AC_MSG_RESULT(yes)
fi], [ xalloc=1; AC_MSG_RESULT(yes) ]
)

AC_MSG_CHECKING(debfoster's keepers file)
if [[ -r /var/state/debfoster/keepers ]]; then
  dffile="/var/state/debfoster/keepers"
  AC_MSG_RESULT($dffile)
else 
  if [[ -r /etc/apt/keepers ]]; then
    dffile="/etc/apt/keepers"
    AC_MSG_RESULT($dffile)
  else
    with_debfoster="no"
    AC_MSG_RESULT("not found.")
  fi
fi 

AC_MSG_CHECKING(wether to ignore debfoster)
AC_ARG_WITH(debfoster,
[  --without-debfoster     Ignore debfoster's keepers file. ],
[if [[ "$withval" = "no" ]]; then
  ignore_df=1
  AC_MSG_RESULT(yes)
else
  ignore_df=0
  AC_MSG_RESULT(no)
fi], [ ignore_df=0; AC_MSG_RESULT(no) ]
)

AC_MSG_CHECKING(memory usage)
AC_ARG_WITH(lowmem,
[  --with-lowmem           Turn on conservative memory usage. ],
[if [[ "$withval" = "yes" ]]; then
  himem=0
  AC_MSG_RESULT(low)
else
  himem=1
  AC_MSG_RESULT(high)
fi], [ himem=1; AC_MSG_RESULT(high) ]
)

AC_MSG_CHECKING(wether to imply -s)
AC_ARG_WITH(isfa,
[  --without-isfa          Disable implication of -s when using -a. ],
[if [[ "$withval" = "no" ]]; then
  isfa=0
  AC_MSG_RESULT(no)
else
  isfa=1
  AC_MSG_RESULT(yes)
fi], [ isfa=1; AC_MSG_RESULT(yes) ]
)

AC_MSG_CHECKING(wether to run in nice mode)
AC_ARG_WITH(nice,
[  --without-nice          Do not run in nice mode by default. ],
[if [[ "$withval" = "no" ]]; then
  nice=0
  AC_MSG_RESULT(no)
else
  nice=1
  AC_MSG_RESULT(yes)
fi], [ nice=1; AC_MSG_RESULT(yes) ]
)

AC_MSG_CHECKING(default priority)
AC_ARG_WITH(priority,
[  --with-priority=PRIOR   Default minimum priority. ],
[if echo $withval | grep -E '^[[[:digit:]]]+$' >/dev/null; then
  priority=$withval
  AC_MSG_RESULT($priority)
else
  AC_MSG_ERROR(invalid priority: $withval)
fi], [ priority=2; AC_MSG_RESULT(2) ]
)

AC_MSG_CHECKING(ignore essential)
AC_ARG_WITH(ignore-essential,
[  --with-ignore-essential Ignore 'Essential: yes' lines. ],
[if [[ "$withval" = "yes" ]]; then
  essential=0
  AC_MSG_RESULT(yes)
else
  essential=1
  AC_MSG_RESULT(no)
fi], [ essential=1; AC_MSG_RESULT(no) ]
)

AC_DEFINE_UNQUOTED(DEFAULT_PRIORITY, $priority, [Default minimum priority])

if [[ $isfa -eq 1 ]]; then
  AC_DEFINE(ALL_PACKAGES_IMPLY_SECTION, 1, [Imply --show-section when using --all-packages.])
fi
if [[ $ignore_df -eq 1 ]]; then
  AC_DEFINE(IGNORE_DEBFOSTER, 1, [Ignore debfoster's keepers file.])
fi
if [[ $xalloc -eq 1 ]]; then
  AC_DEFINE(USE_XALLOC, 1, [Safe memory allocation])
fi
if [[ $nice -eq 1 ]]; then
  AC_DEFINE(DEFAULT_NICE, 1, [Count 'recommends' and 'suggests' as 'depends'])
fi
if [[ ! $himem -eq 1 ]]; then
  AC_DEFINE(LOW_MEM, 1, [ Conservative memory usage])
fi
if [[ ! $essential -eq 1 ]]; then
  AC_DEFINE(IGNORE_ESSENTIAL, 1, [Ignore 'Essential: yes' lines])
fi
if [[ ! -z $dffile ]]; then
  AC_DEFINE_UNQUOTED(DEBFOSTER_KEEP, "$dffile", [Location of debfoster's keepers file.])
fi

AC_OUTPUT(Makefile src/Makefile doc/Makefile doc/po/Makefile doc/fr/Makefile doc/pl/Makefile doc/es/Makefile doc/de/Makefile doc/pt/Makefile include/Makefile po/Makefile.in intl/Makefile util/Makefile) 

