1#!/bin/sh -e
2#
3
4SHLIB_COMPAT=$(dirname $0)/shlib-compat.py
5
6if [ $# -lt 3 ]; then
7	echo "Usage: $0 orig-dir new-dir output-dir"
8	exit 1
9fi
10
11orig=$1
12new=$2
13out=$3
14shift 3
15
16remove_empty() {
17	local i
18	for i in $*; do
19		[ -s $i ] || rm -f $i
20	done
21}
22
23test_file() {
24	local i
25	for i in $*; do
26		if [ \! -f $1 ]; then
27			echo "file not found: $1"
28			return 1
29		fi
30	done
31}
32
33rorig=`realpath $orig`
34rnew=`realpath $new`
35list=`(cd $rorig; ls; cd $rnew; ls) | sort -u`
36for i in $list; do
37	echo $i
38	test_file $orig/$i $new/$i || continue
39	$SHLIB_COMPAT --out-orig $out/$i.orig.c --out-new $out/$i.new.c -v "$@" \
40		$orig/$i $new/$i > $out/$i.cmp 2> $out/$i.err || true
41	remove_empty $out/$i.orig.c $out/$i.new.c $out/$i.cmp $out/$i.err
42	if [ -f $out/$i.orig.c -a -f $out/$i.new.c ]; then
43		astyle --quiet --style=bsd -k3 $out/$i.orig.c $out/$i.new.c
44		rm -f $out/$i.orig.c.orig $out/$i.new.c.orig
45		diff -u $out/$i.orig.c $out/$i.new.c > $out/$i.diff || true
46	fi
47done
48