#
# configure.in --
#
#      Process this file with autoconf to produce a configure script.
#
# Copyright (c) 1999-2008 Frank Strauss, Technical University of Braunschweig.
#
# See the file "COPYING" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# @(#) $Id: configure.in 8090 2008-04-18 12:56:29Z strauss $
#

AC_INIT(tools/smilint.c)

LIBSMI_MAJOR=0
LIBSMI_MINOR=4
LIBSMI_PATCHLEVEL=8
LIBTOOL_VERSION=2
LIBTOOL_REVISION=27
LIBTOOL_AGE=0

VERSION_STRING="$LIBSMI_MAJOR.$LIBSMI_MINOR.$LIBSMI_PATCHLEVEL"
VERSION_LIBTOOL="$LIBTOOL_VERSION:$LIBTOOL_REVISION:$LIBTOOL_AGE"

AM_INIT_AUTOMAKE(libsmi,$VERSION_STRING)
AM_CONFIG_HEADER(config.h)

AC_DEFINE([MAX_LEX_DEPTH], 30,
[The maximum module import recursion depth.])

AC_DEFINE([DEFAULT_ERRORLEVEL], 3,
[The default error level at libsmi initialization.])

AC_ARG_WITH(cflags,
[  --with-cflags=FLAGS     use FLAGS for CFLAGS],
CFLAGS="$withval")

AC_PROG_CC
AC_ARG_WITH(cc,
[  --with-cc=CC            use CC as the C compiler],
CC="$withval")

AC_MSG_CHECKING([for additional required compiler flags])
AC_TRY_RUN([#include <stdio.h>
  main() {
  #ifdef __SUNPRO_C
        exit(0);
  #else
        exit(1);
  #endif
  }
], ADDCFLAGS="-DYY_USE_PROTOS", ADDCFLAGS="", ADDCFLAGS="")
echo $ADDCFLAGS
CFLAGS="$CFLAGS $ADDCFLAGS"

AC_CHECK_FUNCS(strtoll strtoull strtoq strtouq)

AC_CHECK_FUNCS(timegm)

AC_CHECK_FUNCS(vsnprintf snprintf asprintf asnprintf vasprintf vasnprintf)

AC_CHECK_HEADERS(pwd.h unistd.h regex.h stdint.h limits.h)

# In case regex is not in libc
AC_CHECK_LIB(c,regexec,LDFLAGS="$LDFLAGS",
[
    AC_CHECK_LIB(rxspencer,regexec,LDFLAGS="$LDFLAGS -lrxspencer",
    [
        AC_CHECK_LIB(regex,regexec,LDFLAGS="$LDFLAGS -lregex")
    ])
])

if test "x$prefix" = "xNONE" ; then
  prefix=/usr/local
fi

AC_ARG_WITH(mibdir,
[  --with-mibdir=DIR       use DIR to install libsmi MIB modules [DATADIR/mibs]],
mibdir="$withval", mibdir="$prefix/share/mibs")

AC_ARG_WITH(pibdir,
[  --with-pibdir=DIR       use DIR to install libsmi PIB modules [DATADIR/pibs]],
pibdir="$withval", pibdir="$prefix/share/pibs")

AC_ARG_WITH(smipath,
[  --with-smipath=DIR:DIR  default DIRs to search for MIB/PIB modules [MIBDIR...]],
smipath="$withval", smipath="$mibdir/ietf:$mibdir/iana:$mibdir/irtf:$mibdir/site:$mibdir/tubs:$pibdir/ietf:$pibdir/site:$pibdir/tubs")

AC_DEFINE_UNQUOTED([DEFAULT_SMIPATH], "$smipath",
[The default search path to lookup SMI module files.])

AC_ARG_WITH(pathseparator,
[  --with-pathseparator=C  use C as the path separator [: on UNIX, ; on WIN32]],
pathseparator="$withval", pathseparator="")

AC_ARG_WITH(dirseparator,
[  --with-dirseparator=C   use C as the dir separator [/ on UNIX, \\ on WIN32]],
dirseparator="$withval", dirseparator="")

