#!/usr/bin/env bash

WRAPPER_INCLUDEDIR="${WRAPPER_INCLUDEDIR:=-I/BB/build/brcm47xx/mips74k/staging_dir/target-mipsel_74kc+dsp2_uClibc-0.9.33.2/usr/include/uClibc++/}"
WRAPPER_LIBDIR="${WRAPPER_LIBDIR:=-L/BB/build/brcm47xx/mips74k/staging_dir/target-mipsel_74kc+dsp2_uClibc-0.9.33.2/usr/lib/}"

WRAPPER_OPTIONS=""
WRAPPER_LIBS="-lc -L/BB/build/brcm47xx/mips74k/staging_dir/toolchain-mipsel_74kc+dsp2_gcc-4.8-linaro_uClibc-0.9.33.2/lib -lgcc_s "

WRAPPER_INCLIB="Y"
while [ -n "$1" ]
do
	WRAPPER_OPTIONS="$WRAPPER_OPTIONS $1"
	if [ "$1" = "-c" -o "$1" = "-E" -o "$1" = "-S" -o "$1" = "-MF" ]
	then
		WRAPPER_INCLIB="N"
	fi
	if [ "$1" = "-static" ]
	then
		WRAPPER_LIBS="-lc -L/BB/build/brcm47xx/mips74k/staging_dir/toolchain-mipsel_74kc+dsp2_gcc-4.8-linaro_uClibc-0.9.33.2/lib -lgcc_s -lgcc_eh"
	fi
	shift
done
if [ "$WRAPPER_INCLIB" = "Y" ]
then
	WRAPPER_OPTIONS="$WRAPPER_OPTIONS -nodefaultlibs $WRAPPER_LIBDIR -luClibc++ $WRAPPER_LIBS"
fi

exec mipsel-openwrt-linux-uclibc-g++ -fno-builtin -nostdinc++ -DGCC_HASCLASSVISIBILITY  $WRAPPER_INCLUDEDIR $WRAPPER_OPTIONS
