summaryrefslogtreecommitdiffstats
path: root/contrib/byacc/test/run_make.sh
blob: 2bbe95d1841f76d35c458180403452e6b276ccc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/sh
# $Id: run_make.sh,v 1.9 2012/01/15 22:35:01 tom Exp $
# vi:ts=4 sw=4:

# do a test-compile on each of the ".c" files in the test-directory

BISON=`bison --version 2>/dev/null | head -n 1 | sed -e 's/^[^0-9.]*//' -e 's/[^0-9.]*$//'`

if test $# = 1
then
	PROG_DIR=`pwd`
	TEST_DIR=$1
else
	PROG_DIR=..
	TEST_DIR=.
fi

MY_MAKE="make -f $PROG_DIR/makefile srcdir=$PROG_DIR VPATH=$TEST_DIR"

echo '** '`date`
for input in ${TEST_DIR}/*.c
do
	test -f "$input" || continue

	obj=`basename "$input" .c`.o

	$MY_MAKE $obj C_FILES=$input
	test -f $obj && rm $obj

	DEFS=
	case $input in #(vi
	${TEST_DIR}/pure_*)
		# DEFS="-DYYLEX_PARAM=flag -DYYLEX_PARAM_TYPE=int"
		;;
	esac

	if test "x$DEFS" != "x"
	then
		$MY_MAKE $obj C_FILES=$input DEFINES="$DEFS"
		test -f $obj && rm -f $obj
	fi
done

if test -n "$BISON"
then
	echo "** compare with bison $BISON"
	for input in ${TEST_DIR}/*.y
	do
		test -f "$input" || continue

		# Bison does not support pure-parser from command-line.
		# Also, its support for %expect is generally broken.
		# Work around these issues using a temporary file.

		echo "... testing $input"
		rm -f run_make.[coy]

		case $input in
		pure_*)
			if test -z `fgrep -l '%pure-parser' $input`
			then
				echo "%pure-parser" >>run_make.y
			fi
			;;
		esac

		sed -e '/^%expect/s,%expect.*,,' $input >>run_make.y

		bison -y run_make.y
		sed -e '/^#line/s,"run_make.y","'$input'",' y.tab.c >run_make.c

		rm -f y.tab.c

		input=run_make.c
		object=run_make.o
		if test -f $input
		then
			$MY_MAKE $object DEFINES='-DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=1 -DYYSTACK_USE_ALLOCA=0 -DYYMAXDEPTH=0'
		else
			echo "?? $input not found"
		fi
		rm -f run_make.[coy]
	done
fi

YACC=
for name in /usr/ccs/bin/yacc
do
	if test -f $name
	then
		YACC=$name
	fi
done

if test -n "$YACC"
then
	echo "** compare with $YACC"
	for input in ${TEST_DIR}/*.y
	do
		test -f "$input" || continue

		echo "... testing $input"
		rm -f run_make.[coy]

		case $input in
		pure_*)
			echo "... skipping $input"
			continue;
			;;
		*)
			if fgrep '%pure-parser' $input >/dev/null ||
			   fgrep '%parse-param' $input >/dev/null ||
			   fgrep '%lex-param' $input >/dev/null ||
			   fgrep 'YYLEX_PARAM' $input >/dev/null
			then
				echo "... skipping $input"
				continue;
			fi
			;;
		esac

		sed -e '/^%expect/s,%expect.*,,' $input >>run_make.y

		$YACC run_make.y
		sed -e '/^#line/s,"run_make.y","'$input'",' y.tab.c >run_make.c

		rm -f y.tab.c

		input=run_make.c
		object=run_make.o
		if test -f $input
		then
			$MY_MAKE $object
		else
			echo "?? $input not found"
		fi
		rm -f run_make.[coy]
	done
fi
OpenPOWER on IntegriCloud