xref: /freebsd/contrib/byacc/test/run_make.sh (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1#!/bin/sh
2# $Id: run_make.sh,v 1.15 2016/06/01 22:56:37 Tom.Shields 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	${REF_DIR}/test-err_*)
48		continue
49		;;
50	esac
51
52	test -f "$input" || continue
53
54	run_make "$input"
55
56	DEFS=
57	case $input in #(vi
58	${REF_DIR}/pure_*)
59		# DEFS="-DYYLEX_PARAM=flag -DYYLEX_PARAM_TYPE=int"
60		;;
61	esac
62
63	if test "x$DEFS" != "x"
64	then
65		run_make "$input" DEFINES="$DEFS"
66	fi
67done
68
69if test -n "$BISON"
70then
71	echo "** compare with bison $BISON"
72	for input in ${TEST_DIR}/*.y
73	do
74		test -f "$input" || continue
75		case $input in
76		${TEST_DIR}/err_*|\
77		${TEST_DIR}/test-err_*)
78			continue
79			;;
80		${TEST_DIR}/ok_syntax*|\
81		${TEST_DIR}/varsyntax*)
82			# Bison does not support all byacc legacy syntax
83			continue
84			;;
85		${TEST_DIR}/btyacc_*)
86			# Bison does not support the btyacc []-action & inherited attribute extensions.
87			continue
88			;;
89		esac
90
91		# Bison does not support pure-parser from command-line.
92		# Also, its support for %expect is generally broken.
93		# Work around these issues using a temporary file.
94
95		echo "... testing $input"
96		rm -f run_make.[coy]
97
98		case $input in
99		${TEST_DIR}/pure_*)
100			if test -z `fgrep -l '%pure-parser' $input`
101			then
102				echo "%pure-parser" >>run_make.y
103			fi
104			;;
105		esac
106
107		sed -e '/^%expect/s,%expect.*,,' $input >>run_make.y
108
109		bison -Wno-other -Wno-conflicts-sr -Wconflicts-rr -y run_make.y
110		if test -f "y.tab.c"
111		then
112			sed -e '/^#line/s,"run_make.y","'$input'",' y.tab.c >run_make.c
113
114			rm -f y.tab.c
115
116			input=run_make.c
117			object=run_make.o
118			if test -f $input
119			then
120				$MY_MAKE $object DEFINES='-DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=1 -DYYSTACK_USE_ALLOCA=0 -DYYMAXDEPTH=0'
121			else
122				echo "?? $input not found"
123			fi
124		fi
125		rm -f run_make.[coy]
126	done
127fi
128
129YACC=
130for name in /usr/ccs/bin/yacc
131do
132	if test -f $name
133	then
134		YACC=$name
135	fi
136done
137
138if test -n "$YACC"
139then
140	echo "** compare with $YACC"
141	for input in ${TEST_DIR}/*.y
142	do
143		test -f "$input" || continue
144
145		echo "... testing $input"
146		rm -f run_make.[coy]
147
148		case $input in
149		pure_*)
150			echo "... skipping $input"
151			continue;
152			;;
153		*)
154			if fgrep '%pure-parser' $input >/dev/null ||
155			   fgrep '%parse-param' $input >/dev/null ||
156			   fgrep '%lex-param' $input >/dev/null ||
157			   fgrep 'YYLEX_PARAM' $input >/dev/null
158			then
159				echo "... skipping $input"
160				continue;
161			fi
162			;;
163		esac
164
165		sed -e '/^%expect/s,%expect.*,,' $input >>run_make.y
166
167		$YACC run_make.y
168		if test -f y.tab.c
169		then
170			sed -e '/^#line/s,"run_make.y","'$input'",' y.tab.c >run_make.c
171
172			rm -f y.tab.c
173
174			input=run_make.c
175			object=run_make.o
176			if test -f $input
177			then
178				$MY_MAKE $object
179			else
180				echo "?? $input not found"
181			fi
182		fi
183		rm -f run_make.[coy]
184	done
185fi
186