#!/bin/sh
TESTSDIR=debian/tests
TMP=${AUTOPKGTEST_TMP:-.}

check() {
	if [ $1 -ne 0 ]; then
		echo "Exit code should be 0, not $1" >&2
		exit 1
	fi
}

# Assemble.
h8300-hitachi-coff-as -o $TMP/asm.o $TESTSDIR/asm.s
check $?
h8300-hitachi-coff-as -o $TMP/link.o $TESTSDIR/link.s
check $?

# Link.
h8300-hitachi-coff-ld -o $TMP/link $TMP/link.o $TMP/asm.o
check $?

# Disassemble.
h8300-hitachi-coff-objdump -d $TMP/link > $TMP/link.d
check $?

# Compare.
sed -e "s,@TMP@,$TMP/," < $TESTSDIR/link.d.expected.in > $TMP/link.d.expected
if ! diff -u $TMP/link.d.expected $TMP/link.d; then
	echo "Disassembly mismatch" >&2
	exit 1
fi

echo Success
exit 0
