dnl This file is part of the FreeType project.
dnl
dnl Process this file with autoconf to produce a configure script.

AC_INIT(lib/freetype.h)

dnl Due to a bug in autoconf we must set $srcdir explicitly to an absolute
dnl path.
srcdir=`cd $srcdir; pwd`

AM_DISABLE_STATIC
AM_PROG_LIBTOOL

dnl FreeType version
freetype_version='1.2.0'

dnl libttf.so version
version_info='4:0:2'

AC_ARG_ENABLE(nls,
              [  --disable-nls           don't use NLS],
              USE_NLS=no, USE_NLS=yes)
AC_SUBST(USE_NLS)

dnl Checks for system type.
AC_CANONICAL_SYSTEM

dnl Checks for programs.
AC_PROG_CC
AC_PROG_CPP

dnl get Compiler flags right.

if test "x$CC" = xgcc; then
  XX_CFLAGS="-Wall -pedantic -ansi"
else
  case "$host" in
    *-dec-osf*)
      XX_CFLAGS="-std1 -O2 -g3"
      ;;
    *)
      XX_CFLAGS=
      ;;
  esac
fi
AC_SUBST(XX_CFLAGS)

dnl at least Digital UNIX 4.0d needs this due to a strange make program

case "$host" in
  *-dec-osf*)
    ln -s ../../MakeSub lib/arch
    ln -s ../../MakeSub test/arch
    ;;
esac

AC_SUBST(freetype_version)
AC_SUBST(version_info)

dnl gettext support
if test "$USE_NLS" = "yes"; then
  AC_REQUIRE([AC_PROG_MAKE_SET])
  AC_CHECK_HEADERS(locale.h)
  AC_CHECK_FUNCS(setlocale)
  AC_SUBST(HAVE_LOCALE_H)  

  ALL_LINGUAS="de fr cs nl es"
  AC_CHECK_HEADERS(libintl.h)
  AC_CHECK_LIB(intl,gettext)
  AC_SUBST(HAVE_LIBINTL_H)  
  AC_SUBST(HAVE_LIBINTL)

  dnl Handle localedir
  LOCALEDIR='${prefix}/share/locale'
  AC_ARG_WITH(locale-dir,
  [  --with-locale-dir=DIR   Location of the locale file(s)
                          [PREFIX/share/locale]],[
    if test x$withval = xyes; then
      AC_MSG_WARN(Usage is: --with-locale-dir=basedir)
    else
      if test x$withval = xno; then
        AC_MSG_WARN(Usage is: --with-locale-dir=basedir)
      else
        LOCALEDIR=$withval
      fi
    fi
  ])
  AC_SUBST(LOCALEDIR)

  AC_PATH_PROG(MSGFMT, msgfmt, $MSGFMT)
  if test -n "$MSGFMT"; then
    AC_CHECK_FUNCS(dcgettext)
    AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
    AC_PATH_PROG(XGETTEXT, xgettext, $XGETTEXT)
    AC_PATH_PROG(MSGMERGE, msgmerge, $MSGMERGE)

    dnl Test whether we really found GNU xgettext.
    if test -n "$XGETTEXT"; then
      if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
        : ;
      else
        AC_MSG_RESULT(
          [found xgettext program is not GNU xgettext; ignore it])
        XGETTEXT=""
      fi
    fi

    dnl We add another test for comparing GNU xgettext with openwin xgettext
    if test -n "$XGETTEXT"; then
      if $XGETTEXT --help > /dev/null 2> /dev/null; then
        : ;
      else
        AC_MSG_RESULT(
          [found xgettext program is not GNU xgettext; ignore it])
        XGETTEXT=""
      fi
    fi

    dnl Test whether we really found GNU msgfmt.
    if test -n "$MSGFMT"; then
      if $MSGFMT < /dev/null 2> /dev/null; then
        AC_MSG_RESULT(
          [found msgfmt program is not GNU msgfmt; NLS won't be installed])
        MSGFMT=""
      fi
    fi

    AC_TRY_LINK(,
                [extern int _nl_msg_cat_cntr;
                 return _nl_msg_cat_cntr],
                [CATOBJEXT=.gmo
                 DATADIRNAME=share],  
                [CATOBJEXT=.mo
                 DATADIRNAME=lib])
    INSTOBJEXT=.mo
  fi

  if test -n "$ALL_LINGUAS"; then
    for lang in $ALL_LINGUAS; do
      CATALOGS="$CATALOGS $lang$CATOBJEXT"
    done
  fi
  AC_SUBST(CATALOGS)
  AC_SUBST(CATOBJEXT)
  AC_SUBST(INSTOBJEXT)
  AC_SUBST(DATADIRNAME)
fi

dnl don't use NLS, when there is no gettext installed
if test x"$MSGFMT" = x; then
  USE_NLS=no
fi


AC_CHECK_PROG(RM, rm, rm)
AC_CHECK_PROG(RMDIR, rmdir, rmdir)
AC_PROG_INSTALL
AC_PROG_LN_S

dnl Checks for libraries.
sinclude(net.m4)
AC_LIBRARY_NET
AC_CHECK_LIB(m, cos)

dnl Checks for header files.
AC_PATH_XTRA
AC_CHECK_HEADERS(stdlib.h fcntl.h unistd.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)

dnl Checks for library functions.

dnl Here we check whether we can use our mmap file component.
AC_FUNC_MMAP
if test "$ac_cv_func_mmap_fixed_mapped" != yes; then
  TT_FILE_COMPONENT=ttfile.c
else
  TT_FILE_COMPONENT=arch/unix/ttmmap.c
fi
AC_SUBST(TT_FILE_COMPONENT)

AC_CHECK_FUNCS(memcpy memmove)

AC_CONFIG_HEADER(ft_conf.h)

dnl Another bug: to make --srcdir work correctly we have to create the
dnl directory hierarchy first since autoconf only uses mkdir.
$srcdir/mkinstalldirs lib/arch/unix test/arch/unix

AC_OUTPUT(Makefile
           MakeSub
           lib/arch/unix/Makefile
           test/arch/unix/Makefile 
           po/Makefile.in,
          [sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile])


dnl end of configure.in
