### -*- makefile -*- A Makefile for building *.class files from *.jtw files

### Copyright (C) 2016 Davin Pearson

### Maintainer: Davin Pearson <davin.pearson@gmail.com>
### Keywords: J.T.W. to Java Makefile

### This program is not part of GNU Emacs

### This program 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 3 of the License, or (at
### your option) any later version.
###
### 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 GNU
### General Public License for more detail.
###
### You should have received a copy of the GNU General Public License
### along with GNU Emacs, see the file COPYING.  If not, see:
###
### <http://www.gnu.org/licenses/gpl.txt>.

### Commentary:

### This Makefile contains code for building *.jtw files into
### *.java files into *.class files and then executing those
### *.class files.

.PRECIOUS:
.PRECIOUS: %.java %.class

JAVAC_FLAGS = -source 1.5 -Xlint:unchecked -Xlint:deprecation
JAVA_FLAGS  = -enableassertions
ifdef IS_DOS
SHELL = c:/cygwin/bin/bash.exe
EMACS = emacs.exe
else
SHELL = /bin/bash
EMACS = emacs
endif

BAK = $(HOME)/bak
DATESTAMP = $$(date +"%Y%m%d-%H%M%S")

%.java: %.jtw
	@echo "* Stage 1 : Debugging $*.jtw and building $*.java file"
	$(EMACS) --batch --eval "(setq *prefix* \"$(PREFIX)\")" --eval "(setq *stump* \"$*\")" --load $(PREFIX)/share/emacs/site-lisp/dlisp/jtw-build-jtw.el \
--funcall doit

%.class: %.java
	@echo "* Stage 2 : Debugging *.java file(s) and building *.class file(s)"
	javac $(JAVAC_FLAGS) $$(find . -name "*.java") \
|& $(EMACS) --batch --eval "(setq *prefix* \"$(PREFIX)\")" --load $(PREFIX)/share/emacs/site-lisp/dlisp/jtw-javac.el --funcall doit \
|& grep "input[0-9]:" - \
|& sed -e "s/input[0-9]://g" -

%.run: %.class
	@echo "* Stage 3 : Running $*.class File"
	java $(JAVA_FLAGS) $* \
|& $(EMACS) --batch --eval "(setq *prefix* \"$(PREFIX)\")" --load $(PREFIX)/share/emacs/site-lisp/dlisp/jtw-java.el --funcall doit \
|& grep "input[0-9]*:" - \
|& sed -e "s/input[0-9]*://g" -

etags:
	etags -l lisp dlisp/*.el

clean:
	rm -fv $$(find . -name "*.java")
	rm -fv $$(find . -name "*.class")


