# Init autoconf (and check for presence of fribidi.c)
AC_INIT(fribidi.c)

ignore_trap=no
AC_ARG_ENABLE(trap,[  --disable-trap    ignore the configure trap],[
	if test "x$enableval" = "xno"; then
		ignore_trap=yes
	fi
])
if test $ignore_trap = no; then
	echo "The version of fribidi included with the AbiWord source is"
	echo "intended for use only for Win32 builds. On other operating"
	echo "systems you should get (at least) 0.10.4 from SourceForge:"
	echo ""
	echo "	http://sourceforge.net/projects/fribidi"
	echo ""
	AC_MSG_ERROR([specify --disable-trap to ignore this trap - if you must.])
fi

# Define different version variables.
#
# Making releases:
#   FRIBIDI_MICRO_VERSION++;
#   FRIBIDI_INTERFACE_AGE++;
#   FRIBIDI_BINARY_AGE++;
#   FRIBIDI_RPM_RELEASE = 0;
#
# If any major functions have been added:
#   FRIBIDI_INTERFACE_AGE = 0;
#   FRIBIDI_INTERFACE_VERSION++;
#
# If backwards compatibility has been broken:
#   FRIBIDI_BINARY_AGE = FRIBIDI_INTERFACE_AGE = 0;
#
# Building RPMs:
#   FRIBIDI_RPM_RELEASE++;
#
FRIBIDI_MAJOR_VERSION=0
FRIBIDI_MINOR_VERSION=10
FRIBIDI_MICRO_VERSION=4
FRIBIDI_INTERFACE_VERSION=2
FRIBIDI_INTERFACE_AGE=4
FRIBIDI_BINARY_AGE=4
FRIBIDI_RPM_RELEASE=0
FRIBIDI_VERSION=$FRIBIDI_MAJOR_VERSION.$FRIBIDI_MINOR_VERSION.$FRIBIDI_MICRO_VERSION

AC_SUBST(FRIBIDI_MAJOR_VERSION)
AC_SUBST(FRIBIDI_MINOR_VERSION)
AC_SUBST(FRIBIDI_MICRO_VERSION)
AC_SUBST(FRIBIDI_VERSION)
AC_SUBST(FRIBIDI_INTERFACE_VERSION)
AC_SUBST(FRIBIDI_INTERFACE_AGE)
AC_SUBST(FRIBIDI_BINARY_AGE)
AC_SUBST(FRIBIDI_RPM_RELEASE)

PACKAGE=fribidi
VERSION=$FRIBIDI_VERSION

AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE($PACKAGE, $VERSION)

dnl Checks for programs.
AC_PROG_AWK
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_PATH_PROG(SED, sed, $PATH)


dnl Checks for libraries

dnl Initialize libtool
AM_PROG_LIBTOOL


dnl Checks for header files.
AC_HEADER_STDC


dnl Checks for typedefs
AC_CHECK_SIZEOF(int, 2)
AC_CHECK_SIZEOF(char, 1)
AC_CHECK_SIZEOF(char*, 2)


dnl Checks for compiler characteristics

changequote(,)dnl
if test "x$GCC" = "xyes"; then
  case " $CFLAGS " in
  *[\ \	]-Wall[\ \	]*) ;;
  *) CFLAGS="$CFLAGS -Wall " ;;
  esac
fi
changequote([,])dnl

dnl Cygwin does not set srcdir to ".".
if test x$srcdir = x; then
  xsrcdir=.
else
  xsrcdir="$srcdir"
fi

dnl check for fribidi_tab_char_type_*.i files

for n in 2 3 4 5 6 7 8 9; do
  if test -f "${srcdir}/fribidi_tab_char_type_$n.i" ||
     test -f         "./fribidi_tab_char_type_$n.i"; then
    AC_DEFINE_UNQUOTED(HAS_FRIBIDI_TAB_CHAR_TYPE_${n}_I)
  fi
done

echo "creating fribidi_tab_char_type_stamp"
echo "time-stamp" > fribidi_tab_char_type_stamp


dnl Check for configure options

dnl --enable-debug
AC_ARG_ENABLE(debug, dnl
[  --enable-debug          turn debugging information on [default=no]],
[case "${enableval}" in
  yes) debug=true ;;  
  no)  debug=false ;;
  *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug) ;;
esac],[debug=false])
if test x"$debug" = xtrue; then
  AC_DEFINE(DEBUG)
fi

dnl --enable-malloc
AC_ARG_ENABLE(malloc, dnl
[  --enable-malloc         do not allocate chunks of memory  [default=no]],
[case "${enableval}" in
  yes) malloc=true ;;
  no)  malloc=false ;;
  *) AC_MSG_ERROR(bad value ${enableval} for --enable-malloc) ;;
esac],[malloc=false])
if test x"$malloc" = xtrue; then
  AC_DEFINE(USE_SIMPLE_MALLOC)
fi

dnl --enable-memopt
AC_ARG_ENABLE(memopt, dnl
[  --enable-memopt         optimize for memory usage [default=no]],
[case "${enableval}" in
  yes) memopt=true ;;
  no)  memopt=false ;;
  *) AC_MSG_ERROR(bad value ${enableval} for --enable-memopt) ;;
esac],[memopt=false])
if test x"$memopt" = xtrue; then
  AC_DEFINE(MEM_OPTIMIZED)
fi

dnl --without-charsets
AC_ARG_WITH(charsets, dnl
[  --without-charsets      exclude character set converters from library
                          causes command-line tool to use iconv],
[case "${withval}" in
  yes) charsets=true ;;
  no)  charsets=false ;;
  *) AC_MSG_ERROR(bad value ${withval} for --without-charsets) ;;
esac],[charsets=true])
if test x"$charsets" = xfalse; then
  AC_DEFINE(FRIBIDI_NO_CHARSETS)
  FRIBIDI_NO_CHARSETS=1
else
  FRIBIDI_NO_CHARSETS=0
fi
AC_SUBST(FRIBIDI_NO_CHARSETS)

AC_OUTPUT([
Makefile
fribidi_config.h
fribidi-config
fribidi.pc
fribidi.spec
],[case "$CONFIG_FILES" in
*fribidi-config*)chmod +x fribidi-config;;
esac])
