# This file is a shell script fragment that supplies the information
# necessary to tailor a template configure script into the configure
# script appropriate for this directory.  For more information, check
# any existing configure script.

subdirs="genclass src iostream iostream/stdio iostream/test no-stream old-stream tests etc etc/graph etc/ADT-examples etc/benchmarks etc/lf etc/PlotFile3D etc/trie-gen etc/fib gperf gperf/src gperf/tests utils test-install"
srctrigger=libg++.texinfo
srcname="GNU C++ Class Library"

# per-host:

case "${host}" in
  i[34]86-*-linux) my_host=linux ;;
  *-*-hpux*)       my_host=hpux ;;
  *-*-solaris2)    my_host=solaris2 ;;
  *-*-*)           my_host=${host_cpu}
esac

host_makefile_frag=config/${my_host}.mh

if [ ! -f ${srcdir}/${host_makefile_frag} ] ; then
	host_makefile_frag=${host_alias}.mh
	echo "No pre-existing host_makefile_frag config/${my_host}.mh for ${host_alias}."
	echo "Generating one in ${host_makefile_frag}"
	if [ ${host_alias} != ${target_alias} ] ; then
	    # Actually, this should work in principle when cross-compiling,
	    # but you need to make sure you have reasonable values
	    # for CC, CONFIG_NM
	    echo "WARNING: This probably won't work if you're cross-compiling!"
	fi

	rootme=`pwd`
	export rootme
	CC=${CC-`if [ -f ${rootme}/../gcc/gcc ] ; \
        	then echo ${rootme}/../gcc/gcc -B${rootme}/../gcc/ ; \
        	else echo gcc ; fi`}
	CONFIG_NM=${CONFIG_NM-nm}

	echo checking for install
	echo "Testing" >FOO1
	if (install -c -m 644 FOO1 FOO2 && cmp -s FOO1 FOO2)>/dev/null 2>&1 ;
	then
	    test -z "$INSTALL" && INSTALL="install -c"
	    test -z "$INSTALL_DATA" && INSTALL_DATA="install -c -m 644"
	elif (/usr/ucb/install -c -m 644 FOO1 FOO2 && cmp -s FOO1 FOO2)>/dev/null 2>&1 ; then
	    test -z "$INSTALL" && INSTALL="/usr/ucb/install -c"
	    test -z "$INSTALL_DATA" && INSTALL_DATA="/usr/ucb/install -c -m 644"
	fi
	rm -f FOO1 FOO2
	    
	echo "INSTALL = ${INSTALL-cp}
INSTALL_DATA = ${INSTALL_DATA-cp}" >${host_makefile_frag}

	# The Bourne shell writes "command not found" to /dev/tty, so if we get
	# a usage message on stderr, we have the program.
	#
	# ksh and zsh write "command not found" to stderr, but test -n does not
	# want any output if there is no program.  So we use the `type' builtin
	# instead for them (and bash).
	if test "$RANDOM" = "$RANDOM"; then
	  checkfor='test -n "`$checkprog $checkargs 2>&1`"'
	else
	  checkfor='type $checkprog >/dev/null'
	fi

	echo checking for ranlib
	checkprog=ranlib checkargs=/dev/null
	if [ -n "$RANLIB" ] ; then
	    echo "RANLIB = ${RANLIB}" >>${host_makefile_frag}
	elif (eval $checkfor) >/dev/null 2>&1 ; then
	    # Use default value set in Makefile
	    echo "# RANLIB = ranlib" >>${host_makefile_frag}
	else
	    echo "RANLIB = true" >>${host_makefile_frag}
	fi


	echo checking if -nostdinc++ flag works
	echo "int foo;" >temp.c
	echo "# Use -nostdinc++ flag if your version of gcc understands it."\
	    >>${host_makefile_frag}
	if [ "`${CC} -c -nostdinc++ temp.c 2>&1`" = "" ]; then
	    echo 'NOSTDINC = -nostdinc++' >>${host_makefile_frag}
	else
	    echo 'NOSTDINC = # -nostdinc++' >>${host_makefile_frag}
	fi

	# Recent SVR4 system wrap extern "C" around function declarations
	# in the system C header files.  Unfortunately, some SYSV systems
	# (such as Irix) miss the extern "C" in curses.h, say,
	# though they have it in *most* of the header files.
#	echo "(checking if C include files have 'extern" '"C"'"')"
#	echo '#include <unistd.h>' >temp.c
#	if ${CC} -E -D__cplusplus temp.c | grep 'extern "C"' 2>&1 >/dev/null ; then
#	    echo 'HAVE_CPLUS_EXTERN = 1' >>${host_makefile_frag}
#	    echo 'WRAP_C_INCLUDES =' >>${host_makefile_frag}
#	else

            echo '
# If the C include files are C++-ready (with extern "C"),
# define: HAVE_CPLUS_EXTERN = 1 and: WRAP_C_INCLUDES =
# If not, define HAVE_CPLUS_EXTERN = 0, and do not define WRAP_C_INCLUDES here.
HAVE_CPLUS_EXTERN = 0' >>${host_makefile_frag}

	echo '
# Flags to pass to gen-params when building _G_config.h.
# For example: G_CONFIG_ARGS = size_t="unsigned long"
G_CONFIG_ARGS =' >>${host_makefile_frag}

	rm temp.c

	# If cross-compiling, don't build gperf or the utils.  They
	# will get built by the target compiler, which is confusing.
	if [ ${host_alias} != ${target_alias} ] ; then
	    echo '
# We do not build gperf or utils when cross-compiling, and we can not
# test the installation.  We install in $(tooldir).
GPERF =
UTILS =
TEST_INSTALL = Makefile
INSTALLDIR = $(tooldir)/lib' >>${host_makefile_frag}
	fi
fi

# per-target:

case "${srcdir}" in
".") ;;
*)
	links=lgpl.texinfo
	files=lgpl.texinfo
esac

# post-target:

if [ -f ${srcdir}/${subdir}/depend ] ; then
  cat ${srcdir}/${subdir}/depend >>${subdir}/Makefile
fi
