#
# $Id: Makefile,v 1.1.1.1 2002/09/30 15:09:02 smartine Exp $
#
# Copyright (c) 1999-2000 by David Brownell.  All Rights Reserved.
#
# This program is free software; you may use, copy, modify, and
# redistribute it under the terms of the LICENSE with which it was
# originally distributed.
#
# This program 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
# LICENSE for more details.
#

#
# Autodetect UNIX vs Cygwin/Win32 ... Win32 JDK works fine from
# Cygwin (B20.1) but needs Win32 style paths.
#
ifeq ($(OSTYPE),cygwin32)
    SEP = ;
else
    SEP = :
endif

#
# TESTCASES holds the path to the XML conformance tests.  The
# reference NIST/OASIS distribution is at:
#
#   http://www.oasis-open.org/committees/xmltest/testsuite.htm
#
# However, you will need a more up-to-date copy, such as the one
# in "suite", because each NIST/OASIS distribution has had bugs
# of real significance, and because the W3C is cranking out errata,
# changing the specification.  The NIST/OASIS team has read/write
# access to this CVS copy (in the "suite" subdirectory).
#
# A URL, absolute file path, or relative file path is OK as input
# to the test harness.
#

TESTCASES =	suite/xmlconf.xml
# TESTCASES =	http://www.oasis-open.org/committees/xmltest/xmlconf.xml

default:
	@echo "Use this directory for running XML 1.0 Conformance tests."
	@echo ""
	@echo "make sanity ... runs all sanity checks"
	@echo "make basics ... tests a key set of parsers"
	@echo "make extras ... tests some other parsers"
	@echo "make everything ... tests all parsers"
	@echo "make clean ... cleanup includes removing test output"
	@echo ""
	@echo "For testing Java SAX/SAX2 processors: "
	@echo "  make java-sanity ... tests bootstrap parser and validator"
	@echo "  make java-basics ... tests a key set of Java parsers"
	@echo "  make java-extras ... tests some other Java parsers"
	@echo "  make java-everything ... tests all the Java parsers"
	@echo ""
ifeq ($(OSTYPE),cygwin32)
	@echo "For testing COM/DOM processors using MS-Windows Scripting Host: "
	@echo "  make com-sanity ... tests bootstrap parser and validator"
	@echo "  make com-basics ... tests a key set of COM parsers"
	@echo "  make com-extras ... tests some other COM parsers"
	@echo "  make com-everything ... tests all the COM parsers"
	@echo ""
endif

sanity:		java-sanity com-sanity
basics:		java-basics com-basics
extras:		java-extras com-extras
everything:	java-everything com-everything

all: everything

clean:
	rm -rf Log report-*.html *~

##############################################################################
#
# JAVA PARSER FRAMEWORK
#
##############################################################################

JAVALIB =	../lib/java

#
# Classpath is built up by automatic then manual steps.
# This distribution is self-sufficient; you can test
# a separately distributed SAX parser without using it
# to bootstrap the test harness.
#
# Current JAXP based distributions, such as GNU ClasspathX
# or Apache Crimson or Xerces, will often be installed as
# extension libraries in $(JAVA_HOME)/jre/lib/ext so that
# the classpaths here won't need updating.
#
CPATH :=	$(JAVALIB)/classes

