#!/usr/bin/env sh
AR=ar
AR_FOR_TARGET=aarch64-xilinx-linux-ar
AS='as '
BUILD_AR=ar
BUILD_AS='as '
BUILD_CC='gcc '
BUILD_CCLD='gcc '
BUILD_CFLAGS='-isystemFIXMESTAGINGDIR/x86_64-linux/usr/include -O2 -pipe'
BUILD_CPP='gcc  -E'
BUILD_CPPFLAGS=-isystemFIXMESTAGINGDIR/x86_64-linux/usr/include
BUILD_CXX='g++ '
BUILD_CXXFLAGS='-isystemFIXMESTAGINGDIR/x86_64-linux/usr/include -O2 -pipe -D_GLIBCXX_USE_CXX11_ABI=0'
BUILD_FC='gfortran '
BUILD_LD='ld '
BUILD_LDFLAGS='-LFIXMESTAGINGDIR/x86_64-linux/usr/lib -LFIXMESTAGINGDIR/x86_64-linux/lib -Wl,-rpath-link,FIXMESTAGINGDIR/x86_64-linux/usr/lib -Wl,-rpath-link,FIXMESTAGINGDIR/x86_64-linux/lib -Wl,-rpath,FIXMESTAGINGDIR/x86_64-linux/usr/lib -Wl,-rpath,FIXMESTAGINGDIR/x86_64-linux/lib -Wl,-O1'
BUILD_NM=nm
BUILD_RANLIB=ranlib
BUILD_STRIP=strip
CC='gcc '
CCACHE_DIR=/home/xbrbbot/.ccache
CCACHE_DISABLE=1
CCLD='gcc '
CC_FOR_BUILD='gcc '
CC_FOR_TARGET=' aarch64-xilinx-linux-gcc'
CFLAGS='-isystemFIXMESTAGINGDIR/x86_64-linux/usr/include -O2 -pipe'
CFLAGS_FOR_BUILD='-isystemFIXMESTAGINGDIR/x86_64-linux/usr/include -O2 -pipe'
CFLAGS_FOR_TARGET=' -O2 -pipe -g -feliminate-unused-debug-types -fdebug-prefix-map=/scratch/petalinux-yocto/yocto_sdk_full_2017.4/build/tmp/work/x86_64-linux/gcc-cross-aarch64/linaro-6.2-r2016.11=/usr/src/debug/gcc-cross-aarch64/linaro-6.2-r2016.11 -fdebug-prefix-map=FIXMESTAGINGDIR/x86_64-linux= -fdebug-prefix-map=FIXMESTAGINGDIR/x86_64-linux= '
CONFIG_SITE='/scratch/petalinux-yocto/yocto_sdk_full_2017.4/sources/core/meta/site/endian-little /scratch/petalinux-yocto/yocto_sdk_full_2017.4/sources/core/meta/site/common-linux /scratch/petalinux-yocto/yocto_sdk_full_2017.4/sources/core/meta/site/common-glibc /scratch/petalinux-yocto/yocto_sdk_full_2017.4/sources/core/meta/site/x86_64-linux /scratch/petalinux-yocto/yocto_sdk_full_2017.4/sources/core/meta/site/common /scratch/petalinux-yocto/yocto_sdk_full_2017.4/sources/core/../meta-openembedded/meta-gnome/site/x86_64-linux /scratch/petalinux-yocto/yocto_sdk_full_2017.4/sources/core/../meta-openembedded/meta-oe/site/endian-little '
CPP='gcc  -E'
CPPFLAGS=
CPPFLAGS_FOR_BUILD=-isystemFIXMESTAGINGDIR/x86_64-linux/usr/include
CPPFLAGS_FOR_TARGET=
CPP_FOR_BUILD='gcc  -E'
CXX='g++ '
CXXFLAGS='-isystemFIXMESTAGINGDIR/x86_64-linux/usr/include -O2 -pipe'
CXXFLAGS_FOR_BUILD='-isystemFIXMESTAGINGDIR/x86_64-linux/usr/include -O2 -pipe -D_GLIBCXX_USE_CXX11_ABI=0'
CXXFLAGS_FOR_TARGET=' -O2 -pipe -g -feliminate-unused-debug-types -fdebug-prefix-map=/scratch/petalinux-yocto/yocto_sdk_full_2017.4/build/tmp/work/x86_64-linux/gcc-cross-aarch64/linaro-6.2-r2016.11=/usr/src/debug/gcc-cross-aarch64/linaro-6.2-r2016.11 -fdebug-prefix-map=FIXMESTAGINGDIR/x86_64-linux= -fdebug-prefix-map=FIXMESTAGINGDIR/x86_64-linux= '
CXX_FOR_BUILD='g++ '
FC='gfortran '
LD='ld '
LDFLAGS='-LFIXMESTAGINGDIR/x86_64-linux/usr/lib -LFIXMESTAGINGDIR/x86_64-linux/lib -Wl,-rpath-link,FIXMESTAGINGDIR/x86_64-linux/usr/lib -Wl,-rpath-link,FIXMESTAGINGDIR/x86_64-linux/lib -Wl,-rpath,FIXMESTAGINGDIR/x86_64-linux/usr/lib -Wl,-rpath,FIXMESTAGINGDIR/x86_64-linux/lib -Wl,-O1'
LDFLAGS_FOR_BUILD='-LFIXMESTAGINGDIR/x86_64-linux/usr/lib -LFIXMESTAGINGDIR/x86_64-linux/lib -Wl,-rpath-link,FIXMESTAGINGDIR/x86_64-linux/usr/lib -Wl,-rpath-link,FIXMESTAGINGDIR/x86_64-linux/lib -Wl,-rpath,FIXMESTAGINGDIR/x86_64-linux/usr/lib -Wl,-rpath,FIXMESTAGINGDIR/x86_64-linux/lib -Wl,-O1'
LDFLAGS_FOR_TARGET='-Wl,-O1  -Wl,--as-needed'
LD_FOR_BUILD='ld '
LD_FOR_TARGET=aarch64-xilinx-linux-ld
MAKE=make
NM=nm
NM_FOR_TARGET=aarch64-xilinx-linux-nm
OBJCOPY=objcopy
OBJDUMP=objdump
OLDPWD=/scratch/petalinux-yocto/yocto_sdk_full_2017.4/build
PATH=FIXMESTAGINGDIR/x86_64-linux/usr/bin/texinfo-dummy-native:FIXMESTAGINGDIR-uninative/x86_64-linux/usr/bin:/scratch/petalinux-yocto/yocto_sdk_full_2017.4/sources/core/scripts:FIXMESTAGINGDIR/x86_64-linux/usr/bin/aarch64-xilinx-linux:FIXMESTAGINGDIR/x86_64-linuxFIXMESTAGINGDIR/x86_64-linux/usr/bin/aarch64-xilinx-linux/crossscripts:FIXMESTAGINGDIR/x86_64-linux/usr/sbin:FIXMESTAGINGDIR/x86_64-linux/usr/bin:FIXMESTAGINGDIR/x86_64-linux/sbin:FIXMESTAGINGDIR/x86_64-linux/bin:/scratch/petalinux-yocto/yocto_sdk_full_2017.4/sources/core/scripts:/scratch/petalinux-yocto/yocto_sdk_full_2017.4/sources/core/bitbake/bin:/lib:/usr/local/bin:/usr/bin:/scratch/petalinux-yocto/yocto_sdk_full_2017.4/scripts
PWD=/scratch/petalinux-yocto/yocto_sdk_full_2017.4/build/tmp/work/x86_64-linux/gcc-cross-aarch64/linaro-6.2-r2016.11/gcc-linaro-6.2-2016.11/build.x86_64-linux.aarch64-xilinx-linux
RANLIB=ranlib
RANLIB_FOR_TARGET=aarch64-xilinx-linux-ranlib
READELF=readelf
STRINGS=strings
STRIP=strip
TARGET_CFLAGS=' -O2 -pipe -g -feliminate-unused-debug-types -fdebug-prefix-map=/scratch/petalinux-yocto/yocto_sdk_full_2017.4/build/tmp/work/x86_64-linux/gcc-cross-aarch64/linaro-6.2-r2016.11=/usr/src/debug/gcc-cross-aarch64/linaro-6.2-r2016.11 -fdebug-prefix-map=FIXMESTAGINGDIR/x86_64-linux= -fdebug-prefix-map=FIXMESTAGINGDIR/x86_64-linux= '
TARGET_CPPFLAGS=
TARGET_CXXFLAGS=' -O2 -pipe -g -feliminate-unused-debug-types -fdebug-prefix-map=/scratch/petalinux-yocto/yocto_sdk_full_2017.4/build/tmp/work/x86_64-linux/gcc-cross-aarch64/linaro-6.2-r2016.11=/usr/src/debug/gcc-cross-aarch64/linaro-6.2-r2016.11 -fdebug-prefix-map=FIXMESTAGINGDIR/x86_64-linux= -fdebug-prefix-map=FIXMESTAGINGDIR/x86_64-linux= '
TARGET_LDFLAGS='-Wl,-O1  -Wl,--as-needed'
_='#!/usr/bin/env sh'
base_bindir=FIXMESTAGINGDIR/x86_64-linux/usr/bin/aarch64-xilinx-linux
base_libdir=FIXMESTAGINGDIR/x86_64-linux/lib
base_prefix=FIXMESTAGINGDIR/x86_64-linux
base_sbindir=FIXMESTAGINGDIR/x86_64-linux/usr/bin/aarch64-xilinx-linux
bindir=FIXMESTAGINGDIR/x86_64-linux/usr/bin/aarch64-xilinx-linux
datadir=FIXMESTAGINGDIR/x86_64-linux/usr/share
docdir=FIXMESTAGINGDIR/x86_64-linux/usr/share/doc
exec_prefix=FIXMESTAGINGDIR/x86_64-linux/usr
gcc_cv_collect2_libs='none required'
includedir=FIXMESTAGINGDIR/x86_64-linux/usr/include
infodir=FIXMESTAGINGDIR/x86_64-linux/usr/share/info
libdir=FIXMESTAGINGDIR/x86_64-linux/usr/lib/aarch64-xilinx-linux
libexecdir=FIXMESTAGINGDIR/x86_64-linux/usr/libexec/aarch64-xilinx-linux
localstatedir=FIXMESTAGINGDIR/x86_64-linux/var
lt_cv_sys_lib_dlsearch_path_spec='FIXMESTAGINGDIR/x86_64-linux/usr/lib/aarch64-xilinx-linux FIXMESTAGINGDIR/x86_64-linux/lib /lib /lib64 /usr/lib /usr/lib64'
mandir=FIXMESTAGINGDIR/x86_64-linux/usr/share/man
nonarch_base_libdir=FIXMESTAGINGDIR/x86_64-linux/lib
nonarch_libdir=FIXMESTAGINGDIR/x86_64-linux/usr/lib
oldincludedir=FIXMESTAGINGDIR/x86_64-linux/usr/include
prefix=FIXMESTAGINGDIR/x86_64-linux/usr
sbindir=FIXMESTAGINGDIR/x86_64-linux/usr/bin/aarch64-xilinx-linux
servicedir=FIXMESTAGINGDIR/x86_64-linux/srv
sharedstatedir=FIXMESTAGINGDIR/x86_64-linux/com
sysconfdir=FIXMESTAGINGDIR/x86_64-linux/etc
systemd_system_unitdir=FIXMESTAGINGDIR/x86_64-linux/lib/systemd/system
systemd_unitdir=FIXMESTAGINGDIR/x86_64-linux/lib/systemd
systemd_user_unitdir=FIXMESTAGINGDIR/x86_64-linux/usr/lib/systemd/user
target="$1"
usage () {
	echo "Usage:"
	echo "$0 user@target 'extra options to dejagnu'"
	echo "$0 target 'extra options to dejagnu'"
	echo "$0 target"
	echo "e.g. $0 192.168.7.2 ' dg.exp=visibility-d.c'"
	echo "will only run visibility-d.c test case"
	echo "e.g. $0 192.168.7.2 '/-mthumb dg.exp=visibility-d.c'"
	echo "will only run visibility-d.c test case in thumb mode"
	echo "You need to have dejagnu autogen expect installed"
	echo "on the build host"
    }
