17953eebeSchristos#!/bin/sh 2*e86eba8aSchristos# Id: run_make.sh,v 1.18 2019/11/25 23:23:26 tom Exp 37953eebeSchristos# vi:ts=4 sw=4: 47953eebeSchristos 57953eebeSchristos# do a test-compile on each of the ".c" files in the test-directory 67953eebeSchristos 7e833cfb1SchristosBISON=`bison --version 2>/dev/null | head -n 1 | sed -e 's/^[^0-9.]*//' -e 's/[^0-9.]*$//'` 8e833cfb1Schristos 97953eebeSchristosif test $# = 1 107953eebeSchristosthen 117953eebeSchristos PROG_DIR=`pwd` 127953eebeSchristos TEST_DIR=$1 137953eebeSchristoselse 147953eebeSchristos PROG_DIR=.. 157953eebeSchristos TEST_DIR=. 167953eebeSchristosfi 1763eba854SchristosTHIS_DIR=`pwd` 187953eebeSchristos 1963eba854SchristosifBTYACC=`fgrep -l 'define YYBTYACC' config.h > /dev/null; test $? != 0; echo $?` 2063eba854Schristos 2163eba854Schristosif test $ifBTYACC = 0; then 2263eba854Schristos REF_DIR=${TEST_DIR}/yacc 2363eba854Schristoselse 2463eba854Schristos REF_DIR=${TEST_DIR}/btyacc 2563eba854Schristosfi 2663eba854Schristos 2763eba854SchristosMY_MAKE="make -f $PROG_DIR/makefile srcdir=$PROG_DIR" 2863eba854Schristos 2963eba854Schristosrun_make() { 3063eba854Schristos C_FILE=`basename "$1"` 3163eba854Schristos O_FILE=`basename "$C_FILE" .c`.o 3263eba854Schristos shift 3363eba854Schristos cd $REF_DIR 3463eba854Schristos make -f $PROG_DIR/makefile srcdir=$PROG_DIR $O_FILE $* 3563eba854Schristos test -f $O_FILE && rm $O_FILE 3663eba854Schristos cd $THIS_DIR 3763eba854Schristos} 38e833cfb1Schristos 397953eebeSchristosecho '** '`date` 4063eba854Schristosecho "** program is in $PROG_DIR" 4163eba854Schristosecho "** test-files in $REF_DIR" 4263eba854Schristos 4363eba854Schristosfor input in ${REF_DIR}/*.c 447953eebeSchristosdo 4563eba854Schristos case $input in #(vi 4665d89d9aSchristos ${REF_DIR}/err_*|\ 4765d89d9aSchristos ${REF_DIR}/test-err_*) 4863eba854Schristos continue 4963eba854Schristos ;; 5063eba854Schristos esac 5163eba854Schristos 52e833cfb1Schristos test -f "$input" || continue 53e833cfb1Schristos 5463eba854Schristos run_make "$input" 55e833cfb1Schristos 56e833cfb1Schristos DEFS= 57e833cfb1Schristos case $input in #(vi 5863eba854Schristos ${REF_DIR}/pure_*) 59e833cfb1Schristos # DEFS="-DYYLEX_PARAM=flag -DYYLEX_PARAM_TYPE=int" 60e833cfb1Schristos ;; 61e833cfb1Schristos esac 62e833cfb1Schristos 63e833cfb1Schristos if test "x$DEFS" != "x" 64e833cfb1Schristos then 6563eba854Schristos run_make "$input" DEFINES="$DEFS" 66e833cfb1Schristos fi 677953eebeSchristosdone 68e833cfb1Schristos 69e833cfb1Schristosif test -n "$BISON" 70e833cfb1Schristosthen 71e833cfb1Schristos echo "** compare with bison $BISON" 72e833cfb1Schristos for input in ${TEST_DIR}/*.y 73e833cfb1Schristos do 74e833cfb1Schristos test -f "$input" || continue 7563eba854Schristos case $input in 7665d89d9aSchristos ${TEST_DIR}/err_*|\ 7765d89d9aSchristos ${TEST_DIR}/test-err_*) 7865d89d9aSchristos continue 7965d89d9aSchristos ;; 8065d89d9aSchristos ${TEST_DIR}/ok_syntax*|\ 8165d89d9aSchristos ${TEST_DIR}/varsyntax*) 8265d89d9aSchristos # Bison does not support all byacc legacy syntax 8363eba854Schristos continue 8463eba854Schristos ;; 8563eba854Schristos ${TEST_DIR}/btyacc_*) 8665d89d9aSchristos # Bison does not support the btyacc []-action & inherited attribute extensions. 8763eba854Schristos continue 8863eba854Schristos ;; 8963eba854Schristos esac 90e833cfb1Schristos 91e833cfb1Schristos # Bison does not support pure-parser from command-line. 92e833cfb1Schristos # Also, its support for %expect is generally broken. 93e833cfb1Schristos # Work around these issues using a temporary file. 94e833cfb1Schristos 95e833cfb1Schristos echo "... testing $input" 96e833cfb1Schristos rm -f run_make.[coy] 97e833cfb1Schristos 98e833cfb1Schristos case $input in 9963eba854Schristos ${TEST_DIR}/pure_*) 1008a8e4c9eSchristos if test -z `fgrep -i -l '%pure-parser' $input` 101e833cfb1Schristos then 102e833cfb1Schristos echo "%pure-parser" >>run_make.y 103e833cfb1Schristos fi 104e833cfb1Schristos ;; 105e833cfb1Schristos esac 106e833cfb1Schristos 107e833cfb1Schristos sed -e '/^%expect/s,%expect.*,,' $input >>run_make.y 108e833cfb1Schristos 1098a8e4c9eSchristos case $BISON in 1108a8e4c9eSchristos [3-9].[0-9]*.[0-9]*) 111*e86eba8aSchristos bison -Wno-other -Wno-conflicts-sr -Wconflicts-rr -y -Wno-yacc run_make.y 1128a8e4c9eSchristos ;; 1138a8e4c9eSchristos *) 1148a8e4c9eSchristos bison -y run_make.y 1158a8e4c9eSchristos ;; 1168a8e4c9eSchristos esac 11763eba854Schristos if test -f "y.tab.c" 11863eba854Schristos then 119e833cfb1Schristos sed -e '/^#line/s,"run_make.y","'$input'",' y.tab.c >run_make.c 120e833cfb1Schristos 121e833cfb1Schristos rm -f y.tab.c 122e833cfb1Schristos 123e833cfb1Schristos input=run_make.c 124e833cfb1Schristos object=run_make.o 125e833cfb1Schristos if test -f $input 126e833cfb1Schristos then 127e833cfb1Schristos $MY_MAKE $object DEFINES='-DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=1 -DYYSTACK_USE_ALLOCA=0 -DYYMAXDEPTH=0' 128e833cfb1Schristos else 129e833cfb1Schristos echo "?? $input not found" 130e833cfb1Schristos fi 13163eba854Schristos fi 132e833cfb1Schristos rm -f run_make.[coy] 133e833cfb1Schristos done 134e833cfb1Schristosfi 135e833cfb1Schristos 136e833cfb1SchristosYACC= 137e833cfb1Schristosfor name in /usr/ccs/bin/yacc 138e833cfb1Schristosdo 139e833cfb1Schristos if test -f $name 140e833cfb1Schristos then 141e833cfb1Schristos YACC=$name 142e833cfb1Schristos fi 143e833cfb1Schristosdone 144e833cfb1Schristos 145e833cfb1Schristosif test -n "$YACC" 146e833cfb1Schristosthen 147e833cfb1Schristos echo "** compare with $YACC" 148e833cfb1Schristos for input in ${TEST_DIR}/*.y 149e833cfb1Schristos do 150e833cfb1Schristos test -f "$input" || continue 151e833cfb1Schristos 152e833cfb1Schristos echo "... testing $input" 153e833cfb1Schristos rm -f run_make.[coy] 154e833cfb1Schristos 155e833cfb1Schristos case $input in 156e833cfb1Schristos pure_*) 157e833cfb1Schristos echo "... skipping $input" 158e833cfb1Schristos continue; 159e833cfb1Schristos ;; 160e833cfb1Schristos *) 1618a8e4c9eSchristos if fgrep -i '%pure-parser' $input >/dev/null || 1628a8e4c9eSchristos fgrep -i '%parse-param' $input >/dev/null || 1638a8e4c9eSchristos fgrep -i '%lex-param' $input >/dev/null || 1648a8e4c9eSchristos fgrep -i '%token-table' $input >/dev/null || 165e833cfb1Schristos fgrep 'YYLEX_PARAM' $input >/dev/null 166e833cfb1Schristos then 167e833cfb1Schristos echo "... skipping $input" 168e833cfb1Schristos continue; 169e833cfb1Schristos fi 170e833cfb1Schristos ;; 171e833cfb1Schristos esac 172e833cfb1Schristos 173e833cfb1Schristos sed -e '/^%expect/s,%expect.*,,' $input >>run_make.y 174e833cfb1Schristos 175e833cfb1Schristos $YACC run_make.y 17663eba854Schristos if test -f y.tab.c 17763eba854Schristos then 178e833cfb1Schristos sed -e '/^#line/s,"run_make.y","'$input'",' y.tab.c >run_make.c 179e833cfb1Schristos 180e833cfb1Schristos rm -f y.tab.c 181e833cfb1Schristos 182e833cfb1Schristos input=run_make.c 183e833cfb1Schristos object=run_make.o 184e833cfb1Schristos if test -f $input 185e833cfb1Schristos then 186e833cfb1Schristos $MY_MAKE $object 187e833cfb1Schristos else 188e833cfb1Schristos echo "?? $input not found" 189e833cfb1Schristos fi 19063eba854Schristos fi 191e833cfb1Schristos rm -f run_make.[coy] 192e833cfb1Schristos done 193e833cfb1Schristosfi 194