AC_INIT
AC_CONFIG_HEADER(config.h)

dnl Define the release numbers here

SETUPDB_VERSION_MAJOR=1
SETUPDB_VERSION_MINOR=6
SETUPDB_VERSION_RELEASE=1

PACKAGE_NAME="Loki Setup DataBase Library"
PACKAGE_TARNAME="setupdb"
PACKAGE_VERSION="$SETUPDB_VERSION_MAJOR.$SETUPDB_VERSION_MINOR.$SETUPDB_VERSION_RELEASE"
PACKAGE_STRING="$PACKAGE_NAME v$PACKAGE_VERSION"

test "x$CFLAGS" = x && CFLAGS="-O2"
CFLAGS="$CFLAGS -fsigned-char -Wall -g -I."
REENTRANT="-D_REENTRANT"

if test -d /usr/codehost/lib; then
	LIBS="-L/usr/codehost/lib"
elif test -d /opt/codehost/lib; then
	LIBS="-L/opt/codehost/lib"
elif test -d /sw/lib; then
	case "$target" in
	powerpc-apple-darwin*)
		LIBS="-L/sw/lib" ;;
	esac
else
	LIBS="$LIBS -L/usr/local/lib"
fi

dnl Detect the canonical host and target build environment
AC_CANONICAL_HOST
AC_CANONICAL_TARGET

AC_PROG_CC
AC_PROG_MAKE_SET

AC_CHECK_HEADERS(unistd.h)
AC_CHECK_HEADERS(strings.h)
AC_CHECK_HEADERS(sys/utsname.h)
AC_CHECK_HEADERS(sys/sysmacros.h)
AC_CHECK_HEADERS(sys/mkdev.h)
AC_CHECK_HEADERS(sys/isa_defs.h)
AC_CHECK_HEADERS(glob.h)
AC_CHECK_HEADERS(elf.h)
AC_CHECK_HEADERS(getopt.h)
AC_CHECK_HEADERS(libintl.h)

GETOPT_C=""

AC_CHECK_FUNCS(setenv)
AC_CHECK_FUNCS(unsetenv)
AC_PATH_PROG(BRANDELF, brandelf, true)

STATIC=""
LIBSUFFIX=""
BSTATIC="-Wl,-Bstatic"
BDYNAMIC="-Wl,-Bdynamic"

dnl Set the architecture flag
case "$target" in
*i?86*OpenUNIX* | *i?86*sco*)
	CFLAGS="$CFLAGS -Dsco"
	EXTRA_LIBS="$EXTRA_LIBS -L/udk/usr/lib -lsocket -lnsl -lresolv -lgen"
	ARCH=x86 ;;
hppa*)
	CFLAGS="$CFLAGS -I/opt/zlib/include"
	EXTRA_LIBS="$EXTRA_LIBS -ldld"
	STATIC="-Wl,-E"
	BSTATIC=""
	BDYNAMIC="-Wl,-a,archive_shared"
	ARCH=hppa ;;
*sgi*)
        LIBSUFFIX=32
	EXTRA_LIBS="$EXTRA_LIBS -L/usr/freeware/lib$LIBSUFFIX"
	ARCH=mips ;;
i?86*solaris*)
	EXTRA_LIBS="$EXTRA_LIBS -lsocket -lnsl -lresolv -ldl"
	ARCH=x86 ;;
*solaris*)
	EXTRA_LIBS="$EXTRA_LIBS -lsocket -lnsl -lresolv -ldl"
	ARCH=`uname -p` ;;
powerpc-apple-darwin*)
	CFLAGS="-Ddarwin"
	BSTATIC=""
	BDYNAMIC=""
	REENTRANT=""
	ARCH=ppc ;;
*aix*)
	BSTATIC=""
	BDYNAMIC=""
	ARCH=`uname -p`
        if test "$ARCH" = powerpc; then
                ARCH=ppc
        fi
	;;
    *ppc64* | *powerpc64*)
        ARCH=ppc64 ;;
    *ppc* | *powerpc*)
        ARCH=ppc ;;
*i?86*)
        ARCH=x86 ;;
*x86_64*)
	ARCH=amd64 ;;
*)
        ARCH=`uname -p 2> /dev/null || uname -m`
	if test "$ARCH" = powerpc; then
		ARCH=ppc
	fi
	;;
esac

ZLIB=${ZLIB:--lz}

dnl Add architecture-specific compile flags
case "$target" in
    alpha*-*-linux*)
        if test x$ac_cv_c_compiler_gnu = xyes; then
            CFLAGS="$CFLAGS -mcpu=ev4 -Wa,-mall"
        fi
        ;;
esac

CFLAGS="$CFLAGS $REENTRANT"

AC_CHECK_FUNCS(getopt, , GETOPT_C="getopt.c")
AC_CHECK_FUNCS(getopt_long, , GETOPT_C="getopt.c")
AC_CHECK_LIB(gnugetopt, getopt_long, LIBS="$LIBS $BSTATIC -lgnugetopt"; GETOPT_C="")

AC_SUBST(ARCH)
AC_SUBST(STATIC)
AC_SUBST(SETUPDB_VERSION_MAJOR)
AC_SUBST(SETUPDB_VERSION_MINOR)
AC_SUBST(SETUPDB_VERSION_RELEASE)
AC_SUBST(GETOPT_C)

dnl Look for the XML libraries

AC_PATH_PROG(HAVEXML, xml-config, $PATH)
if test ! -z "$HAVEXML"; then
    XML_CFLAGS=`$HAVEXML --cflags`
    XML_LIBS=`$HAVEXML --libs`
    XML_PREFIX=`$HAVEXML --prefix`

    CFLAGS="$CFLAGS $XML_CFLAGS"
    LIBS="$LIBS $XML_PREFIX/lib$LIBSUFFIX/libxml.a $BSTATIC $ZLIB $BDYNAMIC $EXTRA_LIBS"
else
    AC_MSG_ERROR([*** xml-config not found. You need a working libxml installation.])
fi

AC_ARG_WITH(vendor,
[  --with-vendor           with specified vendor prefix  [default=loki]], 
	,   with_vendor=loki)
if test x$with_vendor != xloki; then
        CFLAGS="$CFLAGS -DLOKI_PREFIX=\\\"$with_vendor\\\""
fi

AC_ARG_WITH(image,
[  --with-image            specifiy the image path  [default=../../spp/private/image]], 
	,   with_image=../../spp/private/image)
IMAGE="$with_image"


AC_SUBST(IMAGE)
AC_SUBST(BRANDELF)
AC_OUTPUT(Makefile)