#
# What JDK is installed?  Builds work a bit differently... JDK 1.1
# needs classes.zip explicitly in CPATH.
#
JDK :=		$(filter-out java version, $(shell java -version 2>&1))
JDK :=		$(subst ",,$(JDK))

ifeq ($(findstring 1.1, $(JDK)),1.1)
    ifeq ($(origin JAVA_HOME),undefined)
	JAVA_HOME := $(patsubst %/bin/java,%,$(shell which java))
    endif
    CPATH := "$(CPATH)$(SEP)$(JAVA_HOME)/lib/classes.zip"
endif

#
# The bundled AElfred2 parser is used to bootstrap the harness.
# Any SAX2 parser could be used so long as it's "conformant enough"
# to read in the test database and report template, and report
# validity errors in the test database.   (The report template
# has no DTD.)
#
# The parser under test is controlled separately, through a
# command line parameter.
#
JFLAGS =

# try the bootstrap parser and its validator
java-sanity:		report-aelf2-nv.html report-aelf2-val.html
	java $(JFLAGS) \
		-classpath "$(CPATH)" xml.DoParse \
		$(TESTCASES) "nsfix | validate"
	java $(JFLAGS) \
		-classpath "$(CPATH)" xml.DoParse \
		report-aelf2-nv.html "nsfix | validate"
	java $(JFLAGS) \
		-classpath "$(CPATH)" xml.DoParse \
		report-aelf2-val.html "nsfix | validate"

java-basics: 	\
	report-aelf2-nv.html \
	report-aelf2-val.html \
	report-crimson-val.html \
	report-crimson-nv.html \
	report-xerces-jnv.html \
	report-xerces-jval.html

#
# See http://sax.sourceforge.net for a current listing of such parsers.
# There are many others which are of mostly historical interest.
#
java-extras:	\
	report-oracle-nv.html \
	report-oracle-val.html \
	report-xp.html \
	report-aelf.html

java-everything: java-basics java-extras 



##############################################################################
#
# RUN JAVA PROCESSOR TESTS
#
##############################################################################

# TODO: drive all of this from a table of releases-to-test.

# YOU MUST COLLECT ALL THE PARSERS YOU TEST!  Save them in your extensions
# directory, this one, or something like that.

# CPATH := $(CPATH):gnujaxp.jar:crimson.jar:xerces.jar


# Note that Aelfred 1.2a suffers some file descriptor leaks, sufficient
# to cause lots of FD-related errors to turn up in this test.
report-aelf.html:
	java -classpath "$(CPATH)" $(JFLAGS) \
		xml.testing.Driver \
		$(TESTCASES) com.megginson.sax.AElfredAdapter template.xml \
		"nv" \
		"SAX2 Wrapper, AElfred 1.2a" \
		> report-aelf.html

# JAXP 1.1 reference bundles the Crimson parser (Java Project X, updated)
# That's what JDK 1.4 bundles.

report-crimson-nv.html:
	java -classpath "$(CPATH)" $(JFLAGS) \
		-Dxml.testing.Driver.validation=false \
		-Dxml.testing.Driver.general-entities=true \
		-Dxml.testing.Driver.parameter-entities=true \
		xml.testing.Driver \
		$(TESTCASES) org.apache.crimson.parser.XMLReaderImpl template.xml \
		"nv" \
		"Crimson 1.1.3" \
		> report-crimson-nv.html
report-crimson-val.html:
	java -classpath "$(CPATH)" $(JFLAGS) \
		-Dxml.testing.Driver.validation=true \
		-Dxml.testing.Driver.general-entities=true \
		-Dxml.testing.Driver.parameter-entities=true \
		xml.testing.Driver \
		$(TESTCASES) org.apache.crimson.parser.XMLReaderImpl template.xml \
		"val" \
		"Crimson 1.1.3" \
		> report-crimson-val.html

# XP 0.5 -- for a long time the de-facto reference implementation
# The SAX2Driver class is available from http://sax.sourceforge.net
# (the links page) if not from XP itself; it subclasses ParserAdapter.
report-xp.html:
	java -classpath "$(CPATH)" $(JFLAGS) \
		xml.testing.Driver \
		$(TESTCASES) com.jclark.xml.sax.SAX2Driver template.xml \
		"nv" \
		"XP 0.5" \
		> report-xp.html

# Oracle's v2 parser ...
report-oracle-nv.html:
	java -classpath "$(CPATH)" $(JFLAGS) \
		xml.testing.Driver \
		$(TESTCASES) oracle.xml.parser.v2.SAXParser template.xml \
		"nv" \
		"Oracle v9.0.2.0.0C" \
		> report-oracle-nv.html
report-oracle-val.html:
	java -classpath "$(CPATH)" $(JFLAGS) \
		-Dxml.testing.Driver.validation=true \
		xml.testing.Driver \
		$(TESTCASES) oracle.xml.parser.v2.SAXParser template.xml \
		"val" \
		"Oracle v9.0.2.0.0C" \
		> report-oracle-val.html

# AElfred2, and an optional validation layer onatopof it.
report-aelf2-nv.html:
	java -classpath "$(CPATH)" $(JFLAGS) \
		xml.testing.Driver \
		$(TESTCASES) gnu.xml.aelfred2.SAXDriver template.xml \
		"nv" \
		"AElfred2/GNU" \
		> report-aelf2-nv.html
report-aelf2-val.html:
	java -classpath "$(CPATH)" $(JFLAGS) \
		-Dxml.testing.Driver.validation=true \
		xml.testing.Driver \
		$(TESTCASES) gnu.xml.aelfred2.XmlReader template.xml \
		"val" \
		"AElfred2/GNU, with Validation" \
		> report-aelf2-val.html

# AElfred2 (an OLD version), as compiled with GCJ
report-gcj-aelf2-nv.html:
	$(JAVALIB)/driver-gcj \
		$(TESTCASES) xml.aelfred2.SAXDriver template.xml \
		"nv" \
		"AElfred2/OLD/gcj" \
		> report-gcj-aelf2-nv.html
report-gcj-aelf2-val.html:
	$(JAVALIB)/driver-gcj \
		$(TESTCASES) xml.aelfred2.Validator template.xml \
		"val" \
		"AElfred2/OLD/gcj, with Validation" \
		> report-gcj-aelf2-val.html

# Xerxes/J
report-xerces-jnv.html:
	java -classpath "$(CPATH)" $(JFLAGS) \
		xml.testing.Driver \
		$(TESTCASES) org.apache.xerces.parsers.SAXParser template.xml \
		"nv" \
		"Xerxes/Java 1.4.3" \
		> report-xerces-jnv.html
report-xerces-jval.html:
	java -classpath "$(CPATH)" $(JFLAGS) \
		-Dxml.testing.Driver.validation=true \
		xml.testing.Driver \
		$(TESTCASES) org.apache.xerces.parsers.SAXParser template.xml \
		"val" \
		"Xerxes/Java 1.4.3" \
		> report-xerces-jval.html


ifeq ($(OSTYPE),cygwin32)

##############################################################################
#
# COM PARSER FRAMEWORK
#
##############################################################################

# try the bootstrap parser and its validator
com-sanity:		report-msxml-nv.html report-msxml-val.html
	@echo "TODO:  validate the test suite document."
	@echo "TODO:  validate the generated test reports."

com-basics: 	\
	report-msxml-nv.html \
	report-msxml-val.html \
	report-xerces-cnv.html \
	report-xerces-cval.html
# Mozilla too

com-extras: 	\
	report-msxml2-nv.html \
	report-msxml2-val.html

com-everything: com-basics com-extras 


##############################################################################
#
# RUN COM PROCESSOR TESTS
#
##############################################################################

# FIXME: the harness isn't reporting the OS and version being used.
# There must be some JavaScript call to determine them.

# FIXME: the descriptions are bogus too; report DLL version

report-msxml-nv.html:
	cscript //nologo harness.js \
		/parser=MSXML.DOMDocument \
		/nvreport=report-msxml-nv.html \
		/suite=$(TESTCASES) /desc="MSXML from IE5.5"

report-msxml-val.html:
	cscript //nologo harness.js \
		/parser=MSXML.DOMDocument \
		/vreport=report-msxml-val.html \
		/suite=$(TESTCASES) /desc="MSXML from IE5.5"

# May technology preview, "msxml3.dll"

report-msxml2-nv.html:
	cscript //nologo harness.js \
		/parser=MSXML2.DOMDocument.3.0 \
		/nvreport=report-msxml2-nv.html \
		/suite=$(TESTCASES) /desc="MSXML, May 2000 preview"

report-msxml2-val.html:
	cscript //nologo harness.js \
		/parser=MSXML2.DOMDocument.3.0 \
		/vreport=report-msxml2-val.html \
		/suite=$(TESTCASES) /desc="MSXML, May 2000 preview"

# http://xml.apache.org/dist/xerces-c/experimental/xerces-com-1_2_0.zip

report-xerces-cnv.html:
	cscript //nologo harness.js \
		/parser=Xerces.DOMDocument \
		/nvreport=report-xerces-cnv.html \
		/suite=$(TESTCASES) /desc="Xerces/COM v.current"

report-xerces-cval.html:
	cscript //nologo harness.js \
		/parser=Xerces.DOMDocument \
		/vreport=report-xerces-cval.html \
		/suite=$(TESTCASES) /desc="Xerces/COM v.current"

else

com-sanity:
com-basics:
com-extras:
com-everything:

endif

dump:
	@echo OSTYPE is ... "$(OSTYPE)"
	@echo SEP is ... "$(SEP)"
	@echo JDK is ... "$(JDK)"
	@echo CPATH is ... "$(CPATH)"

