dnl Process this file with autoconf to produce a configure script. -*-m4-*-
AC_INIT(src/db-alias.c)
AM_INIT_AUTOMAKE(nss_db, 2.2.3)
AM_CONFIG_HEADER(config.h)

dnl Set of available languages.
ALL_LINGUAS="de nl"

# Check for a --with-db argument.
AC_ARG_WITH(db, dnl
  --with-db=DIR         find Berkeley DB library and headers with prefix DIR,
	    [dnl
case "$with_db" in
yes|''|no) ;;
*) libdb_include="-I$withval/include"
   libdb_libs="-L$withval/lib" ;;
esac
])
AC_ARG_WITH(db-include, dnl
  --with-db-include=DIR  find Berkeley DB headers in DIR,
            [dnl
case "$with_db_include" in
''|no) ;;
*) libdb_include="-I$withval" ;;
esac
])
AC_ARG_WITH(db-lib, dnl
  --with-db-lib=DIR      find Berkeley DB library in DIR,
            [dnl
case "$with_db_lib" in
''|no) ;;
*) libdb_libs="-L$withval" ;;
esac
])

dnl Checks for programs.
AC_PROG_CC
AC_PROG_CPP			dnl Later checks need this.
AM_DISABLE_STATIC		dnl Makes no sense for a NSS module
AM_PROG_LIBTOOL

DB_CFLAGS="$libdb_include"
DB_LIBS="$libdb_libs"

CPPFLAGS="$CPPFLAGS $DB_CFLAGS"

AC_CHECK_HEADER(db.h,, AC_MSG_ERROR([
*** Could not find Berkeley DB headers.]))

AC_CHECK_LIB(db, db_version,, AC_MSG_ERROR([
*** Could not find Berkeley DB library.]))

AC_CACHE_CHECK([Berkeley DB version], nss_db_cv_db_version,
  [AC_TRY_CPP(
    [
#    include <db.h>
#    ifndef DB_VERSION_STRING
#     error "Unknown"
#    endif
#    if DB_VERSION_MAJOR < 2
#     error "Too old"
#    endif
#    if DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR < 4
#     error "Too old"
#    endif
    ],
    nss_db_cv_db_version="ok",
    nss_db_cv_db_version="not ok")
  ])

if test "$nss_db_cv_db_version" != "ok"; then
AC_MSG_ERROR([
*** Unsupported Berkeley DB version detected.])
fi

AC_CANONICAL_HOST
slibdir=NONE
case "$host" in
*-linux*)
  # The Linux filesystem standard prescribed where to place "essential"
  # files.  I.e., when the installation prefix is "/usr" we have to place
  # shared library objects on the root partition in /lib.
  if test "$prefix" = "/usr" -o "$prefix" = "/usr"; then
    # 64bit libraries on sparc go to /lib64 and not /lib
    if test "$host_cpu" = "sparc64"; then
      slibdir="/lib64"
      if test "$libdir" = '${exec_prefix}/lib'; then
        libdir='${exec_prefix}/lib64';
      fi
    else
      slibdir="/lib"
    fi
  fi
  ;;
esac

if test "$slibdir" = "NONE"; then
  slibdir='${libdir}'
fi

AC_SUBST(DB_CFLAGS)
AC_SUBST(DB_LIBS)
AC_SUBST(slibdir)

dnl Internationalization macros.
AM_GNU_GETTEXT

AC_OUTPUT([Makefile src/Makefile intl/Makefile po/Makefile.in])
