#!/bin/bash
#echo "test 0" > /tmp/0000.log
# Test 1:
#exec $0.orig $@
# Test 2:
#$0.orig $@
#RET=$?
#exit $RET

BASENAME_WRAPPER=/tmp/`basename $0`.$$.log
# Note 1: Below does not works in the build root
#BASENAME_WRAPPER=/tmp/`basename $0`.$BASHPID.log

# Warning: only for debug, else it's linkage error for compile option '-o -' output to stdout
#echo "$0 $@" >> $BASENAME_WRAPPER

# Note 2: Inject additional params is incorrect - it's does not works with autotool tests
#DUMPBASE_PARAM=`echo "$@"|sed -rn "s|\-dumpbase ([^ ]*) |\-dumpbase \1 -Wall -Wprint-abs-path |p"`

DUMPBASE_OUT=`echo "$@" | grep -e "\-dumpbase \+\-" -e "\-dumpbase \+null" -e "\-o \+/dev/null"`
#echo "DUMPBASE_OUT=$DUMPBASE_OUT" >> $BASENAME_WRAPPER
[ "x$DUMPBASE_OUT" != "x" ] && BASENAME_WRAPPER=/dev/null

# Note 3: Below does not works, stdout may be redefined
#$0.orig $@ |& tee -a $BASENAME_WRAPPER
#$0.orig $@ | tee -a $BASENAME_WRAPPER 1>&2

# See note 2
# $0.orig $DUMPBASE_PARAM 2>> $BASENAME_WRAPPER

# Note 3: Below does not works in the SVACE environment
#         The SVACE tool can't capture the data if a wrapper is symlink
#exec $0.orig $@ 2>> $BASENAME_WRAPPER

$0.orig $@ 2>> $BASENAME_WRAPPER
RET=$?
cat $BASENAME_WRAPPER >&2
exit $RET
