+}], fptools_cv_lead_uscore=yes, fptools_cv_lead_uscore=no, fptools_cv_lead_uscore=NO)
+;;
+esac);
+LeadingUnderscore=`echo $fptools_cv_lead_uscore | sed 'y/yesno/YESNO/'`
+AC_SUBST(LeadingUnderscore)
+case $LeadingUnderscore in
+YES) AC_DEFINE(LEADING_UNDERSCORE);;
+esac
+])
+
+dnl
+dnl FPTOOLS_PROG_CHECK_VERSION(VERSIONSTR1, TEST, VERSIONSTR2,
+dnl ACTION-IF-TRUE [, ACTION-IF-FALSE])
+dnl
+dnl compare versions field-wise (separator is '.')
+dnl TEST is one of {-lt,-le,-eq,-ge,-gt}
+dnl
+dnl quite shell-independant and SUSv2 compliant code
+dnl
+dnl NOTE: the loop could be unrolled within autoconf, but the
+dnl macro code would be a) longer and b) harder to debug... ;)
+dnl
+AC_DEFUN(FPTOOLS_PROG_CHECK_VERSION,
+[if ( IFS=".";
+ a="[$1]"; b="[$3]";
+ while test -n "$a$b"
+ do
+ set -- [$]a; h1="[$]1"; shift 2>/dev/null; a="[$]*"
+ set -- [$]b; h2="[$]1"; shift 2>/dev/null; b="[$]*"
+ test -n "[$]h1" || h1=0; test -n "[$]h2" || h2=0
+ test [$]{h1} -eq [$]{h2} || break
+ done
+ test [$]{h1} [$2] [$]{h2}
+ )
+then ifelse([$4],,[:],[
+ $4])
+ifelse([$5],,,
+[else
+ $5])
+fi
+])])dnl
+
+
+dnl
+dnl Check for Greencard and version.
+dnl
+AC_DEFUN(FPTOOLS_GREENCARD,
+[
+AC_PATH_PROG(GreencardCmd,greencard)
+AC_CACHE_CHECK([for version of greencard], fptools_cv_greencard_version,
+changequote(, )dnl
+[if test x"$GreencardCmd" != x; then
+ fptools_cv_greencard_version="`$GreencardCmd --version |
+ grep 'version' | sed -e 's/greencard. version \([^ ]*\).*/\1/g'`"
+else
+ fptools_cv_greencard_version=""
+fi
+changequote([, ])dnl
+])
+FPTOOLS_PROG_CHECK_VERSION([$fptools_cv_greencard_version],-lt,$1,
+ [AC_MSG_ERROR([greencard version $1 or later is required (found '$fptools_cv_greencard_version')])])dnl
+GreencardVersion=$fptools_cv_greencard_version
+AC_SUBST(GreencardVersion)
+])
+
+dnl
+dnl Check for Happy and version. If we're building GHC, then we need
+dnl at least Happy version 1.13. If there's no installed Happy, we look
+dnl for a happy source tree and point the build system at that instead.
+dnl
+AC_DEFUN(FPTOOLS_HAPPY,
+[
+if test -d $srcdir/happy; then
+ SrcTreeHappyCmd=$hardtop/happy/src/happy-inplace
+fi
+if test x"$UseSrcTreeHappy" = xYES; then
+ HappyCmd=$SrcTreeHappyCmd
+else
+ AC_PATH_PROG(HappyCmd,happy,$SrcTreeHappyCmd)
+fi
+AC_CACHE_CHECK([for version of happy], fptools_cv_happy_version,
+changequote(, )dnl
+[if test x"$HappyCmd" = x"$SrcTreeHappyCmd"; then
+ fptools_cv_happy_version=`grep '^ProjectVersion[ ]*=' $srcdir/happy/mk/version.mk | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`;
+elif test x"$HappyCmd" != x; then
+ fptools_cv_happy_version="`$HappyCmd -v |
+ grep 'Happy Version' | sed -e 's/Happy Version \([^ ]*\).*/\1/g'`" ;
+else
+ fptools_cv_happy_version="";
+fi;
+changequote([, ])dnl
+])
+if test -d $srcdir/ghc -a ! -f $srcdir/ghc/compiler/parser/Parser.hs; then
+ FPTOOLS_PROG_CHECK_VERSION([$fptools_cv_happy_version],-lt,[1.13],
+ [AC_MSG_ERROR([Happy version 1.13 or later is required to compile GHC.])])dnl
+fi
+HappyVersion=$fptools_cv_happy_version;
+AC_SUBST(HappyVersion)
+])
+
+dnl
+dnl Check for Haddock and version. If there's no installed Haddock, we look
+dnl for a haddock source tree and point the build system at that instead.
+dnl
+AC_DEFUN(FPTOOLS_HADDOCK,
+[
+if test -d $srcdir/haddock; then
+ SrcTreeHaddockCmd=$hardtop/haddock/src/haddock-inplace
+fi
+if test x"$UseSrcTreeHaddock" = xYES; then
+ HaddockCmd=$SrcTreeHaddockCmd
+else
+ AC_PATH_PROG(HaddockCmd,haddock,$SrcTreeHaddockCmd)
+fi
+dnl Darn, I forgot to make Haddock print out its version number when
+dnl invoked with -v. We could try generating some HTML and grepping
+dnl through that to find the version number, but I think we'll make
+dnl do without it for now.
+])
+
+dnl
+dnl What's the best way of doing context diffs?
+dnl
+dnl (NB: NeXTStep thinks diff'ing a file against itself is "trouble")
+dnl
+AC_DEFUN(FPTOOLS_PROG_DIFF,
+[AC_CACHE_CHECK([for ok way to do context diffs], fptools_cv_context_diffs,
+[echo foo > conftest1
+echo foo > conftest2
+if diff -C 1 conftest1 conftest2 > /dev/null 2>&1 ; then
+ fptools_cv_context_diffs='diff -C 1'
+else
+ if diff -c1 conftest1 conftest2 > /dev/null 2>&1 ; then
+ fptools_cv_context_diffs='diff -c1'
+ else
+ echo "Can't figure out how to do context diffs."
+ echo "Neither \`diff -C 1' nor \`diff -c1' works."
+ exit 1
+ fi
+fi
+rm -f conftest1 conftest2
+])
+ContextDiffCmd=$fptools_cv_context_diffs
+AC_SUBST(ContextDiffCmd)
+])
+
+dnl
+dnl Check whether ld supports -x
+dnl
+AC_DEFUN(FPTOOLS_LD_X,
+[AC_CACHE_CHECK([whether ld understands -x], fptools_cv_ld_x,
+[
+echo 'foo() {}' > conftest.c
+${CC-cc} -c conftest.c
+if ${LdCmd} -r -x -o foo.o conftest.o; then
+ fptools_cv_ld_x=yes
+else
+ fptools_cv_ld_x=no
+fi
+rm -rf conftest.c conftest.o foo.o
+])
+if test "$fptools_cv_ld_x" = yes; then
+ LdXFlag=-x
+else
+ LdXFlag=
+fi
+AC_SUBST(LdXFlag)
+])
+
+dnl
+dnl Finding the Right Yacc
+dnl
+AC_DEFUN(FPTOOLS_PROG_YACCY,
+[AC_PROG_YACC
+if test "$YACC" = "yacc"; then
+ AC_CACHE_CHECK([if it is an OK yacc], ac_cv_prog_yacc,
+ [AC_CHECK_PROG(WhatCmd, what, what, :)
+ $WhatCmd $YACC > conftest.out
+ if egrep 'y1\.c 1\..*SMI' conftest.out >/dev/null 2>&1; then
+ echo "I don't trust your $YaccCmd; it looks like an old Sun yacc"
+ if test -f /usr/lang/yacc; then
+ echo "I'm going to use /usr/lang/yacc instead"
+ ac_cv_prog_yacc=/usr/lang/yacc
+ else
+ echo "I'm assuming the worst...no parser generator at all"
+ ac_cv_prog_yacc=:
+ fi
+ elif egrep 'y1\.c.*Revision: 4\.2\.6\.3.*DEC' conftest.out >/dev/null 2>&1; then
+ echo "I don't trust your $YaccCmd; it looks like a lame DEC yacc"
+ echo "I'm assuming the worst...no parser generator at all"
+ ac_cv_prog_yacc=:
+ else
+ ac_cv_prog_yacc=$YACC
+ fi
+ rm -fr conftest*
+])
+else
+ ac_cv_prog_yacc=$YACC
+fi
+YaccCmd=$ac_cv_prog_yacc
+AC_SUBST(YaccCmd)
+])
+
+dnl *** Checking for ar and its arguments + whether we need ranlib.
+dnl
+dnl ArCmd, ArSupportsInput and RANLIB are AC_SUBST'ed
+dnl On Digital UNIX, we test for the -Z (compress) and
+dnl -input (take list of files from external file) flags.
+dnl
+AC_DEFUN(FPTOOLS_PROG_AR_AND_RANLIB,
+[AC_PATH_PROG(ArCmdRaw,ar)
+if test -z "$ArCmdRaw"; then
+ echo "You don't seem to have ar in your PATH...I have no idea how to make a library"
+ exit 1;
+fi
+dnl GNU ar needs special treatment: it appears to have problems with
+dnl object files with the same name if you use the 's' modifier, but
+dnl simple 'ar q' works fine, and doesn't need a separate ranlib.
+if $ArCmdRaw --version | grep 'GNU' >/dev/null 2>/dev/null; then
+ ArCmdArgs='q'
+ NeedRanLib=''
+elif $ArCmdRaw clqsZ conftest.a >/dev/null 2>/dev/null; then
+ ArCmdArgs="clqsZ"
+ NeedRanLib=''
+elif $ArCmdRaw clqs conftest.a >/dev/null 2>/dev/null; then
+ ArCmdArgs="clqs"
+ NeedRanLib=''
+elif $ArCmdRaw cqs conftest.a >/dev/null 2>/dev/null; then
+ ArCmdArgs="cqs"
+ NeedRanLib=''
+elif $ArCmdRaw clq conftest.a >/dev/null 2>/dev/null; then
+ ArCmdArgs="clq"
+ NeedRanLib='YES'
+elif $ArCmdRaw cq conftest.a >/dev/null 2>/dev/null; then
+ ArCmdArgs="cq"
+ NeedRanLib='YES'
+elif $ArCmdRaw cq conftest.a 2>&1 | grep 'no archive members specified' >/dev/null 2>/dev/null; then
+ ArCmdArgs="cq"
+ NeedRanLib='YES'
+else
+ echo "I can't figure out how to use your $ArCmd"
+ exit 1
+fi
+rm -rf conftest*
+case $HostPlatform in
+ *mingw32)
+ ArCmd="`cygpath -w ${ArCmdRaw} | sed -e 's@\\\\@/@g' ` ${ArCmdArgs}"
+ ;;
+ *) ArCmd="${ArCmdRaw} ${ArCmdArgs}"
+ ;;
+esac
+test -n "$ArCmd" && test -n "$verbose" && echo " setting ArCmd to $ArCmd"
+AC_SUBST(ArCmd)
+if $ArCmd conftest.a -input /dev/null >/dev/null 2>/dev/null; then
+ ArSupportsInput='-input'
+else
+ ArSupportsInput=''
+fi
+rm -rf conftest*
+test -n "$ArSupportsInput" && test -n "$verbose" && echo " setting ArSupportsInput to $ArSupportsInput"
+AC_SUBST(ArSupportsInput)
+if test -z "$NeedRanLib"; then
+ RANLIB=':'
+ test -n "$verbose" && echo " setting RANLIB to $RANLIB"
+ AC_SUBST(RANLIB)
+else
+ AC_PROG_RANLIB
+fi
+])
+
+dnl
+dnl AC_SHEBANG_PERL - can we she-bang perl?
+dnl
+AC_DEFUN(FPTOOLS_SHEBANG_PERL,
+[AC_CACHE_CHECK([if your perl works in shell scripts], fptools_cv_shebang_perl,
+[echo "#!$PerlCmd"'
+exit $1;
+' > conftest
+chmod u+x conftest
+(SHELL=/bin/sh; export SHELL; ./conftest 69 > /dev/null)
+if test $? -ne 69; then
+ fptools_cv_shebang_perl=yes
+else
+ fptools_cv_shebang_perl=no
+fi
+rm -f conftest
+])])
+
+dnl
+dnl Extra testing of the result AC_PROG_CC, testing the gcc version no.
+dnl *Must* be called after AC_PROG_CC
+dnl
+AC_DEFUN(FPTOOLS_HAVE_GCC,
+[AC_CACHE_CHECK([whether you have an ok gcc], fptools_cv_have_gcc,
+[if test -z "$GCC"; then
+ echo ''
+ echo "You would be better off with gcc"
+ echo "Perhaps it is already installed, but not in your PATH?"
+ fptools_cv_have_gcc='no'
+else
+changequote(, )dnl
+ gcc_version_str="`$CC -v 2>&1 | grep 'version ' | sed -e 's/.*version [^0-9]*\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1\.\2/g' `"
+changequote([, ])dnl
+ fptools_cv_have_gcc='yes'
+ FPTOOLS_PROG_CHECK_VERSION($gcc_version_str, -lt, "2.0",
+ fptools_cv_have_gcc='no'
+ echo ""
+ echo "your gcc version appears to be ..."
+ $CC --version
+ echo "gcc prior to 2.0 and have never worked with ghc."
+ echo "we recommend 2.95.3, although versions back to 2.7.2 should be ok."
+ AC_MSG_ERROR([gcc 1.X has never been supported])
+ )
+fi
+])
+HaveGcc=`echo $fptools_cv_have_gcc | sed 'y/yesno/YESNO/'`
+AC_SUBST(HaveGcc)
+])
+
+dnl
+dnl Some OSs (Mandrake Linux, in particular) configure GCC with
+dnl -momit-leaf-frame-pointer on by default. If this is the case, we
+dnl need to turn it off for mangling to work. The test is currently a bit
+dnl crude, using only the version number of gcc.
+dnl
+AC_DEFUN(FPTOOLS_GCC_NEEDS_NO_OMIT_LFPTR,
+[AC_CACHE_CHECK([whether gcc needs -mno-omit-leaf-frame-pointer], fptools_cv_gcc_needs_no_omit_lfptr,
+[
+ fptools_cv_gcc_needs_no_omit_lfptr='no'
+ FPTOOLS_PROG_CHECK_VERSION($gcc_version_str, -ge, "3.2",
+ fptools_cv_gcc_needs_no_omit_lfptr='yes')
+])
+if test "$fptools_cv_gcc_needs_no_omit_lfptr" = "yes"; then
+ AC_DEFINE(HAVE_GCC_MNO_OMIT_LFPTR)
+fi
+])
+
+dnl Small feature test for perl version. Assumes PerlCmd
+dnl contains path to perl binary
+dnl
+AC_DEFUN(FPTOOLS_CHECK_PERL_VERSION,
+[$PerlCmd -v >conftest.out 2>&1
+if grep "version 5" conftest.out >/dev/null 2>&1; then
+ :
+else
+ if grep "v5.6" conftest.out >/dev/null 2>&1; then
+ :
+ else
+ if grep "v5.8" conftest.out >/dev/null 2>&1; then
+ :
+ else
+ if grep "version 6" conftest.out >/dev/null 2>&1; then
+ :
+ else
+ echo "Your version of perl probably won't work."
+ fi
+ fi
+ fi
+fi
+rm -fr conftest*
+])
+
+dnl
+dnl Getting at the right version of 'find'
+dnl (i.e., not the MS util on a Win32 box).
+dnl
+AC_DEFUN(FPTOOLS_FIND_FIND,
+[
+AC_PATH_PROG(Find2Cmd, find)
+$Find2Cmd --version > conftest.out 2>&1
+if grep "FIND: Parameter format" conftest.out >/dev/null 2>&1 ; then
+ # Encountered MS' find utility, which is not what we're after.
+ #
+ # HACK - AC_CHECK_PROG is useful here in that does let you reject
+ # an (absolute) entry in the path (Find2Cmd). It is not so useful
+ # in that it doesn't let you (AFAIU) set VARIABLE equal to the
+ # absolute path eventually found. So, hack around this by inspecting
+ # what variables hold the abs. path & use them directly.
+ AC_CHECK_PROG(FindCmd,find,`echo $ac_dir/$ac_word`,find,,$Find2Cmd)
+else
+FindCmd=$Find2Cmd
+AC_SUBST(FindCmd)
+fi
+])
+
+dnl
+dnl FPTOOLS_NOCACHE_CHECK prints a message, then sets the
+dnl values of the second argument to the result of running
+dnl the commands given by the third. It does not cache its
+dnl result, so it is suitable for checks which should be
+dnl run every time.
+dnl
+AC_DEFUN(FPTOOLS_NOCACHE_CHECK,
+[AC_MSG_CHECKING([$1])
+ $3
+ AC_MSG_RESULT([$][$2])
+])
+
+dnl
+dnl FPTOOLS_GHC_VERSION(version)
+dnl FPTOOLS_GHC_VERSION(major, minor [, patchlevel])
+dnl FPTOOLS_GHC_VERSION(version, major, minor, patchlevel)
+dnl
+dnl Test for version of installed ghc. Uses $GHC.
+dnl [original version pinched from c2hs]
+dnl
+AC_DEFUN(FPTOOLS_GHC_VERSION,
+[FPTOOLS_NOCACHE_CHECK([version of ghc], [fptools_version_of_ghc],
+["${WithGhc-ghc}" --version > conftestghc 2>&1
+ cat conftestghc >&AC_FD_CC
+#Useless Use Of cat award...
+ fptools_version_of_ghc=`cat conftestghc | sed -n -e 's/, patchlevel *\([[0-9]]\)/.\1/;s/.* version \([[0-9]][[0-9.]]*\).*/\1/p'`
+ rm -fr conftest*
+ if test "[$]fptools_version_of_ghc" = ""
+ then
+ fptools_version_of_ghc='unknown'
+ fi
+fptools_version_of_ghc[_major]=`echo [$]fptools_version_of_ghc | sed -e 's/^\([[0-9]]\).*/\1/'`
+fptools_version_of_ghc[_minor]=`echo [$]fptools_version_of_ghc | sed -e 's/^[[0-9]]\.\([[0-9]]*\).*/\1/'`
+fptools_version_of_ghc[_pl]=`echo [$]fptools_version_of_ghc | sed -n -e 's/^[[0-9]]\.[[0-9]]*\.\([[0-9]]*\)/\1/p'`