dnl
dnl Binary distribution configure script
dnl
#!/bin/sh
#

AC_INIT(Makefile.in)

#
# First off, what system are we running under?
#
AC_CANONICAL_SYSTEM

dnl ** canonicalize platform names
# Canonicali[sz]e the platform name
TargetPlatform=`/bin/sh $srcdir/config.sub $target` || exit 1

#
# The following will be more difficult when we *are* cross-compiling.
# Suitable names to slam in *_CPP are in platform.h.in.
# We also record the architecture, vendor, and operating system (OS)
# separately.
case $HostPlatform in
alpha-dec-osf[[1234]]*)
	TargetPlatform=alpha-dec-osf1;;
hppa1.1-hp-hpux*)
	TargetPlatform=hppa1.1-hp-hpux;;
i[[3456]]86-*-linuxaout*)
	TargetPlatform=i386-unknown-linuxaout;;
i[[3456]]86-*-linux*)
	TargetPlatform=i386-unknown-linux;;
i[[3456]]86-*-freebsd*)
	TargetPlatform=i386-unknown-freebsd;;
i[[3456]]86-*-netbsd*)
	TargetPlatform=i386-unknown-netbsd;;
i[[3456]]86-*-solaris2*)
	TargetPlatform=i386-unknown-solaris2;;
i[[3456]]86-*-cygwin32*)
	TargetPlatform=i386-unknown-cygwin32;;
m68k-next-nextstep2)
	TargetPlatform=m68k-next-nextstep2;;
m68k-next-nextstep3)
	TargetPlatform=m68k-next-nextstep3;;
i[[3456]]86-next-nextstep3)
	TargetPlatform=i386-next-nextstep3
m68k-sun-sunos4*)
	TargetPlatform=m68k-sun-sunos4 #hack
mips-dec-ultrix*)
        TargetPlaformP=mips-dec-ultrix;;
mips-sgi-irix*)
	TargetPlatform=mips-sgi-irix;;
powerpc-ibm-aix*)
	TargetPlatform=powerpc-ibm-aix;;
sparc-sun-sunos4*)
	TargetPlatform=sparc-sun-sunos4;;
sparc-sun-solaris2*)
	TargetPlatform=sparc-sun-solaris2;;
*)
        echo "Unrecognised platform: $TargetPlatform"
        exit 1
        ;;
esac
echo "Which we'll canonicalise into: $TargetPlatform"

platform=$TargetPlatform
AC_SUBST(platform)

AC_CHECK_PROG(PerlCmd,perl,$ac_dir/$ac_word)
if test -z "$PerlCmd"; then
    echo "You must install perl before you can continue"
    echo "Perhaps it is already installed, but not in your PATH?"
    exit 1
else
    $PerlCmd -v >conftest.out 2>&1
    if egrep "version 4" conftest.out >/dev/null 2>&1; then
        if egrep "Patch level: 35" conftest.out >/dev/null 2>&1; then
            echo "
************************************************************************
Uh-oh...looks like you have Perl 4.035.

Perl version 4.035 has a bug to do with recursion that will bite if
you run the lit2texi script, when making Info files from
literate files of various sorts.  Either use the current version
(4.036), an older version (e.g., perl 4.019) or apply the patch in
glafp-utils/perl-4.035-fixes to your 4.035 perl.
************************************************************************
"
        fi
    else
	if egrep "version 5" conftest.out >/dev/null 2>&1; then
	    :
	else
	    echo "I'm not sure if your version of perl will work,"
	    echo "but it's worth a shot, eh?"
	fi
    fi
    rm -fr conftest*
fi
#
dnl ** does #!.../perl work? (sometimes it's too long...)
echo "checking if \`#!$PerlCmd' works in shell scripts"
echo "#!$PerlCmd"'
exit $1;
' > conftest
chmod u+x conftest
(SHELL=/bin/sh; export SHELL; ./conftest 69 > /dev/null)
if test $? -ne 69; then
   echo "It does!"
else
   echo "It doesn't!  Perhaps \`#!$PerlCmd' is too long (often 32 characters max)"
   exit 1
fi
rm -f conftest
#
dnl ** check if perl library is properly installed
# (by seeing if a "do 'getopts.pl'" works...
if $PerlCmd -e 'do "getopts.pl" || exit(1); exit(0);' > /dev/null 2>&1 ; then
    :
else
    echo "I think your perl library is misinstalled."
    echo "The following script did not work:"
    echo '      do "getopts.pl" || exit(1); exit(0);'
    exit 1
fi

dnl ** figure out how to do a BSD-ish install
#
AC_PROG_INSTALL
#


AC_OUTPUT(Makefile)

