#
#	  Copyright 1999,2000 by the Purdue Research Foundation for CERIAS (the
#	  Center for Education and Research in Information Assurance and
#	  Security).  All rights reserved.  This work may be used for
#	  non-profit educational and research purposes only.  Any copies made
#	  of this file or portions of its contents must include this copyright
#	  statement.  For information on reuse, licensing, or copying, contact
#	  <cerias-info@cerias.purdue.edu>.
#
#	  This software is experimental in nature and is provided without any
#	  express or implied warranties, including, without limitation, the
#	  implied warranties of merchantability and fitness for any particular
#	  purpose.
#
#         $Id: Makefile,v 1.4 2000/01/31 03:56:30 flack Exp $
#
#  Makefile for BSM parser - extensions to ANTLR
#
#  ANTLR's default convention that nonterminal names MUST start with lowercase
#  letters and terminal names MUST start with capitals would interfere with
#  the BSMParser convention of copying the official BSM identifiers as symbol
#  names.  These files make up a "percent_rule" extension to ANTLR, where any
#  name in the grammar can be any valid Java identifier (within the Basic Latin
#  Unicode block, for the time being), but terminals have a % prefix (which is
#  not considered part of the name).
#
#  Chapman Flack, flack@cs.purdue.edu
#

JAVA_BIN = $(JAVA_HOME)/bin

JAVA = $(JAVA_BIN)/java -Djava.compiler

JAVAC = $(JAVA_BIN)/javac

ANTL = $(JAVA) -cp $(ANTLR_HOME) antlr.Tool

CLASSES = antlr/ANTLRLexer.class \
	  antlr/preprocessor/Preprocessor.class \
	  antlr/preprocessor/PreprocessorLexer.class

.SUFFIXES : .class .java .g

.java.class :
	$(JAVAC) -classpath .:$(ANTLR_CLASSES)  $<

all : $(CLASSES)

antlr/ANTLRLexer.java : antlr/antlr.g
	( cd antlr; $(JAVA) -cp $(ANTLR_CLASSES) antlr.Tool antlr.g )

antlr/preprocessor/Preprocessor.java \
antlr/preprocessor/PreprocessorLexer.java : antlr/preprocessor/preproc.g
	( cd antlr/preprocessor; $(JAVA) -cp $(ANTLR_CLASSES) antlr.Tool preproc.g)

antlr/antlr.g.orig : $(ANTLR_HOME)/antlr/antlr.g
	rm  -f  $@
	cp  $?  $@

antlr/preprocessor/preproc.g.orig : $(ANTLR_HOME)/antlr/preprocessor/preproc.g
	rm  -f  $@
	cp  $?  $@

antlr/antlr.g antlr/preprocessor/preproc.g : \
	antlr/antlr.g.orig antlr/preprocessor/preproc.g.orig percent.pat
	rm -f antlr/antlr.g antlr/preprocessor/preproc.g
	cp antlr/antlr.g.orig antlr/antlr.g
	cp antlr/preprocessor/preproc.g.orig antlr/preprocessor/preproc.g
	patch -p0 <percent.pat
