#!/bin/sh
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../gcc/wrappers.in
# Copyright (C) 2004 - 2006 The T2 SDE Project
# Copyright (C) 1998 - 2003 Clifford Wolf
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---

gcc_build_wrapper() {
	local x="$1" y z ; shift
	local p="$1" ; shift
	for y ; do
		local ver=`$y -dumpversion 2> /dev/null`
		[ $? != 0 ] && continue

		[ "$x" != "$p" ] && z="$x,$p" || z="$x"
		case "$ver" in
			2.*) z="$z,${p}2" ;;
			3.*) z="$z,${p}3" ;;
			4.*) z="$z,${p}4" ;;
			*)   continue ;;
		esac

		if [ $x = KCC ] ; then
			build_wrapper $x $y
		else
			build_wrapper $z $y
		fi
	done
}

gcc_build_wrapper CC	GCC ${arch_target}-cc ${arch_target}-gcc{-2,-3,-33,-x,}
gcc_build_wrapper KCC	GCC ${arch_target}-kcc{-2,-3,-33,-x,}

if atstage native || [ "$SDECFG_USE_CROSSCC" = 0 ] ; then
	gcc_build_wrapper CC  GCC cc gcc{-2,-3,-33,-x,}
	gcc_build_wrapper CXX GCC {c,g}++{-2,-3,-33,-x,}
	gcc_build_wrapper F77 GCC {g,f}77{-2,-3,-33,-x,}
	gcc_build_wrapper KCC GCC kcc{-2,-3,-33,-x,}
	gcc_build_wrapper CPP CPP cpp{-2,-3,-33,-x,}
else
	# system compiler used in stage 0 - mostly for ccache
	gcc_build_wrapper SYSCC  SYSGCC {,g}cc
	gcc_build_wrapper SYSCXX SYSGCC {c,g}++
	gcc_build_wrapper SYSCPP SYSCPP cpp
fi