#!/bin/sh

in=$1
out=$2

echo "GRAMMAR compile script begins"  1>&2
# Perform a command, after echoing it, and abort if it fails.
run () { echo "RUNNING $@" 1>&2 ; if ! "$@"; then exit 1; fi; }

# run yacc -l -v $in
run btyacc -l -v -t $in

# run g++ -g -c y.tab.c -I`pwd`
run g++ -g -c y_tab.c -I`pwd`

# I have no clue why I need certain object files here, while other
# ones seem to be resolved from my executable just fine.  Maybe it has
# to do with how/whether they are used in the executable?  

#run g++ -g -shared -Wl -o $out y.tab.o TripleSink.o ParseType.o
run g++ -g -shared -Wl -o $out y_tab.o TripleSink.o ParseType.o

echo "GRAMMAR compile script ends successfully."  1>&2

exit 0