#!/bin/sh

#
# values substituted from configure
#
host=x86_64-suse-linux-gnu
prefix=/usr/lib64/mpi/gcc/openmpi4
exec_prefix=/usr
libdir=/usr/lib64/mpi/gcc/openmpi4/lib64
includedir=/usr/include
legacyinclude=@enablelegacyincludepaths@
has_been_installed=yes

#
# Define the usage() function
#
usage ()
{
  echo "usage: $0 --cppflags --cxxflags --include --libs"
  echo "       $0 --cxx"
  echo "       $0 --cc"
  echo "       $0 --fc"
  echo "       $0 --fflags"
  echo "       $0 --version"
  echo "       $0 --host"
  echo "       $0 --ldflags"
  exit
}

#
# Need at least one command-line argument
#
if [ "$#" = "0" ] ; then
    usage $0
fi

#
# Need a valid METHOD
#
if (test "x$METHOD" = x); then
    #echo "No METHOD specified - defaulting to opt"
    METHOD=opt
fi

case "$METHOD" in
    optimized|opt)
	CXXFLAGS=" -O2 -felide-constructors -fstrict-aliasing -Wdisabled-optimization -funroll-loops -ftrapping-math   "
	CPPFLAGS="-DNDEBUG  -I/usr/include/"
	CFLAGS="   "
	libext="_opt"
	;;
    debug|dbg)
	CXXFLAGS=" -O0 -felide-constructors -g -pedantic -W -Wall -Wextra -Wno-long-long -Wunused -Wpointer-arith -Wformat -Wparentheses -Woverloaded-virtual -ftrapping-math   "
	CPPFLAGS="-DDEBUG  -I/usr/include/"
	CFLAGS="   "
	libext="_dbg"
	;;
    devel)
	CXXFLAGS=" -O2 -felide-constructors -g -pedantic -W -Wall -Wextra -Wno-long-long -Wunused -Wpointer-arith -Wformat -Wparentheses -Wuninitialized -fstrict-aliasing -Woverloaded-virtual -Wdisabled-optimization -funroll-loops -ftrapping-math   "
	CPPFLAGS="  -I/usr/include/"
	CFLAGS="   "
	libext="_devel"
	;;
    profiling|pro|prof)
	CXXFLAGS=" -O2 -felide-constructors -fstrict-aliasing -Wdisabled-optimization -funroll-loops -ftrapping-math   -pg "
	CPPFLAGS="-DNDEBUG  -I/usr/include/"
	CFLAGS="   -pg "
	libext="_prof"
	;;
    oprofile|oprof)
	CXXFLAGS=" -O2 -felide-constructors -fstrict-aliasing -Wdisabled-optimization -funroll-loops -ftrapping-math   -g -fno-omit-frame-pointer "
	CPPFLAGS="-DNDEBUG  -I/usr/include/"
	CFLAGS="   -g -fno-omit-frame-pointer "
	libext="_oprof"
	;;
    *)
	echo "ERROR: Unknown \$METHOD: $METHOD"
	echo "  should be one of: <opt,dbg,devel,prof,oprof>"
	exit 1
	;;
esac

#
# Process the command-line arguments, build up
# return_val
#
return_val=""

while [ "x$1" != "x" ]; do
    case "$1" in
	"--cxx")
	    return_val="g++ $return_val"
	    ;;

	"--cc")
	    return_val="gcc $return_val"
	    ;;

	"--f77")
	    return_val="@F77@ $return_val"
	    ;;

	"--fc")
	    return_val="gfortran $return_val"
	    ;;

	"--cppflags")
	    return_val="${CPPFLAGS} $return_val"
	    ;;

	"--cxxflags")
	    return_val="${CXXFLAGS} $return_val"
	    ;;

	"--cflags")
	    return_val="${CFLAGS} $return_val"
	    ;;

	"--fflags")
	    return_val="@FFLAGS@ $return_val"
	    ;;

	"--include")
	    # handle legacy include paths when needed.
	    if (test "x$legacyinclude" = "xyes"); then
		return_val="-I${includedir}/timpi $return_val"
	    fi
	    return_val="-I${includedir}
 	                
                        $return_val"
	    ;;

	"--libs")
	    return_val="-L${libdir} -ltimpi${libext}  $return_val"
	    ;;

	"--ldflags")
	    return_val="@timpi_LDFLAGS@ $return_val"
	    ;;

	"--version")
	    return_val="1.8.5"
	    ;;

	"--host")
	    return_val="$host"
	    ;;

	*)
	    echo "Unknown argument: $1"
	    usage $0
    esac
    shift
done

echo $return_val

# Local Variables:
# mode: shell-script
# End:
