# 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

	# 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

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

# If they didn't specify --enable-shared, don't generate shared libs.
if [ "${enable_shared}" = "yes" ]; then
  case "${target}" in
    hppa*-*-*)		frags=../../libio/config/mt-papic ;;
    i[345]86-*-*)	frags=../../libio/config/mt-x86pic ;;
    *-*-*) 		frags=../../libio/config/mt-${target_cpu}pic ;;
  esac
  case "${target}" in
    *-dec-osf*)		frags="${frags} dec-osf.ml";;
    *-*-hpux*)		frags="${frags} hpux.ml" ;;
    *-*-irix5*)		frags="${frags} irix5.ml" ;;
    *-*-linuxelf*)	frags="${frags} elf.ml" ;;
    *-*-sysv4*)		frags="${frags} elf.ml" ;;
    *-*-solaris*)	frags="${frags} elfshlibm.ml" ;;
    *-*-sunos4*)	frags="${frags} sunos4.ml" ;;
  esac
fi

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

target_makefile_frag=target-mkfrag
${moveifchange} temp.mt target-mkfrag

TOLIBGXX=
ALL='libs rest-in-parallel'
MOSTLYCLEAN='*.o core \#* temp.c dummy.out dummy.[Cc] TMP a.out list'
CLEAN='.stmp-* _G_config.h $(BUILD_LIBS)'
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}
