# 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.

configdirs="genclass no-stream old-stream src tests gperf utils etc test-install"
srctrigger=libg++.texi
srcname="GNU C++ Class Library"

# per-host:

# per-target:

package_makefile_frag=Make.pack

	echo "# Warning this fragment is automatically generated" >temp.mt
	rootme=`pwd`
	export rootme
	CC=${CC-`if [ -f ${rootme}/../gcc/xgcc ] ; \
        	then echo ${rootme}/../gcc/xgcc -B${rootme}/../gcc/ ; \
        	else echo gcc ; fi`}
	CONFIG_NM=${CONFIG_NM-nm}

	# 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}" >>temp.mt
	elif (eval $checkfor) >/dev/null 2>&1 ; then
	    # Use default value set in Makefile
	    echo "# RANLIB = ranlib" >>temp.mt
	else
	    echo "RANLIB = true" >>temp.mt
	fi

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

	# Check if we have reasonable include files:
#cat >temp.c <<'EOF'
##include <unistd.h>
##include <stdarg.h>
##include <stdio.h>
##include <string.h>
##include <stdlib.h>
#int call() { return 0; }
#int main()
#{
#  call(fclose);
#  call(rename);
#  return call(memcmp);
#}
#EOF
#	if [ -s "`${CC} -o temp temp.c 2>&1`" ] ; then true
#	else
#	    # Include files look tolerable
#	    echo 'WRAP_C_INCLUDES =' >>temp.mt
#	fi

	# Some recent systems wrap extern "C" around function declarations
	# in the system C header files.  Unfortunately, some systems
	# (such as Irix) miss the extern "C" in curses.h, say,
	# though they have it in *most* of the header files,
	# so it is hard to test for this automatically.
#	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 'WRAP_C_INCLUDES =' >>temp.mt
#	else

            echo '
# If the C include files are C++-ready (with extern "C"), uncomment next line:
# WRAP_C_INCLUDES =' >>temp.mt

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

rm -f temp.c temp.o temp

case "${target}" in
  i[34]86-*-linux) my_target=linux ;;
  *-*-solaris2*)   my_target=solaris2 ;;
  *-*-solaris)     my_target=solaris2 ;;
  *-*-*)           my_target=${target_cpu}
esac

target_makefile_frag=config/${my_target}.mt
if [ -f ${srcdir}/${target_makefile_frag} ] ; then
  echo "Appending ${srcdir}/${target_makefile_frag} to target-mkfrag"
  echo "# Following fragment copied from ${srcdir}/${target_makefile_frag}" >>temp.mt
  cat ${srcdir}/${target_makefile_frag} >>temp.mt
fi

${moveifchange} temp.mt target-mkfrag

TOLIBGXX=
ALL='$(TARGETLIB) rest-in-parallel'
MOSTLYCLEAN='*.o core \#* temp.c stamp-$(TARGETLIB) dummy.out dummy.[Cc] TMP a.out'
CLEAN='.stmp-* _G_config.h $(TARGETLIB)'
DISTCLEAN='config.status Makefile target-mkfrag'
INFO_FILES=libg++
INFO_SUBDIRS='$(SUBDIRS)'

# If cross-compiling, don't configure gperf or test-install, since
# they do not work (gperf and utils will get built by the target
# compiler, which is confusing, and test-install will try to execute
# programs built by the target compiler, which can not be done).
if [ ${host} != ${target} ] ; then
  configdirs=`echo ${configdirs} | sed -e 's/gperf//' -e 's/test-install//' -e 's/utils//'`
fi

(. ${srcdir}/config.shared) >${package_makefile_frag}

# post-target:

# If cross-compiling, don't build gperf or the utils.  They
# will get built by the target compiler, which is confusing.
# We cannot test the installation.  We install in $(tooldir).
if [ ${host} != ${target} ] ; then
    sed \
	-e 's|INSTALLDIR.*=.*$|INSTALLDIR = $(tooldir)/lib|' \
	-e 's|GPERF.*=.*gperf|GPERF = # gperf|' \
	-e 's|TEST_INSTALL[ 	]*=.*$|TEST_INSTALL = |' \
	-e 's|UTILS[ 	]*=.*$|UTILS =|' \
	-e 's|LIBIBERTY =.*$|LIBIBERTY = xiberty|' \
	Makefile >Makefile.tem
    mv -f Makefile.tem Makefile
fi

rm -f ${package_makefile_frag}
