dnl Public domain.  Originally written many years ago by Karl Berry and
dnl Thomas Esser, and others.
dnl
dnl Top-level configure for kpathsea-using programs.
dnl Our job is to run configure in the relevant subdirectories.
dnl
dnl Assumption: each program will create a c-auto.h that defines
dnl everything kpathsea needs.  We arrange this by including (at
dnl autoconf time) kpathsea/common.ac.
dnl 
dnl Consequence: we don't need to run configure in the kpathsea directory
dnl itself; we can just copy from a program directory.  We'll use the
dnl first one.
dnl 
AC_INIT(kpathsea/kpathsea.texi)

dnl These configure scripts won't work with anything else.
AC_PREREQ(2.13)

AC_PROG_MAKE_SET

dnl Because we include make/common.make.
AC_PROG_CC
AC_ISC_POSIX
AC_PROG_LN_S

dnl If we guessed the prefix in the subdirectories, it might guess
dnl differently than the prefix here, and that would cause confusion.
AC_PREFIX_PROGRAM(tex)

dnl Pass this down from the top level so that when the subprograms
dnl install kpathsea a command line value is propagated.
AC_PROG_INSTALL

dnl If the other programs ever acquire their own --with or --enable
dnl options, they must be added, so configure --help at the top level
dnl will show all the options.
sinclude(libtool.m4)
sinclude(withenable.ac)
sinclude(kpathsea/withenable.ac)
sinclude(web2c/withenable.ac)
sinclude(xdvik/withenable.ac)

AC_PROG_LIBTOOL

if test "x$with_x" = xno; then
  with_xdvik=no
fi

PKGS='
 afm2pl
 bibtex8
 cjkutils
 detex
 devnag
 dtl 
 dvi2tty
 dvidvi
 dviljk
 dvipdfm
 dvipdfmx
 dvipng
 dvipos
 dvipsk
 gsftopk
 lacheck
 makeindexk
 musixflx
 ps2pkm
 seetexk
 tetex
 tex4htk
 texlive
 ttf2pk
 tth
 xdv2pdf
 xdvik
 xdvipdfmx
'

ESUBDIRS=
for pkg in $PKGS; do
  if eval "test \"x`echo '$with_'${pkg}`\" != xno"; then
    ESUBDIRS="$ESUBDIRS $pkg"

    if test "$pkg" = dvipos; then
      # attempt to discover if srcdir = builddir.
      dir_src=`cd $srcdir/dvipos && /bin/pwd`
      dir_work=`/bin/pwd`/dvipos  # may not exist, so don't cd
      echo "testing configure kludge for dvipos..."
      if test "$dir_src" != "$dir_work"; then
        # this is a terrible kludge, but dvipos has no real configure
        # and it is claimed crucial for context.
        # So copy the entire sam2p srcdir into objdir.
        rm -rf $dir_work
        mkdir $dir_work
        cp -pr $dir_src/* $dir_work/  # omit .svn
        echo "  copied dvipos dir_src ($dir_src) dir_work ($dir_work)"
      fi
    fi
  fi
done
AC_SUBST(ESUBDIRS)

AC_CONFIG_SUBDIRS(kpathsea web2c $ESUBDIRS)

KPSE_CONFIG_FILES([Makefile])
AC_OUTPUT
