#!/bin/sh

if [ $# -ne 2 ]; then
	echo "Usage: $0 library.def library.so"
	exit 1
fi

export LC_ALL=C

def_path=$1
def_name=$(basename $def_path)
lib_path=$2

lib_result=$(mktemp /tmp/defcompare.XXXXXX)

nm $lib_path | awk \
	'{
		if ($3 !~ /^_gst_parse_yy/)
		{
			if ($2 == "B")
				print "\t" $3 " DATA"
			else if ($2 == "T")
				print "\t" $3
		}
	 }' | sort | awk '{ if (NR == 1) print "EXPORTS"; print $0; }' \
	> $lib_result

diff -u $def_path $lib_result | awk -v def_name=$def_name \
	'{
		if (NR > 2)
		{
			print $0
		}
		else
		{
			if (NR == 1)
				$2 = def_name "-orig"
			else
				$2 = def_name
			print $0
		}
		
	 }'

rm $lib_result
