run_make.sh revision 268899
1#!/bin/sh
2# $Id: run_make.sh,v 1.14 2014/04/06 17:50:57 tom Exp $
3# vi:ts=4 sw=4:
4
5# do a test-compile on each of the ".c" files in the test-directory
6
7BISON=`bison --version 2>/dev/null | head -n 1 | sed -e 's/^[^0-9.]*//' -e 's/[^0-9.]*$//'`
8
9if test $# = 1
10then
11	PROG_DIR=`pwd`
12	TEST_DIR=$1
13else
14	PROG_DIR=..
15	TEST_DIR=.
16fi
17THIS_DIR=`pwd`
18
19ifBTYACC=`fgrep -l 'define YYBTYACC' config.h > /dev/null; test $? != 0; echo $?`
20
21if test $ifBTYACC = 0; then
22	REF_DIR=${TEST_DIR}/yacc
23else
24	REF_DIR=${TEST_DIR}/btyacc
25fi
26
27MY_MAKE="make -f $PROG_DIR/makefile srcdir=$PROG_DIR"
28
29run_make() {
30	C_FILE=`basename "$1"`
31	O_FILE=`basename "$C_FILE" .c`.o
32	shift
33	cd $REF_DIR
34	make -f $PROG_DIR/makefile srcdir=$PROG_DIR $O_FILE $*
35	test -f $O_FILE && rm $O_FILE
36	cd $THIS_DIR
37}
38
39echo '** '`date`
40echo "** program is in $PROG_DIR"
41echo "** test-files in $REF_DIR"
42
43for input in ${REF_DIR}/*.c
44do
45	case $input in #(vi
46	${REF_DIR}/err_*)
47		continue
48		;;
49	esac
50
51	test -f "$input" || continue
52
53	run_make "$input"
54
55	DEFS=
56	case $input in #(vi
57	${REF_DIR}/pure_*)
58		# DEFS="-DYYLEX_PARAM=flag -DYYLEX_PARAM_TYPE=int"
59		;;
60	esac
61
62	if test "x$DEFS" != "x"
63	then
64		run_make "$input" DEFINES="$DEFS"
65	fi
66done
67
68if test -n "$BISON"
69then
70	echo "** compare with bison $BISON"
71	for input in ${TEST_DIR}/*.y
72	do
73		test -f "$input" || continue
74		case $input in
75		${TEST_DIR}/err_*)
76			continue
77			;;
78		${TEST_DIR}/btyacc_*)
79			# Bison does not support the btyacc []-action extension.
80			continue
81			;;
82		esac
83
84		# Bison does not support pure-parser from command-line.
85		# Also, its support for %expect is generally broken.
86		# Work around these issues using a temporary file.
87
88		echo "... testing $input"
89		rm -f run_make.[coy]
90
91		case $input in
92		${TEST_DIR}/pure_*)
93			if test -z `fgrep -l '%pure-parser' $input`
94			then
95				echo "%pure-parser" >>run_make.y
96			fi
97			;;
98		esac
99
100		sed -e '/^%expect/s,%expect.*,,' $input >>run_make.y
101
102		bison -y run_make.y
103		if test -f "y.tab.c"
104		then
105			sed -e '/^#line/s,"run_make.y","'$input'",' y.tab.c >run_make.c
106
107			rm -f y.tab.c
108
109			input=run_make.c
110			object=run_make.o
111			if test -f $input
112			then
113				$MY_MAKE $object DEFINES='-DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=1 -DYYSTACK_USE_ALLOCA=0 -DYYMAXDEPTH=0'
114			else
115				echo "?? $input not found"
116			fi
117		fi
118		rm -f run_make.[coy]
119	done
120fi
121
122YACC=
123for name in /usr/ccs/bin/yacc
124do
125	if test -f $name
126	then
127		YACC=$name
128	fi
129done
130
131if test -n "$YACC"
132then
133	echo "** compare with $YACC"
134	for input in ${TEST_DIR}/*.y
135	do
136		test -f "$input" || continue
137
138		echo "... testing $input"
139		rm -f run_make.[coy]
140
141		case $input in
142		pure_*)
143			echo "... skipping $input"
144			continue;
145			;;
146		*)
147			if fgrep '%pure-parser' $input >/dev/null ||
148			   fgrep '%parse-param' $input >/dev/null ||
149			   fgrep '%lex-param' $input >/dev/null ||
150			   fgrep 'YYLEX_PARAM' $input >/dev/null
151			then
152				echo "... skipping $input"
153				continue;
154			fi
155			;;
156		esac
157
158		sed -e '/^%expect/s,%expect.*,,' $input >>run_make.y
159
160		$YACC run_make.y
161		if test -f y.tab.c
162		then
163			sed -e '/^#line/s,"run_make.y","'$input'",' y.tab.c >run_make.c
164
165			rm -f y.tab.c
166
167			input=run_make.c
168			object=run_make.o
169			if test -f $input
170			then
171				$MY_MAKE $object
172			else
173				echo "?? $input not found"
174			fi
175		fi
176		rm -f run_make.[coy]
177	done
178fi
179