# Copyright (c) 1998 by Wayne C. Gramlich.
# All rights reserved.

# Permission to use, copy, modify, distribute, and sell this software
# for any purpose is hereby granted without fee provided that the above
# copyright notice and this permission are retained.  The author makes
# no representations about the suitability of this software for any purpose.
# It is provided "as is" without express or implied warranty.

all: everything

ROOT = ../..

include $(ROOT)/Makefile_common.mk
include $(ROOT)/Makefile_private.mk

NSTC_DIRECTORY = ../nstc
NSTC = $(NSTC_DIRECTORY)/$(PLATFORM)/nstc
STCOV = $(NSTC_DIRECTORY)/$(PLATFORM)/stcov

BASES =					\
	lexeme				\
	parse_defines			\
	parse_expression		\
	parse_program			\
	parse_routines			\
	parse_statement
COVER_STS_FILES = ${BASES:%=%_cover.sts}
ERROR_STS_FILES = ${BASES:%=%_errors1.sts}
ERROR_FILES = ${BASES:%=%1.errors}
ALL_STS_FILES =			\
	${COVER_STS_FILES}	\
	${ERROR_STS_FILES}

HTMLS =				\
	index.html
SOURCES =			\
	${ALL_STS_FILES}	\
	Makefile
ALL_FILES =			\
	${HTMLS}		\
	${SOURCES}		\
	source.html


# Some Targets:

.PHONY: all clean copy everything site test

everything: ${SOURCES} $(WAIT) source.html

clean:

site:

copy: source.html

	if [ "$(COPY_DIRECTORY)" = "" ] ;			\
	  then							\
	    echo "Please set COPY_DIRECTORY in `pwd`" ;		\
	    exit 1 ;						\
	  fi
	rm -rf $(COPY_DIRECTORY)
	mkdir -p $(COPY_DIRECTORY)
	cp ${ALL_FILES} source.html $(COPY_DIRECTORY)

# NOTE: program_errors2 is missed in the stuff below.

test: $(NSTC)
	mkdir -p /tmp/$(PLATFORM)
	$(STCOV) -b -z $(NSTC)
	set -e ;						\
	for i in ${BASES} ;					\
	  do 							\
	    rm -f $$i.pass $$i.fail ;				\
	    echo $(NSTC) -m parse $$i\_errors1.sts ;		\
	    if $(NSTC) -m parse $$i\_errors1.sts >output 2>&1 ;	\
	      then						\
		echo "Error: $$i compile succeeded" ;		\
	        exit 1 ;					\
	      fi ;						\
	    if cmp output $$i\1.errors ;			\
	      then						\
		true ;						\
	      else						\
		echo "$$i Compare failed" ;			\
		exit 1 ;					\
	      fi ;						\
	    rm -f output ;					\
	    echo $(NSTC) -m parse $$i\_cover.sts ;		\
	    $(NSTC) -m parse $$i\_cover.sts > /dev/null 2>&1 ;	\
	    $(STCOV) -u -m $$i $(NSTC) | 			\
	     grep -v stcov-ok | cat > output ;			\
	    cat output | sed 's,^.*:\t,,g' > output2 ;		\
	    if cmp output2 $$i.tcov ;				\
	      then						\
		true ;						\
	      else						\
		echo "$$i tcov failed" ;			\
		cat output2 ;					\
	      fi ;						\
	    rm -f output output2 ;				\
	  done
	$(STCOV) -e $(NSTC)

source.html: ${SOURCES}
	@echo -n "Generating $@..."
	@rm -f $@
	@echo '<HTML>' > $@
	@echo '<Head>' >> $@
	@echo '<Title>New STIPPLE Compiler Test Files</Title>' >> $@
	@echo '</Head>' >> $@
	@echo '<Body>' >> $@
	@echo '<H1>' >> $@
	@echo 'New STIPPLE Compiler Test Files' >> $@
	@echo '</H1>' >> $@
	@echo '<P>The following source files are available:</P>' >> $@
	@echo '<UL>' >> $@
	@for i in `ls ${SOURCES} | sort` ; do				\
		echo "  <LI><A HRef='$$i'>$$i</A></LI>" >> $@ ;	\
		done
	@echo '</UL>' >> $@
	@echo '<HR>' >> $@
	@echo '<Address>' >> $@
	@echo '<A HRef="../../../copyright.html">' >> $@
	@echo 'Copyright</A> (c) 1998 by' >> $@
	@echo '<A HRef="../../../gramlich.html">' >> $@
	@echo 'Wayne Gramlich</A> All rights reserved.' >> $@
	@echo '</Address>' >> $@
	@echo '</Body>' >> $@
	@echo '</HTML>' >> $@
	@echo "Done"


