AC_INIT(texk/klibtool)

AC_CONFIG_AUX_DIR(config)
AC_SET_MAKE
AC_PROG_CC
AC_CANONICAL_SYSTEM

dnl Various compiler directives
dnl Various compiler directives
AC_MSG_CHECKING(whether to define additional compiler specific flags)
case "$target" in
    alpha*-dec*)
        if test "$CC" = "cc"; then
          CFLAGS="$CFLAGS -Olimit 1000 -std1"; export CFLAGS
          AC_MSG_WARN(Digital Unix's cc)
        fi
        ;;
    hp*hpux*)
        if test "$CC" = "cc"; then
          CFLAGS="$CFLAGS -Aa +e -D_HPUX_SOURCE"; export CFLAGS
          AC_MSG_WARN(HP-UX's cc)
        fi
        ;;
    *)
        AC_MSG_RESULT(no)
        ;;
esac

dnl We check this here, because otherwise some worse check (from ncurses?)
dnl is used instead for the cached value.
AC_HEADER_SYS_WAIT

AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_LN_S
AC_FUNC_ALLOCA
AC_PROG_RANLIB

sinclude(tetex.ac)
sinclude(withenable.ac)
sinclude(dialog/withenable.ac)
sinclude(texk/withenable.ac)
sinclude(texk/kpathsea/withenable.ac)
sinclude(texk/kpathsea/xt.ac)
sinclude(texk/web2c/withenable.ac)
sinclude(texk/xdvik/withenable.ac)
sinclude(libs/libwww/withenable.ac)
sinclude(libs/ncurses/withenable.ac)
sinclude(libs/libpng/withenable.ac)
sinclude(libs/zlib/withenable.ac)

LIBWWWDIR=libs/libwww
NCURSESDIR=libs/ncurses
LIBPNGDIR=libs/libpng
ZLIBDIR=libs/zlib

# we need libwww for xdvik and oxdvik
test ! -d $srcdir/$LIBWWWDIR  && : ${needs_libwww=no}
test "$with_xdvik"   != no    && : ${needs_libwww=yes}
test "$with_oxdvik"  != no    && : ${needs_libwww=yes}
: ${needs_libwww=no}

# we need ncurses for dialog
test ! -d $srcdir/$NCURSESDIR && : ${needs_ncurses=no}
test "$with_dialog"  != no    && : ${needs_ncurses=yes}
: ${needs_ncurses=no}

# we need pnglib for pdftex and pdfetex
test ! -d $srcdir/$LIBPNGDIR  && : ${needs_pnglib=no}
test "$with_pdftex"  != no    && : ${needs_pnglib=yes}
test "$with_pdfetex" != no    && : ${needs_pnglib=yes}
: ${needs_pnglib=no}

# we need zlib for texinfo, pdftex and pdfetex
test ! -d $srcdir/$ZLIBDIR    && : ${needs_zlib=no}
test "$with_pdftex"  != no    && : ${needs_zlib=yes}
test "$with_pdfetex" != no    && : ${needs_zlib=yes}
test "$with_texinfo" != no    && : ${needs_zlib=yes}
: ${needs_zlib=no}

export needs_ncurses needs_pnglib needs_zlib needs_libwww

dnl We cannot use variables (e.g. $LIBPNGDIR) for sinclude, so...
sinclude(libs/libpng/libpng.ac)
sinclude(libs/zlib/zlib.ac)
sinclude(libs/libwww/libwww.ac)
sinclude(libs/ncurses/ncurses.ac)

LIBSDEP="$LIBWWWDEP $CURSESDEP $ZLIBDEP $LIBPNGDEP"

LIBSDIRS=
test "$needs_libwww" = yes && test "$using_system_wwwlib"  != yes \
  && LIBSDIRS="$LIBWWWDIR $LIBSDIRS"
test "$needs_ncurses" = yes && test "$using_system_ncurses" != yes \
  && LIBSDIRS="$NCURSESDIR $LIBSDIRS"
test "$needs_pnglib" = yes && test "$using_system_pnglib" != yes \
  && LIBSDIRS="$LIBPNGDIR $LIBSDIRS"
test "$needs_zlib" = yes && test "$using_system_zlib" != yes \
  && LIBSDIRS="$ZLIBDIR $LIBSDIRS"

PKGS='texinfo dialog t1utils'
ESUBDIRS=
for pkg in $PKGS; do
  if test -d $srcdir/$pkg; then
    if eval "test \"`echo '$with_'${pkg}`\" != no"; then
      ESUBDIRS="$ESUBDIRS $pkg"
    fi
  fi
done

AC_SUBST(ESUBDIRS)
AC_SUBST(LIBSDEP)
AC_SUBST(LIBSDIRS)

AC_CONFIG_SUBDIRS(libs $ESUBDIRS texk)
AC_OUTPUT(Makefile)
