#!/bin/sh

#
# This script computes the various flags needed to run GNU C++ testsuites
# (compiler specific as well as library specific). 
#
# Written by Benjamin Kosnik <bkoz@redhat.com>
#            Gabriel Dos Reis <gdr@codesourcery.com>
#

# Print a message saying how this script is intended to be invoked
print_usage() {
    cat <<EOF
Usage: 
    testsuite_flags --install-includes
		    --build-includes
		    --build-cxx
		    --build-cc
		    --install-cxx
		    --cxxflags
		    --cxxpchflags
		    --cxxldflags
EOF
}

# Establish configure-generated directory structure.
BUILD_DIR=/home/gdobra/compilers/RX/build/gcc/rx-elf/libstdc++-v3
SRC_DIR=/home/gdobra/compilers/RX/source/gcc-4.8.4/libstdc++-v3
PREFIX_DIR=/home/gdobra/compilers/RX/prefix
query=$1

case ${query} in
    --install-includes)
      INCLUDES="-I${SRC_DIR}/testsuite/util"
      echo ${INCLUDES}
      ;;
    --build-includes)
      INCLUDES="-nostdinc++ -I/home/gdobra/compilers/RX/build/gcc/rx-elf/libstdc++-v3/include/rx-elf -I/home/gdobra/compilers/RX/build/gcc/rx-elf/libstdc++-v3/include -I/home/gdobra/compilers/RX/source/gcc-4.8.4/libstdc++-v3/libsupc++ 
                -I${SRC_DIR}/include/backward -I${SRC_DIR}/testsuite/util"
      echo ${INCLUDES}
      ;;
    --install-cxx)
      CXX=${PREFIX_DIR}/bin/g++
      echo ${CXX}
      ;;
    --build-cxx)
      CXX_build=" /home/gdobra/compilers/RX/build/gcc/./gcc/xgcc -shared-libgcc -B/home/gdobra/compilers/RX/build/gcc/./gcc -nostdinc++ -L/home/gdobra/compilers/RX/build/gcc/rx-elf/libstdc++-v3/src -L/home/gdobra/compilers/RX/build/gcc/rx-elf/libstdc++-v3/src/.libs -B/home/gdobra/compilers/RX/prefix/rx-elf/bin/ -B/home/gdobra/compilers/RX/prefix/rx-elf/lib/ -isystem /home/gdobra/compilers/RX/prefix/rx-elf/include -isystem /home/gdobra/compilers/RX/prefix/rx-elf/sys-include   "
      CXX=`echo "$CXX_build" | sed 's,gcc/xgcc ,gcc/xg++ ,'`
      echo ${CXX}
      ;;
    --build-cc)
      CC_build="/home/gdobra/compilers/RX/build/gcc/./gcc/xgcc -B/home/gdobra/compilers/RX/build/gcc/./gcc/ -B/home/gdobra/compilers/RX/prefix/rx-elf/bin/ -B/home/gdobra/compilers/RX/prefix/rx-elf/lib/ -isystem /home/gdobra/compilers/RX/prefix/rx-elf/include -isystem /home/gdobra/compilers/RX/prefix/rx-elf/sys-include   "
      CC="$CC_build"
      echo ${CC}
      ;;
    --cxxflags)
      CXXFLAGS_default="-D_GLIBCXX_ASSERT -fmessage-length=0"
      CXXFLAGS_config="-ffunction-sections -fdata-sections -g -O2 "
      echo ${CXXFLAGS_default} ${CXXFLAGS_config}
      ;;
    --cxxparallelflags)
      CXXFLAGS_parallel="-D_GLIBCXX_PARALLEL -fopenmp
			 -B${BUILD_DIR}/../libgomp 
                         -I${BUILD_DIR}/../libgomp 
			 -L${BUILD_DIR}/../libgomp/.libs -lgomp"
      echo ${CXXFLAGS_parallel}
      ;;
    --cxxpchflags)
      PCHFLAGS=""
      echo ${PCHFLAGS}
      ;;
    --cxxldflags)
      SECTIONLDFLAGS=" "
      echo ${SECTIONLDFLAGS}
      ;;
    *)
      print_usage
      ;;
esac

exit 0
