#!/bin/sh
#=============================================================================
#
#  Program:   GCC-XML
#  Module:    $RCSfile: find_flags,v $
#  Language:  C++
#  Date:      $Date: 2004/01/14 16:14:33 $
#  Version:   $Revision: 1.3 $
#
#  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
#  See Copyright.txt for details.
#
#     This software is distributed WITHOUT ANY WARRANTY; without even 
#     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
#     PURPOSE.  See the above copyright notices for more information.
#
#=============================================================================

# Find the MIPSPro executable name.
if test "x$1" = "x" ; then
  if test "x${CXX}" = "x" ; then
    CXX=CC
  fi
else 
  CXX="$1"
  shift
  CXXFLAGS="$@"
fi

GCCXML_PID="$$"
TESTFILE="find_flags_temp$GCCXML_PID"
touch /tmp/$TESTFILE.cxx

# Find the macro definition options.
MACROS=`
${CXX} ${CXXFLAGS} -E -v /tmp/$TESTFILE.cxx 2>&1 |
sed -n '/_COMPILER_VERSION/{s/ \/tmp\/'$TESTFILE'.cxx.*$//
s/ -/\\
-/g;p;}' |
sed -n '/^-D.*$/{s/-D\([^=]*\)=\([^ ]\{1,\} .*\)/-D\1='\''\2'\''/;p;}' |
sed -n 'H;${g;s/\n/ /g;p;}'`

# Find and translate the -LANG:std option into -D_STANDARD_C_PLUS_PLUS
LANGSTD=`
${CXX} ${CXXFLAGS} -E -v /tmp/$TESTFILE.cxx 2>&1 |
sed -n '/_COMPILER_VERSION/{s/ \/tmp\/'$TESTFILE'.cxx.*$//
s/ -/\\
-/g;p;}' |
sed -n '/^-LANG:std.*$/{s/-LANG:std/-D_STANDARD_C_PLUS_PLUS/;p;}' |
sed -n 'H;${g;s/\n/ /g;p;}'`

# Find the include path options.
INCLUDES=`
${CXX} ${CXXFLAGS} -E -v /tmp/$TESTFILE.cxx 2>&1 |
sed -n '/_COMPILER_VERSION/{s/ \/tmp\/'$TESTFILE'.cxx.*$//
s/ -/\\
-/g;p;}' |
sed -n '/^-I.*$/{p;}' |
sed -n 'H;${g;s/\n/ /g;p;}'`

# The support headers are located where this script is.
SELFPATH=`echo $0 | sed -n '/\//{s/\/find_flags//;p;}'`
if test "x$SELFPATH" = "x" ; then SELFPATH="." ; fi
SELFPATH=`cd "$SELFPATH" ; pwd`
INCLUDES="-iwrapper$SELFPATH/7.3 $INCLUDES"

rm -f /tmp/$TESTFILE.cxx

# Format and print out the options.
OPTIONS="$MACROS $LANGSTD $INCLUDES"
echo $OPTIONS
