xref: /freebsd/contrib/byacc/test/run_make.sh (revision e17f5b1d)
1#!/bin/sh
2# $Id: run_make.sh,v 1.18 2019/11/25 23:23:26 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	${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 -i -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		case $BISON in
110		[3-9].[0-9]*.[0-9]*)
111			bison -Wno-other -Wno-conflicts-sr -Wconflicts-rr -y -Wno-yacc run_make.y
112			;;
113		*)
114			bison -y run_make.y
115			;;
116		esac
117		if test -f "y.tab.c"
118		then
119			sed -e '/^#line/s,"run_make.y","'$input'",' y.tab.c >run_make.c
120
121			rm -f y.tab.c
122
123			input=run_make.c
124			object=run_make.o
125			if test -f $input
126			then
127				$MY_MAKE $object DEFINES='-DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=1 -DYYSTACK_USE_ALLOCA=0 -DYYMAXDEPTH=0'
128			else
129				echo "?? $input not found"
130			fi
131		fi
132		rm -f run_make.[coy]
133	done
134fi
135
136YACC=
137for name in /usr/ccs/bin/yacc
138do
139	if test -f $name
140	then
141		YACC=$name
142	fi
143done
144
145if test -n "$YACC"
146then
147	echo "** compare with $YACC"
148	for input in ${TEST_DIR}/*.y
149	do
150		test -f "$input" || continue
151
152		echo "... testing $input"
153		rm -f run_make.[coy]
154
155		case $input in
156		pure_*)
157			echo "... skipping $input"
158			continue;
159			;;
160		*)
161			if fgrep -i '%pure-parser' $input >/dev/null ||
162			   fgrep -i '%parse-param' $input >/dev/null ||
163			   fgrep -i '%lex-param' $input >/dev/null ||
164			   fgrep -i '%token-table' $input >/dev/null ||
165			   fgrep 'YYLEX_PARAM' $input >/dev/null
166			then
167				echo "... skipping $input"
168				continue;
169			fi
170			;;
171		esac
172
173		sed -e '/^%expect/s,%expect.*,,' $input >>run_make.y
174
175		$YACC run_make.y
176		if test -f y.tab.c
177		then
178			sed -e '/^#line/s,"run_make.y","'$input'",' y.tab.c >run_make.c
179
180			rm -f y.tab.c
181
182			input=run_make.c
183			object=run_make.o
184			if test -f $input
185			then
186				$MY_MAKE $object
187			else
188				echo "?? $input not found"
189			fi
190		fi
191		rm -f run_make.[coy]
192	done
193fi
194