dnl **********************************
dnl *** include special CSL macros ***
dnl **********************************
builtin(include, ac_csl.m4)dnl

#
# Configure script for CSL
#
AC_INIT(adapter/adapter_impl.h)
AM_CONFIG_HEADER(CSL_config.h)
AC_PREREQ(2.13)

#
# CSL version numbers
#
AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)dnl
CSL_MAJOR_VERSION=0
CSL_MINOR_VERSION=2
CSL_MICRO_VERSION=0
CSL_INTERFACE_AGE=0
CSL_BINARY_AGE=0
CSL_VERSION=$CSL_MAJOR_VERSION.$CSL_MINOR_VERSION.$CSL_MICRO_VERSION
AC_DIVERT_POP()dnl
dnl#
dnl# Making releases:
dnl#   CSL_MICRO_VERSION += 1;
dnl#   CSL_INTERFACE_AGE += 1;
dnl#   CSL_BINARY_AGE += 1;
dnl# if any functions have been added, set CSL_INTERFACE_AGE to 0.
dnl# if backwards compatibility has been broken,
dnl# set CSL_BINARY_AGE _and_ CSL_INTERFACE_AGE to 0.
dnl#
# CSL version numbers
AC_SUBST(CSL_MAJOR_VERSION)
AC_SUBST(CSL_MINOR_VERSION)
AC_SUBST(CSL_MICRO_VERSION)
AC_SUBST(CSL_INTERFACE_AGE)
AC_SUBST(CSL_BINARY_AGE)
AC_SUBST(CSL_VERSION)

# compute libtool versions
LT_RELEASE=$CSL_MAJOR_VERSION.$CSL_MINOR_VERSION
LT_CURRENT=`expr $CSL_MICRO_VERSION - $CSL_INTERFACE_AGE`
LT_REVISION=$CSL_INTERFACE_AGE
LT_AGE=`expr $CSL_BINARY_AGE - $CSL_INTERFACE_AGE`
AC_SUBST(LT_RELEASE)
AC_SUBST(LT_CURRENT)
AC_SUBST(LT_REVISION)
AC_SUBST(LT_AGE)

dnl figure debugging default, prior to $ac_help setup
dnl
AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)dnl
if test `expr $CSL_MINOR_VERSION \% 2 \| $CSL_MAJOR_VERSION \< 1` = 1 ; then
        debug_default=yes
else
        debug_default=minimum
fi
AC_DIVERT_POP()dnl


# initialize automake, don't define PACKAGE and VERSION
AM_INIT_AUTOMAKE(csl, $CSL_VERSION, no-define)

# Support program name conversion.
AC_ARG_PROGRAM

# Disable automatic maintainer mode.
AM_MAINTAINER_MODE

# We have subdirectories.
AC_PROG_MAKE_SET

# Make sure else configure stuff exists.
AC_CANONICAL_HOST

# declare --enable-* args and collect ac_help strings
AC_ARG_ENABLE(debug, [  --enable-debug=[no/minimum/yes] turn on debugging [default=$debug_default]],,enable_debug=$debug_default)

dnl setup DEBUG defaults
if test "x$enable_debug" = "xyes"; then
  DEBUG_FLAGS="-DG_ENABLE_DEBUG"
else if test "x$enable_debug" = "xno"; then
  DEBUG_FLAGS="-DG_DISABLE_CHECKS" # -DG_DISABLE_ASSERT
else
  DEBUG_FLAGS="-DG_DISABLE_CAST_CHECKS"
fi fi
if test "$cflags_set" = set; then
  CFLAGS="$CFLAGS -g $DEBUG_FLAGS"
else
  CFLAGS="$DEBUG_FLAGS"
fi


dnl Foreign defaults:
MC_IF_VAR_EQ(enable_static, yes, , enable_static=no)
MC_IF_VAR_EQ(enable_shared, no, , enable_shared=yes)