if [ "x$target" = "x" ]
then
	echo "Please specify the target machine and remote user in form of user@target\n"
	usage
	exit 1;
fi

shift

echo "$target" | grep "@" 2>&1 > /dev/null
if [ "x$?" = "x0" ]
then
   user=$(echo $target | cut -d '@' -f 1)
   target=$(echo $target | cut -d '@' -f 2)
else
   user=$USER
fi
ssh $user@$target date 2>&1 > /dev/null
if [ "x$?" != "x0" ]
then
	echo "Failed connecting to $user@$target it could be because"
	echo "you don't have passwordless ssh setup to access $target"
	echo "or sometimes host key has been changed"
	echo "in such case do something like below on build host"
	echo "ssh-keygen -f "~/.ssh/known_hosts" -R $target"
	echo "and then try ssh $user@$target"

	usage
	exit 1
fi
	echo "lappend boards_dir [pwd]/../../.." > /scratch/petalinux-yocto/yocto_sdk_full_2017.4/build/tmp/work/x86_64-linux/gcc-cross-aarch64/linaro-6.2-r2016.11/gcc-linaro-6.2-2016.11/build.x86_64-linux.aarch64-xilinx-linux/site.exp
	echo "load_generic_config \"unix\"" > /scratch/petalinux-yocto/yocto_sdk_full_2017.4/build/tmp/work/x86_64-linux/gcc-cross-aarch64/linaro-6.2-r2016.11/gcc-linaro-6.2-2016.11/build.x86_64-linux.aarch64-xilinx-linux/x86_64.exp
	echo "set_board_info username $user" >> /scratch/petalinux-yocto/yocto_sdk_full_2017.4/build/tmp/work/x86_64-linux/gcc-cross-aarch64/linaro-6.2-r2016.11/gcc-linaro-6.2-2016.11/build.x86_64-linux.aarch64-xilinx-linux/x86_64.exp
	echo "set_board_info rsh_prog ssh" >> /scratch/petalinux-yocto/yocto_sdk_full_2017.4/build/tmp/work/x86_64-linux/gcc-cross-aarch64/linaro-6.2-r2016.11/gcc-linaro-6.2-2016.11/build.x86_64-linux.aarch64-xilinx-linux/x86_64.exp
	echo "set_board_info rcp_prog scp" >> /scratch/petalinux-yocto/yocto_sdk_full_2017.4/build/tmp/work/x86_64-linux/gcc-cross-aarch64/linaro-6.2-r2016.11/gcc-linaro-6.2-2016.11/build.x86_64-linux.aarch64-xilinx-linux/x86_64.exp
	echo "set_board_info hostname $target" >> /scratch/petalinux-yocto/yocto_sdk_full_2017.4/build/tmp/work/x86_64-linux/gcc-cross-aarch64/linaro-6.2-r2016.11/gcc-linaro-6.2-2016.11/build.x86_64-linux.aarch64-xilinx-linux/x86_64.exp
	DEJAGNU=/scratch/petalinux-yocto/yocto_sdk_full_2017.4/build/tmp/work/x86_64-linux/gcc-cross-aarch64/linaro-6.2-r2016.11/gcc-linaro-6.2-2016.11/build.x86_64-linux.aarch64-xilinx-linux/site.exp make -k check RUNTESTFLAGS="--target_board=x86_64$@"

