#!/bin/sh
srctree=$(dirname "$0")

SHOW_ERROR=
if [ "$1" = "--show-error" ] ; then
	SHOW_ERROR=1
	shift || true
fi

gccplugins_dir=$($3 -print-file-name=plugin)
plugincc=$($1 -E -x c++ - -o /dev/null -I"${srctree}"/gcc-plugins -I"${gccplugins_dir}"/include 2>&1 <<EOF
#include "gcc-common.h"
#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
#warning $2 CXX
#else
#warning $1 CC
#endif
EOF
)

if [ $? -ne 0 ]
then
	if [ -n "$SHOW_ERROR" ] ; then
		echo "${plugincc}" >&2
	fi
	exit 1
fi

case "$plugincc" in
	*"$1 CC"*)
		echo "$1"
		exit 0
		;;

	*"$2 CXX"*)
		# the c++ compiler needs another test, see below
		;;

	*)
		exit 1
		;;
esac

# we need a c++ compiler that supports the designated initializer GNU extension
plugincc=$($2 -c -x c++ -std=gnu++98 - -fsyntax-only -I"${srctree}"/gcc-plugins -I"${gccplugins_dir}"/include 2>&1 <<EOF
#include "gcc-common.h"
class test {
public:
	int test;
} test = {
	.test = 1
};
EOF
)

if [ $? -eq 0 ]
then
	echo "$2"
	exit 0
fi

if [ -n "$SHOW_ERROR" ] ; then
	echo "${plugincc}" >&2
fi
exit 1
' selected='selected'>master</option>
<option value='nds-private-remove'>nds-private-remove</option>
<option value='packet-loop-back'>packet-loop-back</option>
<option value='packet-rx-pump-back'>packet-rx-pump-back</option>
</select> <input type='submit' value='switch'/></form></td></tr>
<tr><td class='sub'>net-next plumbings</td><td class='sub right'>Tobias Klauser</td></tr></table>
<table class='tabs'><tr><td>
<a href='/cgit.cgi/linux/net-next.git/'>summary</a><a href='/cgit.cgi/linux/net-next.git/refs/?id=69973b830859bc6529a7a0468ba0d80ee5117826'>refs</a><a class='active' href='/cgit.cgi/linux/net-next.git/log/drivers/usb/dwc3/gadget.h'>log</a><a href='/cgit.cgi/linux/net-next.git/tree/drivers/usb/dwc3/gadget.h?id=69973b830859bc6529a7a0468ba0d80ee5117826'>tree</a><a href='/cgit.cgi/linux/net-next.git/commit/drivers/usb/dwc3/gadget.h?id=69973b830859bc6529a7a0468ba0d80ee5117826'>commit</a><a href='/cgit.cgi/linux/net-next.git/diff/drivers/usb/dwc3/gadget.h?id=69973b830859bc6529a7a0468ba0d80ee5117826'>diff</a></td><td class='form'><form class='right' method='get' action='/cgit.cgi/linux/net-next.git/log/drivers/usb/dwc3/gadget.h'>
<input type='hidden' name='id' value='69973b830859bc6529a7a0468ba0d80ee5117826'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/cgit.cgi/linux/net-next.git/log/?id=69973b830859bc6529a7a0468ba0d80ee5117826'>root</a>/<a href='/cgit.cgi/linux/net-next.git/log/drivers?id=69973b830859bc6529a7a0468ba0d80ee5117826'>drivers</a>/<a href='/cgit.cgi/linux/net-next.git/log/drivers/usb?id=69973b830859bc6529a7a0468ba0d80ee5117826'>usb</a>/<a href='/cgit.cgi/linux/net-next.git/log/drivers/usb/dwc3?id=69973b830859bc6529a7a0468ba0d80ee5117826'>dwc3</a>/<a href='/cgit.cgi/linux/net-next.git/log/drivers/usb/dwc3/gadget.h?id=69973b830859bc6529a7a0468ba0d80ee5117826'>gadget.h</a></div><div class='content'><table class='list nowrap'><tr class='nohover'><th class='left'>Age</th><th class='left'>Commit message (<a href='/cgit.cgi/linux/net-next.git/log/drivers/usb/dwc3/gadget.h?id=69973b830859bc6529a7a0468ba0d80ee5117826&amp;showmsg=1'>Expand</a>)</th><th class='left'>Author</th><th class='left'>Files</th><th class='left'>Lines</th></tr>