# -*- makefile -*- mode for emacs
# @(#) $Id: Makefile,v 1.22 2004/05/04 19:13:49 cdchambers 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.

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

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

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

clean-this:	simple-clean local-clean

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

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

MJC = java org.multijava.mjc.Main
MJCFLAGS = -W $(USERMJCFLAGS)
# user can override this on the command line to pass extra flags to mjc
USERMJCFLAGS = 

PACKAGE = org/multijava/mjc/testcase/typecheck
TESTFILES = 	TopMethodCalcTestCase \
	 	testsTestCase \
		MixedClassConstantDispatch3TestCase \
		InheritInnerOrderTestCase \
		TestsWithOutputTestSuite \
		atTestsTestCase \
		reservedWordTestsTestCase \
		RelaxClientsTestCase

SUBDIRS = subpack subpack2 subpackageconstant1 subpackageconstant2

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

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

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

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

all: check

check: runtests-this-junit

# check all JML specs.

runtests-this-junit: removerelaxclasses junittests 

runtests-this-nojunit: removerelaxclasses checkjava checksh

removerelaxclasses:
	@$(RM) relaxAccessGF*.class RelaxAccessClass*.class

LIST_TESTS = ls *.java | grep -v -f skip

junittests-before:
	@touch skip
	@$(LIST_TESTS) >  listTestsWithOutput

checkjava:
	@touch skip
	@-for f in `$(LIST_TESTS)` ; \
	do \
	    $(MAKE) $${f}-test ; \
	done 2>&1 | tee checkall.out-ckd

checksh:
	@-for f in `ls *.sh | grep -v -f skip` ; \
	do \
	    $(MAKE) $${f}-test ; \
	done 2>&1 | tee -a checkall.out-ckd
	@echo

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

%.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 Checking $$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.out-ckd

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

include $(TOPDIR)/Make.ProjDefs
