xref: /freebsd/contrib/byacc/test/run_make.sh (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1#!/bin/sh
2# $Id: run_make.sh,v 1.21 2022/11/06 20:57:33 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
19: "${FGREP:=grep -F}"
20ifBTYACC=`$FGREP -l 'define YYBTYACC' config.h > /dev/null; test $? != 0; echo $?`
21
22if test "$ifBTYACC" = 0; then
23	REF_DIR=${TEST_DIR}/yacc
24else
25	REF_DIR=${TEST_DIR}/btyacc
26fi
27
28MY_MAKE="make -f $PROG_DIR/makefile srcdir=$PROG_DIR"
29
30run_make() {
31	C_FILE=`basename "$1"`
32	O_FILE=`basename "$C_FILE" .c`.o
33	shift
34	RETEST=`unset CDPATH; cd $TEST_DIR; pwd`
35	cd "$REF_DIR"
36	test -f "$I_FILE" && rm "$I_FILE"
37	make -f "$PROG_DIR/makefile" EXTRA_CFLAGS=-I$RETEST srcdir="$PROG_DIR" "$O_FILE" "$@"
38	test -f "$O_FILE" && rm "$O_FILE"
39	cd "$THIS_DIR"
40}
41
42echo "** `date`"
43echo "** program is in $PROG_DIR"
44echo "** test-files in $REF_DIR"
45
46for input in ${REF_DIR}/*.c
47do
48	case $input in #(vi
49	${REF_DIR}/err_*|\
50	${REF_DIR}/test-err_*)
51		continue
52		;;
53	esac
54
55	test -f "$input" || continue
56
57	run_make "$input"
58
59	DEFS=
60	case $input in #(vi
61	${REF_DIR}/pure_*)
62		# DEFS="-DYYLEX_PARAM=flag -DYYLEX_PARAM_TYPE=int"
63		;;
64	esac
65
66	if test "x$DEFS" != "x"
67	then
68		run_make "$input" DEFINES="$DEFS"
69	fi
70done
71
72if test -n "$BISON"
73then
74	echo "** compare with bison $BISON"
75	for input in ${TEST_DIR}/*.y
76	do
77		test -f "$input" || continue
78		case $input in
79		${TEST_DIR}/err_*|\
80		${TEST_DIR}/test-err_*)
81			continue
82			;;
83		${TEST_DIR}/ok_syntax*|\
84		${TEST_DIR}/varsyntax*)
85			# Bison does not support all byacc legacy syntax
86			continue
87			;;
88		${TEST_DIR}/btyacc_*)
89			# Bison does not support the btyacc []-action & inherited attribute extensions.
90			continue
91			;;
92		esac
93
94		# Bison does not support pure-parser from command-line.
95		# Also, its support for %expect is generally broken.
96		# Work around these issues using a temporary file.
97
98		echo "... testing $input"
99		rm -f run_make.[coy]
100
101		case $input in
102		${TEST_DIR}/pure_*)
103			if test -z "`$FGREP -i -l '%pure-parser' "$input"`"
104			then
105				echo "%pure-parser" >>run_make.y
106			fi
107			;;
108		esac
109
110		sed -e '/^%expect/s,%expect.*,,' "$input" >>run_make.y
111
112		case $BISON in
113		[3-9].[0-9]*.[0-9]*)
114			bison -Wno-other -Wno-conflicts-sr -Wconflicts-rr -y -Wno-yacc run_make.y
115			;;
116		*)
117			bison -y run_make.y
118			;;
119		esac
120		if test -f "y.tab.c"
121		then
122			sed -e '/^#line/s,"run_make.y","'"$input"'",' y.tab.c >run_make.c
123
124			rm -f y.tab.c
125
126			input=run_make.c
127			object=run_make.o
128			if test -f $input
129			then
130				$MY_MAKE $object DEFINES='-DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=1 -DYYSTACK_USE_ALLOCA=0 -DYYMAXDEPTH=0'
131			else
132				echo "?? $input not found"
133			fi
134		fi
135		rm -f run_make.[coy]
136	done
137fi
138
139YACC=
140for name in /usr/ccs/bin/yacc
141do
142	if test -f $name
143	then
144		YACC=$name
145	fi
146done
147
148if test -n "$YACC"
149then
150	echo "** compare with $YACC"
151	for input in ${TEST_DIR}/*.y
152	do
153		test -f "$input" || continue
154
155		echo "... testing $input"
156		rm -f run_make.[coy]
157
158		case $input in
159		pure_*)
160			echo "... skipping $input"
161			continue;
162			;;
163		*)
164			if $FGREP -i '%pure-parser' "$input" >/dev/null ||
165			   $FGREP -i '%parse-param' "$input" >/dev/null ||
166			   $FGREP -i '%lex-param' "$input" >/dev/null ||
167			   $FGREP -i '%token-table' "$input" >/dev/null ||
168			   $FGREP 'YYLEX_PARAM' "$input" >/dev/null
169			then
170				echo "... skipping $input"
171				continue;
172			fi
173			;;
174		esac
175
176		sed -e '/^%expect/s,%expect.*,,' "$input" >>run_make.y
177
178		$YACC run_make.y
179		if test -f y.tab.c
180		then
181			sed -e '/^#line/s,"run_make.y","'"$input"'",' y.tab.c >run_make.c
182
183			rm -f y.tab.c
184
185			input=run_make.c
186			object=run_make.o
187			if test -f $input
188			then
189				$MY_MAKE $object
190			else
191				echo "?? $input not found"
192			fi
193		fi
194		rm -f run_make.[coy]
195	done
196fi
197