AC_MSG_CHECKING([for path separator character])
if test "$pathseparator" = "" ; then
  AC_TRY_RUN([#include <stdio.h>
    main() {
    #ifdef _WIN32
	  exit(0);
    #else
	  exit(1);
    #endif
    }
  ], pathseparator=";", pathseparator=":", pathseparator=":")
fi
echo $pathseparator

AC_MSG_CHECKING([for dir separator character])
if test "$dirseparator" = "" ; then
  AC_TRY_RUN([#include <stdio.h>
    main() {
    #ifdef _WIN32
	  exit(0);
    #else
	  exit(1);
    #endif
    }
  ], dirseparator="\\\\", dirseparator="/", dirseparator="/")
fi
echo $dirseparator

AC_DEFINE_UNQUOTED([PATH_SEPARATOR], '$pathseparator',
[The default path separator character.])

AC_DEFINE_UNQUOTED([DIR_SEPARATOR], '$dirseparator',
[The default path separator character.])


AC_MSG_CHECKING([for 64 bit types])
#
# Note that int64_min is defined as -9223372036854775807LL and NOT as
# -9223372036854775808LL. gcc (version 2.95.4 and others) complains with
# "warning: decimal constant is so large that it is unsigned"
# if used with the (correct) value -9223372036854775808LL.
#
AC_TRY_RUN([#include <stdio.h>
      main() {
	  long long ll;
	  unsigned long long ull;
	  exit(0);
      }
    ],
    uint64_type="unsigned long long"; int64_type="long long";
    uint64_format="%llu"; int64_format="%lld";
    uint64_max="18446744073709551615ULL";
    int64_min="-9223372036854775807LL"; int64_max="9223372036854775807LL"
    ,
    uint64_type="unsigned long"; int64_type="long";
    uint64_format="%lu"; int64_format="%ld";
    uint64_max="4294967295";
    int64_min="-2147483648"; int64_max="2147483647"
    ,
    uint64_type="unsigned long long"; int64_type="long long";
    uint64_format="%llu"; int64_format="%lld";
    uint64_max="18446744073709551615ULL";
    int64_min="-9223372036854775807LL"; int64_max="9223372036854775807LL"
)
echo $int64_type/$int64_format, etc.

UINT64_TYPE=$uint64_type
INT64_TYPE=$int64_type
AC_DEFINE_UNQUOTED([UINT64_FORMAT], "$uint64_format",
[The unsigned 64 bit integer format conversion specification string.])
AC_DEFINE_UNQUOTED([INT64_FORMAT], "$int64_format",
[The signed 64 bit integer format conversion specification string.])
AC_DEFINE_UNQUOTED([LIBSMI_UINT64_MAX], $uint64_max,
[The unsigned 64 bit integer maximum value.])
AC_DEFINE_UNQUOTED([LIBSMI_INT64_MIN], $int64_min,
[The unsigned 64 bit integer minimum value.])
AC_DEFINE_UNQUOTED([LIBSMI_INT64_MAX], $int64_max,
[The signed 64 bit integer maximum value.])


AC_ARG_ENABLE(dmalloc,
[  --enable-dmalloc        enable dmalloc debugging (www.dmalloc.com)],
LIBS="$LIBS -ldmalloc"
AC_DEFINE([HAVE_DMALLOC_H], 1, ""))

AC_DEFINE(BACKEND_SMI, 1, "")
AC_ARG_ENABLE(smi,
[  --disable-smi           disable SMIv1/v2 parser support],
AC_DEFINE(BACKEND_SMI, 1, ""))

AC_ARG_ENABLE(sming,
[  --enable-sming          enable SMIng parser support],
AC_DEFINE(BACKEND_SMING, 0, ""))

AC_PATH_PROG(FLEX, "flex")
if test -z "${FLEX}" ; then
  echo "NOTE: We will not be able to build scanner C code from flex sources."
fi

AC_PATH_PROG(BISON, "bison")
if test -z "${BISON}" ; then
  echo "NOTE: We will not be able to build parser C code from bison sources."
fi

AC_PATH_PROG(BASH, "bash")
AC_PATH_PROG(SH, "sh")
AC_PATH_PROG(AWK, awk)
AC_PATH_PROG(WGET, wget)

