dnl Process this file with autoconf to produce a configure script.
AC_INIT(Makefile.in)

dnl We use a path for perl so the #! line in autoscan will work.
AC_SUBST(PERL)dnl
AC_SUBST(INSTALL)dnl
AC_PROG_INSTALL

PACKAGE=apsfilter
VERSION=1.1.1
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
AC_SUBST(PACKAGE)
AC_SUBST(VERSION)

AC_PATH_PROG(PERL5, perl5, no)
AC_PATH_PROG(PERL, perl, no)
if test "$PERL5" = no; then
  AC_MSG_WARN(did not find perl5)
	if test "$PERL" = no; then
	  AC_MSG_WARN(did not find perl as well)
	  exit 1;
	fi
    dnl check the version of perl
   V=`$PERL -v | sed -n -e '/version/s/.*version./version/' \
		-e '/version/s/\..*//' -e s/version//p`;
	if test $V lt 5; then
	  AC_MSG_WARN(perl version too low)
	  exit 1;
    fi;
	PERL5=$PERL;
fi
PERL=$PERL5

AC_SUBST(GS)dnl
AC_PATH_PROG(GS, gs, no)
if test "$GS" = no; then
  AC_MSG_WARN(did not find gs)
fi;
AC_SUBST(A2PS)dnl
AC_PATH_PROG(A2PS, a2ps, no)
if test "$A2PS" = no; then
  AC_MSG_WARN(did not find a2ps)
fi;
AC_SUBST(DJPEG)dnl
AC_PATH_PROG(DJPEG, djpeg, no)
if test "$DJPEG" = no; then
  AC_MSG_WARN(did not find djpeg)
fi;
AC_SUBST(DVIPS)dnl
AC_PATH_PROG(DVIPS, dvips, no)
if test "$DVIPS" = no; then
  AC_MSG_WARN(did not find dvips)
fi;
AC_SUBST(FCAT)dnl
AC_PATH_PROG(FCAT, fcat, no)
if test "$FCAT" = no; then
  AC_MSG_WARN(did not find fcat)
fi;
AC_SUBST(FIG2DEV)dnl
AC_PATH_PROG(FIG2DEV, fig2dev, no)
if test "$FIG2DEV" = no; then
  AC_MSG_WARN(did not find fig2dev)
fi;
AC_SUBST(GIFTOPNM)dnl
AC_PATH_PROG(GIFTOPNM, giftopnm, no)
if test "$GIFTOPNM" = no; then
  AC_MSG_WARN(did not find giftopnm)
fi;
AC_SUBST(GZIP)dnl
AC_PATH_PROG(GZIP, gzip, no)
if test "$GZIP" = no; then
  AC_MSG_WARN(did not find gzip)
fi;
AC_SUBST(PNMTOPS)dnl
AC_PATH_PROG(PNMTOPS, pnmtops, no)
if test "$PNMTOPS" = no; then
  AC_MSG_WARN(did not find pnmtops)
fi;
AC_SUBST(PPMTOPGM)dnl
AC_PATH_PROG(PPMTOPGM, ppmtopgm, no)
if test "$PPMTOPGM" = no; then
  AC_MSG_WARN(did not find ppmtopgm)
fi;
AC_SUBST(RASTTOPNM)dnl
AC_PATH_PROG(RASTTOPNM, rasttopnm, no)
if test "$RASTTOPNM" = no; then
  AC_MSG_WARN(did not find rasttopnm)
fi;
AC_SUBST(TIFFTOPNM)dnl
AC_PATH_PROG(TIFFTOPNM, tifftopnm, no)
if test "$TIFFTOPNM" = no; then
  AC_MSG_WARN(did not find tifftopnm)
fi;
AC_SUBST(ZCAT)dnl
AC_PATH_PROG(ZCAT, zcat, no)
if test "$ZCAT" = no; then
  AC_MSG_WARN(did not find zcat)
fi;

AC_SUBST(FILEPROG)dnl
AC_PATH_PROG(FILEPROG, file, no)
if test "$FILEPROG" = no; then
  AC_MSG_WARN(did not find file)
  exit 1;
fi;

FILEOPTS="-";
CMD="$FILEPROG $FILEOPTS";
echo "Trying '$CMD'";
text=`echo hi | $CMD | sed -n 's/.*text.*/yes/p'`;
if test -z "$text" ; then
	FILEOPTS="";
	CMD="$FILEPROG $FILEOPTS";
	echo "Trying '$CMD'";
	text=`echo hi | $CMD | sed -n 's/.*text.*/yes/p'`;
	if test -z "$text" ; then
		echo "cannot guess what options $FILEPROG wants";
		exit 1;
	fi;
fi;
FILEPROG="$FILEPROG $FILEOPTS"
export FILEPROG

AC_OUTPUT(Makefile apsfilter.pl setup.pl)
