dnl Process this file with autoconf to produce a configure script.
AC_INIT(src/main.c)
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(covered,covered-0.7.10)

dnl Get host information
AC_CANONICAL_HOST
case $host_os in
  *cygwin* ) build_cygwin=yes;;
         * ) build_cygwin=no;;
esac
AM_CONDITIONAL([BUILD_CYGWIN], [test x$build_cygwin = xyes])

dnl Checks for programs.
AC_PROG_MAKE_SET
AC_PROG_CC
dnl AC_ARG_PROGRAM
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_PROG_YACC
AC_PROG_LEX
AC_SYS_LARGEFILE
AC_C_BIGENDIAN
AC_CHECK_PROGS(XGPERF,gperf,none)
if test "$XGPERF" = "none"
then
	echo "*** Error:  No suitable gperf found. ***"
	echo "    Please install the 'gperf' package."
	exit 1
fi

dnl Libraries
AC_CHECK_LIB(z,gzdopen)

## Tcl/Tk.
AC_ARG_WITH([tcltk],
[AC_HELP_STRING([--with-tcltk],
                [use Tcl/Tk, or specify its library dir @<:@yes@:>@])],
[if test "${withval}" = no; then
  want_tcltk=no
elif test "${withval}" = yes; then
  want_tcltk=yes
else
  want_tcltk=yes
  LDFLAGS="${LDFLAGS} -L${withval}"
  tcltk_prefix="${withval}"
fi],
[want_tcltk=yes])
AC_ARG_WITH([tcl-config],
[AC_HELP_STRING([--with-tcl-config=TCL_CONFIG],
                [specify location of tclConfig.sh @<:@@:>@])],
[TCL_CONFIG="${withval}"],
[TCL_CONFIG=""])
AC_ARG_WITH([tk-config],
[AC_HELP_STRING([--with-tk-config=TK_CONFIG],
                [specify location of tkConfig.sh @<:@@:>@])],
[TK_CONFIG="${withval}"],
[TK_CONFIG=""])

AC_ARG_VAR([TCLTK_LIBS],
           [flags needed for linking against the Tcl and Tk libraries])
AC_ARG_VAR([TCLTK_CPPFLAGS],
           [flags needed for finding the tcl.h and tk.h headers])

## Tcl/Tk.
COVERED_TCLTK

## Check for browser for help pages
COVERED_PROG_BROWSER

dnl Specify debug enabling
COVERED_DEBUG

dnl Specify profiler enabling
COVERED_PROFILER

dnl Specify test-mode enabling
COVERED_TEST

## Simulators supported
AC_ARG_WITH([iv],
[AC_HELP_STRING([--with-iv=IV_BASE_DIR],
                [Create covered.vpi module for the Icarus Verilog simulator with the specified base directory @<:@@:>@])],
[if test "${withval}" = no; then
  want_iv=no
elif test "${withval}" = yes; then
  want_iv=yes
else
  AC_CHECK_HEADER([$withval/include/iverilog/vpi_user.h],
    [want_iv=yes
     iv_prefix="${withval}"
     iv_inc_prefix="${withval}/include/iverilog"],
    [AC_CHECK_HEADER([$withval/include/vpi_user.h],
       [want_iv=yes
        iv_prefix="${withval}"
        iv_inc_prefix="${withval}/include"],
       [AC_CHECK_HEADER([$withval/include/verilog/vpi_user.h],
          [want_iv=yes
           iv_prefix="${withval}"
           iv_inc_prefix="${withval}/include/verilog"],AC_MSG_ERROR([Invalid base directory specified in --with-iv]))])])
fi],
[want_iv=no])
if test "$want_iv" = yes; then
  AC_SUBST([IVLIB], ['covered.vpi'])
  AC_SUBST([IVDIR], ["${iv_prefix}"])
  AC_SUBST([IVINC], ["${iv_inc_prefix}"])
fi

