# /**(c)
# 
#   Copyright (C) 2006, 2007, 2008, 2009 Michael Stilkerich, Johannes Bauer, Christian Wawersich 
# 
#   This file is part of the JOSEK operating system.
# 
# 	JOSEK is free software: you can redistribute it and/or modify it under the
#   terms of the Lesser GNU General Public License as published by the Free
#   Software Foundation, either version 3 of the License, or (at your option)
#   any later version.
# 
# 	JOSEK 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 Lesser General Public License for
#   more details. You should have received a copy of the GNU Lesser General
#   Public License along with JOSEK. If not, see <http://www.gnu.org/licenses/>.
# 
#   Please contact keso@cs.fau.de for more info.
# 
#   (c)**/
ifeq ($(JDK),)
	JDK := $(error Environment variable JDK is not set)
endif

JAVA   ?= "$(JDK)/bin/java"
JAVAC  ?= "$(JDK)/bin/javac"
JAVACC ?= javacc
JAR    ?= "$(JDK)/bin/jar"

JOSEKSRC:=$(shell find josek -name '*.java')
JOSEKFILES:=$(shell find josek/code/ -type f -not -path "*/.svn*" )
JOSEKOPTS = -f keso_main_complex.oil
JOSEKOPTS += -h avr
JOSEKOPTS += -r
JOSEKOPTS += -D signals
JOSEKOPTS += -D timer
#JOSEKOPTS += -D debug
#JOSEKOPTS += -D codecomments
#JOSEKOPTS += -D stackprotector
#JOSEKOPTS += -D stackprotector_simple
#JOSEKOPTS += -D assertions
JOSEKOPTS += -D saveram

.PHONY: all
all: josek.jar

classes/josek/JOsek.class: josek/parser/ConfigReader.java josek/conditionparser/ConditionParser.java $(JOSEKSRC)
	@$(JAVAC) -d classes -sourcepath . $(JOSEKSRC)
#	$(JAVAC) -Xlint:unchecked -d classes -sourcepath . $(JOSEKSRC)

josek.jar: classes/josek/JOsek.class $(JOSEKFILES)
	@find josek/code/ -type d -not -path "*/.svn*" -exec mkdir -p classes/{} \;
	@find josek/code/ -type f -not -path "*/.svn*" -exec cp {} classes/{} \;
	@$(JAR) -cfm josek.jar manifest -C classes josek/

josek/parser/ConfigReader.java: ConfigReader.jj
	@$(JAVACC) -OUTPUT_DIRECTORY:josek/parser ConfigReader.jj

josek/conditionparser/ConditionParser.java: ConditionParser.jj
	@$(JAVACC) -OUTPUT_DIRECTORY:josek/conditionparser ConditionParser.jj

.PHONY: rebuild clean proper tags
rebuild: clean all

clean:
	@rm -rf classes/* 

proper: clean
	@rm -f josek/parser/* josek/conditionparser/* tags