dnl
dnl Define package requirements.
dnl
AC_DEFUN(AC_CHECK_ARTS,
[
    CFLAGS="$CFLAGS -DG_DISABLE_DEPRECATED"

    dnl Need pkg-config first
    ARTSDIR=
    ARTS_CFLAGS=
    ARTS_LIBS=
    AC_PATH_PROG(ARTSC_CONFIG, artsc-config, no)
    if test x$ARTSC_CONFIG = xno ; then
      CSL_FEATURE_ARTS=0
    else
      dnl Check for proper Arts version and retrive paths
      REQUIRED=0.5.4
      AC_MSG_CHECKING(for ARTS - version >= $REQUIRED)
      ARTS_VERSION=[`$ARTSC_CONFIG --arts-version | sed 's/^[^0-9]*//'`]
      MC_CHECK_VERSION($ARTS_VERSION, $REQUIRED,
        AC_MSG_RESULT([yes ($ARTS_VERSION)])
        CSL_FEATURE_ARTS=1
        
        dnl setup variables
        ARTSDIR=[`$ARTSC_CONFIG --arts-prefix`]
        ARTS_CFLAGS="-I$ARTSDIR/include/arts"
        ARTS_LIBS="-L$ARTSDIR/lib -lmcop"
        ,
        AC_MSG_RESULT([no ($ARTS_VERSION < $REQUIRED)])
        CSL_FEATURE_ARTS=0
      )
    fi
    AC_SUBST(ARTSDIR)
    AC_SUBST(ARTS_CFLAGS)
    AC_SUBST(ARTS_LIBS)
    AC_SUBST(CSL_FEATURE_ARTS)
    AM_CONDITIONAL(CSL_BUILD_ARTS, test x$CSL_FEATURE_ARTS = x1)
])

# check compilers and their behaviour, setup CFLAGS
MC_PROG_CC_WITH_CFLAGS
AC_PROG_CXX
MC_PROG_CXX_WITH_CXXFLAGS
AC_PROG_CPP
AC_PROG_CXXCPP
AC_C_CONST
AC_C_INLINE
AC_HEADER_STDC

# Checks for programs
AC_PROG_INSTALL
AC_PROG_LN_S

# initialize libtool, we need dynamic module support
AC_LIBTOOL_DLOPEN
AM_PROG_LIBTOOL

# Figure build requirements
AC_MSG_CHECKING(whether make is GNU Make)
STRIP_BEGIN=
STRIP_END=
if $ac_make --version 2>/dev/null | grep '^GNU Make ' >/dev/null ; then
        STRIP_BEGIN='$(strip $(STRIP_DUMMY)'
        STRIP_END=')'
        AC_MSG_RESULT(yes)
else
        AC_MSG_RESULT(no)
fi
dnl some Make 3.79 $(strip ) versions are broken and require an empty arg
STRIP_DUMMY=
AC_SUBST(STRIP_DUMMY)
AC_SUBST(STRIP_BEGIN)
AC_SUBST(STRIP_END)

# feature aRts
AC_CHECK_ARTS

# architecture information
AC_DEFINE_UNQUOTED(CSL_ARCH_NAME, "${host_alias}")

# check for bytesex stuff and export it
AC_C_BIGENDIAN
case xyes in
  x$ac_cv_c_bigendian)
    CSL_BYTE_ORDER=CSL_BIG_ENDIAN
    ;;
  *)
    CSL_BYTE_ORDER=CSL_LITTLE_ENDIAN
    ;;
esac
AC_SUBST(CSL_BYTE_ORDER)

# libtool option to control which symbols are exported
# right now, symbols starting with _ are not exported
LIBTOOL_EXPORT_OPTIONS='-export-symbols-regex "^[[^_]].*"'
AC_SUBST(LIBTOOL_EXPORT_OPTIONS)

# Automake @VARIABLE@ exports.
AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)

# create output files
AC_OUTPUT([
csl.pc
Makefile
csl/Makefile
adapter/Makefile
tests/Makefile
examples/Makefile
doc/Makefile
])
