# -*- makefile -*- mode for emacs
# @(#) $Id: Makefile,v 1.14 2006/07/10 10:05:33 wdietl Exp $

# Copyright (C) 1998-2004 Iowa State University

# This file is part of mjc, a MultiJava Compiler

# mjc is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# mjc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with mjc; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

#
# Developer's Makefile for testing mjc
#

## ----------------------------------------------------------------- 
## At the bottom of this file we import $(TOPDIR)/Make.ProjDefs.  See the
## that file for substantial documentation.
## ----------------------------------------------------------------- 

TOPDIR =	../../../../..

PACKAGE =	org/multijava/mjc/testcase/runtime

SUBDIRS = upcalls relax

## -------------------------------------------------------------
## GOALS

clean-this:	simple-clean local-clean

local-clean:
	$(RM) *.*-ckd *.class core file-list.junk *-expected.old
	$(RM) `cat .cvsignore`

## -------------------------------------------------------------
## Local targets and vars

# flag suppresses cautions
MJC = $(JAVA) org.multijava.mjc.Main
MJCFLAGS = -w0 $(USERMJCFLAGS)
# user can override this on the command line to pass extra flags to mjc
USERMJCFLAGS = 

DIS = $(JAVA) org.multijava.dis.Main
DISFLAGS = --stdout --sorted

SED = sed
RM = rm -f
DIFF = diff -w
MV = mv -f

.SUFFIXES: .java .java-ckd .java-expected .class .class-ckd .class-expected

.java.java-expected:
	-mv $@ $@.old
	$(MJC) $(MJCFLAGS) $< 2>&1 | $(PATHTOFILE) | tee $@

.java.java-ckd:
	$(MJC) $(MJCFLAGS) $< 2>&1 | $(PATHTOFILE) | tee $@

#.class.class-expected:
#	-mv $@ $@.old
#	$(DIS) $(DISFLAGS) $< 2>&1 | $(PATHTOFILE) | tee $@
#
#.class.class-ckd:
#	$(DIS) $(DISFLAGS) $< 2>&1 | $(PATHTOFILE) | tee $@

all: check

check: runtests-this-junit

runtests-this-junit: junittests checkall

runtests-this-nojunit: compileall checkall

TESTFILES = TestCompilesTestSuite

junittests-before:
	@touch skip
	@$(RM) *.class ;
	@$(JAVAC) TestSuite.java TestCompilesTestSuite.java
	@ls *.java | grep -v -f skip > listCompileTests

# compile all test cases.
compileall:
	@echo COMPILING `pwd`
	@touch skip;
	@$(RM) *.class ;
	@-for f in `ls *.java | grep -v -f skip ` ; \
	do \
		$(MAKE) $${f}-test; \
	done 2>&1 | tee checkall.out-ckd
	@echo; echo Completed compiling

%.java-test:
	@if [ ! "$(QUIET)" ]; then echo Compiling $(@F:%.java-test=%.java) ... ; else printf "." ; fi; 
	@$(MJC) $(MJCFLAGS) $(@F:%.java-test=%.java) 2>&1 | $(PATHTOFILE) > $(@F:%.java-test=%.java-ckd) ;
	@$(DIFF) $(@F:%.java-test=%.java-ckd) $(@F:%.java-test=%.java-expected) && \
		(if [ ! "$(QUIET)" ]; then echo 'Compared as expected!'; fi && $(RM) $(@F:%.java-test=%.java-ckd); );

# check generated code for all test cases.
checkall:
	@echo CHECKING SCRIPTS `pwd`
	@-for f in `ls *.sh | grep -v -f skip` ; \
	do \
	  $(MAKE) $${f}-test ; \
	done 2>&1 | tee -a checkall.out-ckd
	@echo; echo Completed `pwd`

%.sh-test:
	@if  [ ! "$(QUIET)" ]  ; then echo Checking $(@F:%.sh-test=%.sh) ... ; else printf "." ; fi
	@chmod +x $(@F:%.sh-test=%.sh)
	@USERMJCFLAGS=$(USERMJCFLAGS) ./$(@F:%.sh-test=%.sh) 2>&1 \
	     | $(PATHTOFILE) | $(FIXTILT) > $(@F:%.sh-test=%.sh-ckd) 
	@$(DIFF) $(@F:%.sh-test=%.sh-expected) $(@F:%.sh-test=%.sh-ckd) && \
	    ( if [ ! "$(QUIET)" ]; then echo 'Compared as expected!' ; fi; ) && \
	    $(RM) $(@F:%.sh-test=%.sh-ckd)

create expected:
	-for f in `ls *.java` ; \
	do \
	  echo Compiling $$f ... ; \
	  $(MV) $${f}-expected $${f}-expected.old ; \
	  $(MJC) $(MJCFLAGS) $$f 2>&1 \
	     | $(PATHTOFILE) > $${f}-expected ; \
	  $(DIFF) $${f}-expected.old $${f}-expected && echo 'Unchanged!' && $(RM) $${f}-expected.old;\
	done 2>&1 | tee create-compile.out-ckd

## ----------------------------------------------------------------------
## GLOBAL DEFINITIONS

include $(TOPDIR)/Make.ProjDefs