AC_ARG_WITH([vcs],
[AC_HELP_STRING([--with-vcs=VCS_INCLUDE_DIR],
                [Create covered.vcs.so file for the VCS simulator with the specified include directory @<:@@:>@])],
[if test "${withval}" = no; then
  want_vcs=no
elif test "${withval}" = yes; then
  want_vcs=yes
else
  AC_CHECK_HEADER([$withval/vpi_user.h],
    [want_vcs=yes
     vcs_prefix="${withval}"],AC_MSG_ERROR([Invalid include directory specified in --with-vcs]))
fi],
[want_vcs=no])
if test "$want_vcs" = yes; then
  if test "$build_cygwin" = yes; then
    AC_MSG_ERROR([Cygwin version of VCS library is not available])
  else
    AC_SUBST([VCSLIB], ['covered.vcs.so'])
    AC_SUBST([VCSINC], ["${vcs_prefix}"])
  fi
fi

AC_ARG_WITH([ncv],
[AC_HELP_STRING([--with-ncv=NCV_INCLUDE_DIR],
                [Create covered.ncv.so file for the NCVerilog simulator with the specified include directory @<:@@:>@])],
[if test "${withval}" = no; then
  want_ncv=no
elif test "${withval}" = yes; then
  want_ncv=yes
else
  AC_CHECK_HEADER([$withval/vpi_user.h],
    [want_ncv=yes
     ncv_prefix="${withval}"],AC_MSG_ERROR([Invalid include directory specified in --with-ncv]))
fi],
[want_ncv=no])
if test "$want_ncv" = yes; then
  if test "$build_cygwin" = yes; then
    AC_MSG_ERROR([Cygwin version of NCVerilog library is not available])
  else
    AC_SUBST([NCVLIB], ['covered.ncv.so'])
    AC_SUBST([NCVINC], ["${ncv_prefix}"])
  fi
fi

AC_ARG_WITH([cver],
[AC_HELP_STRING([--with-cver=CVER_INCLUDE_DIR],
                [Create covered.cver.so file for the CVER simulator with the specified include directory @<:@@:>@])],
[if test "${withval}" = no; then
  want_cver=no
elif test "${withval}" = yes; then
  want_cver=yes
else
  AC_CHECK_HEADER([$withval/vpi_user.h],
    [want_cver=yes
     cver_prefix="${withval}"],AC_MSG_ERROR([Invalid include directory specified in --with-cver]))
fi],
[want_cver=no])
if test "$want_cver" = yes; then
  if test "$build_cygwin" = yes; then
    AC_SUBST([CVERLIB], ['covered.cver.dll'])
  else
    AC_SUBST([CVERLIB], ['covered.cver.so'])
  fi
  AC_SUBST([CVERINC], ["${cver_prefix}"])
fi

dnl AC_CHECK_HEADERS(getopt.h)
AC_CHECK_HEADERS(string.h)
AC_CHECK_HEADERS(sys/time.h)
AC_CHECK_HEADERS(math.h)

dnl Checks for libraries.
dnl AM_WITH_MPATROL(yes)

dnl Checks for header files.
AC_HEADER_STDC

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_CHECK_SIZEOF(char,4)
AC_CHECK_SIZEOF(short,4)
AC_CHECK_SIZEOF(int,4)
AC_CHECK_SIZEOF(long,4)
AC_CHECK_SIZEOF([long long],4)
AC_CHECK_SIZEOF(float,4)
AC_CHECK_SIZEOF(double,4)

dnl Checks for library functions.
AC_TYPE_SIGNAL
AC_TYPE_SIZE_T
AC_CHECK_LIB(m,round)
AC_CHECK_LIB(m,roundf)

dnl Stuff for creating dynamically loadable shared objects in a system-neutral way
# Compiler option for position independent code, needed when making shared objects.
# CFLAGS inherited by cadpli/Makefile?
AX_C_PICFLAG

# may modify CPPFLAGS and CFLAGS
AX_CPP_PRECOMP

# Linker option used when compiling the target
AX_LD_RDYNAMIC

# linker options when building a shared library
AX_LD_SHAREDLIB_OPTS


AC_OUTPUT(Makefile src/Makefile lib/Makefile scripts/Makefile doc/Makefile doc/docbook/Makefile)

if test -n "${warn_tcltk_version}"; then
  AC_MSG_WARN([${warn_tcltk_version}])
fi
