# copyright (c) 2000-2002 Chris Lyttle

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

dnl ==========================================================================
dnl
dnl If you add a version number here, you *must* add an AC_SUBST line for
dnl it too, or it will never make it into the spec file!
dnl
dnl ==========================================================================

SCROLLKEEPER_BUILD_REQUIRED=0.3.4
AC_SUBST(SCROLLKEEPER_BUILD_REQUIRED)

dnl ==========================================================================

dnl Checks for programs.
AC_PROG_AWK
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET

dnl Checks for libraries.

dnl Checks for header files.
AC_HEADER_STDC

dnl ====================================
dnl = Begin checks for typedefs, structures, and compiler characteristics.
dnl ====================================
AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T
dnl ====================================
dnl = End checks for typedefs, structures, and compiler characteristics.
dnl ====================================

dnl ====================================
dnl = Begin checks for library functions.
dnl ====================================
AC_FUNC_ALLOCA
AC_FUNC_MMAP
AC_CHECK_FUNCS(getcwd getwd putenv strdup)
dnl ====================================
dnl = End checks for library functions.
dnl ====================================

dnl ====================================
dnl = Begin tests for scrollkeeper
dnl ====================================
AC_PATH_PROG(SCROLLKEEPER_CONFIG, scrollkeeper-config,no)
if test x$SCROLLKEEPER_CONFIG = xno; then
  AC_MSG_ERROR(Couldn't find scrollkeeper-config. Please install the scrollkeeper package: http://scrollkeeper.sourceforge.net)
fi
dnl ====================================
dnl = End tests for scrollkeeper
dnl ====================================

AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(gnucash-docs,1.8.0)
AM_PROG_LIBTOOL

dnl
dnl Check for xsltproc
dnl
AC_PATH_PROG(XSLTPROC, xsltproc)
if test -z "$XSLTPROC"; then
  AC_MSG_ERROR([xsltproc not found])
fi

### --------------------------------------------------------------------------
### Check for perl

# Check for perl, force version 5
AC_ARG_WITH(perl,
  [  --with-perl=FILE             which perl executable to use ],
  PERL="${with_perl}")

# If the user didn't specify a perl, then go fetch.
if test x"$PERL" = x;
then
  AC_PATH_PROG(PERL, perl)
fi

# Make sure Perl was found
if test x"$PERL" = x; then
    AC_MSG_ERROR([Cannot find Perl. Try using the --with-perl flag.])
fi

# Make sure it's version 5 or later
if "$PERL" -e 'exit 1 if $] < 5.0'; then
	:
else
    AC_MSG_ERROR([Found ${PERL} reports version ]
                 [`${PERL} -e 'print $]'`, need version 5.*])
fi
AC_SUBST(PERL)

# Now check for perl headers
# This appears to be what Perl's
# ExtUtils::MakeMaker module does, so
# I'm reasonably sure it's correct.
# PERLINCL="/usr/lib/perl5/i386-linux/5.00404"
#
PERLINCL=`$PERL -MConfig -e 'print $Config{"archlibexp"}'`
AC_ARG_WITH( perl-includes,
   [  --with-perl-includes=DIR     specify where to look for perl includes],
        PERLINCL="$with_perl_includes" )
AC_SUBST(PERLINCL)

### --------------------------------------------------------------------------
### Berkeley db

AC_ARG_ENABLE(prefer-db1,
  [  --enable-prefer-db1          Prefer Berkeley DB
1.x],[prefer_db1="$enableval"],[prefer_db1=yes])

DB_LIBS=
AC_CHECK_FUNC(dbopen, [],
if test "$prefer_db1" = "yes"; then
 AC_CHECK_LIB(db1, dbopen, DB_LIBS="-ldb1",
  AC_CHECK_LIB(db, dbopen, DB_LIBS="-ldb",
   AC_CHECK_LIB(db-3, __db185_open, DB_LIBS="-ldb-3",
    AC_CHECK_LIB(db-4.0, __db185_open, DB_LIBS="-ldb-4.0",
     AC_MSG_ERROR([Your db library is missing db 1.85 compatibility mode])
    )
   )
  )
 )
else
 AC_CHECK_LIB(db, dbopen, DB_LIBS="-ldb",
  AC_CHECK_LIB(db1, dbopen, DB_LIBS="-ldb1",
   AC_CHECK_LIB(db-3, __db185_open, DB_LIBS="-ldb-3",
    AC_CHECK_LIB(db-4.0, __db185_open, DB_LIBS="-ldb-4.0",
     AC_MSG_ERROR([Your db library is missing db 1.85 compatibility mode])
    )
   )
  )
 )
fi
)

dnl look for db headers
if test "$prefer_db1" = "yes"; then
	AC_CHECK_HEADERS(db_185.h db1/db.h db4/db_185.h)
	if test "$ac_cv_header_db_185_h$ac_cv_header_db1_db_h$ac_cv_header_db4_db_185_h" = nonono; then
	  AC_MSG_ERROR([Berkeley db library required for GnuCash])
	fi
	AC_DEFINE(PREFER_DB1)
else
	AC_CHECK_HEADERS(db.h db_185.h db1/db.h db4/db_185.h)

	if test "$ac_cv_header_db_h$ac_cv_header_db_185_h$ac_cv_header_db1_db_h$ac_cv_header_db4_db_185_h" = nononono;
then
	  AC_MSG_ERROR([Berkeley db library required for GnuCash])
	fi
fi

AC_SUBST(DB_LIBS)

AC_OUTPUT(
gnucash-docs.spec
doc-tools/Makefile
help/Makefile
help/C/Makefile
help/de_DE/Makefile
guide/Makefile
guide/C/Makefile
Makefile)