AC_PATH_PROGS(DIFF, gdiff diff)
$DIFF --version >/dev/null 2>&1
if test $? -eq 0 ; then
	DIFF="$DIFF --ignore-matching-lines='generated by smidump' --ignore-matching-lines='\$Id.*\$' --ignore-matching-lines='@author.*smidump'"
fi

AC_EXEEXT
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AM_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)

AC_DEFINE_UNQUOTED([DEFAULT_GLOBALCONFIG], "${sysconfdir}/smi.conf",
[The full pathname of the global configuration file.])

AC_DEFINE([DEFAULT_USERCONFIG], ".smirc",
[The basename of the per-user configuration file searched in $HOME.])

if ${CONFIG_SHELL} ./libtool --features | grep "enable static" >/dev/null; then
  STATIC=-static
else
  STATIC=
fi
AC_SUBST(STATIC)

AC_SUBST(LIBSMI_MAJOR)
AC_SUBST(LIBSMI_MINOR)
AC_SUBST(LIBSMI_PATCHLEVEL)
AC_SUBST(LIBTOOL_VERSION)
AC_SUBST(LIBTOOL_REVISION)
AC_SUBST(LIBTOOL_AGE)
AC_SUBST(VERSION_STRING)
AC_SUBST(VERSION_LIBTOOL)
AC_SUBST(UINT64_TYPE)
AC_SUBST(INT64_TYPE)

AC_SUBST(EXEEXT)
AC_SUBST(BASH)
AC_SUBST(SH)
AC_SUBST(AWK)
AC_SUBST(WGET)
AC_SUBST(DIFF)
AC_SUBST(CC)
AC_SUBST(CFLAGS)
AC_SUBST(srcdir)
AC_SUBST(mibdir)
AC_SUBST(pibdir)
AC_SUBST(smipath)

AC_OUTPUT([
Makefile
lib/Makefile
tools/Makefile
mibs/Makefile
mibs/iana/Makefile
mibs/ietf/Makefile
mibs/irtf/Makefile
mibs/tubs/Makefile
mibs/site/Makefile
pibs/Makefile
pibs/ietf/Makefile
pibs/tubs/Makefile
pibs/site/Makefile
test/Makefile
test/mibs/Makefile
test/smidiff/Makefile
test/dumps/Makefile
test/dumps/corba/Makefile
test/dumps/imports/Makefile
test/dumps/jax/Makefile
test/dumps/netsnmp/Makefile
test/dumps/mosy/Makefile
test/dumps/orig-smiv2/Makefile
test/dumps/smilint-smiv2/Makefile
test/dumps/sming/Makefile
test/dumps/smiv1/Makefile
test/dumps/smiv2/Makefile
test/dumps/smiv2-smiv2/Makefile
test/dumps/tree/Makefile
test/dumps/types/Makefile
test/dumps/identifiers/Makefile
test/dumps/metrics/Makefile
test/dumps/xml/Makefile
test/dumps/cm/Makefile
test/dumps/python/Makefile
test/dumps/yang/Makefile
doc/Makefile
lib/smi.h
lib/libsmi.3
lib/smi_macro.3
lib/smi_module.3
lib/smi_node.3
lib/smi_type.3
lib/smi_config.3
lib/smi_render.3
lib/smi_util.3
lib/smi_class.3
lib/smi_attribute.3
lib/smi_event.3
lib/smi_identity.3
tools/smistrip
tools/smicache
tools/smiquery.1
tools/smilint.1
tools/smidump.1
tools/smidiff.1
tools/smistrip.1
tools/smicache.1
tools/smixlate.1
tools/mib2svg.cgi
test/parser.test
test/smidump-corba.test
test/smidump-jax.test
test/smidump-netsnmp.test
test/smidump-imports.test
test/smidump-mosy.test
test/smidump-orig-smiv2.test
test/smidump-sming.test
test/smidump-yang.test
test/smidump-smiv1.test
test/smidump-smiv2-smiv2.test
test/smidump-smiv2.test
test/smidump-tree.test
test/smidump-types.test
test/smidump-identifiers.test
test/smidump-metrics.test
test/smidump-xml.test
test/smidump-cm.test
test/smidump-python.test
test/smilint-smiv2.test
test/smidiff.test
libsmi.pc
win/config.h],
chmod a+x test/*.test
)
