# Generate jar and native header file using a JDK

.SUFFIXES: .java

CLASSPATH = "src/tclblend:src/tcljava"
    
JCFLAGS = -g:none -source 1.4 -target 1.6 -Xlint:-options

%.class: %.java
	javac $(JCFLAGS) -classpath $(CLASSPATH) $<

TCLBLEND_SRCS = \
	src/tclblend/tcl/lang/CObject.java \
	src/tclblend/tcl/lang/IdleHandler.java \
	src/tclblend/tcl/lang/Interp.java \
	src/tclblend/tcl/lang/Notifier.java \
	src/tclblend/tcl/lang/TclList.java \
	src/tclblend/tcl/lang/TclObject.java \
	src/tclblend/tcl/lang/TimerHandler.java \
	src/tclblend/tcl/lang/Util.java

TCLJAVA_SRCS = \
	src/tcljava/tcl/lang/AdaptorClassLoader.java \
	src/tcljava/tcl/lang/AdaptorGen.java \
	src/tcljava/tcl/lang/ArrayObject.java \
	src/tcljava/tcl/lang/AssocData.java \
	src/tcljava/tcl/lang/BeanEvent.java \
	src/tcljava/tcl/lang/BeanEventMgr.java \
	src/tcljava/tcl/lang/BeanEventParamSet.java \
	src/tcljava/tcl/lang/BlendExtension.java \
	src/tcljava/tcl/lang/ClassRep.java \
	src/tcljava/tcl/lang/Command.java \
	src/tcljava/tcl/lang/CommandWithDispose.java \
	src/tcljava/tcl/lang/EventAdaptor.java \
	src/tcljava/tcl/lang/EventDeleter.java \
	src/tcljava/tcl/lang/Extension.java \
	src/tcljava/tcl/lang/FieldSig.java \
	src/tcljava/tcl/lang/FuncSig.java \
	src/tcljava/tcl/lang/InternalRep.java \
	src/tcljava/tcl/lang/JavaBindCmd.java \
	src/tcljava/tcl/lang/JavaCallCmd.java \
	src/tcljava/tcl/lang/JavaCastCmd.java \
	src/tcljava/tcl/lang/JavaDefineClassCmd.java \
	src/tcljava/tcl/lang/JavaEventCmd.java \
	src/tcljava/tcl/lang/JavaFieldCmd.java \
	src/tcljava/tcl/lang/JavaForCmd.java \
	src/tcljava/tcl/lang/JavaGetInterpCmd.java \
	src/tcljava/tcl/lang/JavaImportCmd.java \
	src/tcljava/tcl/lang/JavaInfoCmd.java \
	src/tcljava/tcl/lang/JavaInstanceofCmd.java \
	src/tcljava/tcl/lang/JavaInvoke.java \
	src/tcljava/tcl/lang/JavaIsNullCmd.java \
	src/tcljava/tcl/lang/JavaIsObjectCmd.java \
	src/tcljava/tcl/lang/JavaLoadCmd.java \
	src/tcljava/tcl/lang/JavaListifyCmd.java \
	src/tcljava/tcl/lang/JavaNewCmd.java \
	src/tcljava/tcl/lang/JavaNullCmd.java \
	src/tcljava/tcl/lang/JavaPropCmd.java \
	src/tcljava/tcl/lang/JavaThrowCmd.java \
	src/tcljava/tcl/lang/JavaTryCmd.java \
	src/tcljava/tcl/lang/PackageNameException.java \
	src/tcljava/tcl/lang/PropertySig.java \
	src/tcljava/tcl/lang/reflect/PkgInvoker.java \
	src/tcljava/tcl/lang/ReflectException.java \
	src/tcljava/tcl/lang/ReflectObject.java \
	src/tcljava/tcl/lang/TCL.java \
	src/tcljava/tcl/lang/TclBoolean.java \
	src/tcljava/tcl/lang/TclClassLoader.java \
	src/tcljava/tcl/lang/TclDouble.java \
	src/tcljava/tcl/lang/TclEvent.java \
	src/tcljava/tcl/lang/TclException.java \
	src/tcljava/tcl/lang/TclIndex.java \
	src/tcljava/tcl/lang/TclInteger.java \
	src/tcljava/tcl/lang/TclNumArgsException.java \
	src/tcljava/tcl/lang/TclObjectBase.java \
	src/tcljava/tcl/lang/TclPosixException.java \
	src/tcljava/tcl/lang/TclRuntimeError.java \
	src/tcljava/tcl/lang/TclString.java \
	src/tcljava/tcl/lang/UnsupportedJDetachCallCmd.java \
	src/tcljava/tcl/lang/VarTrace.java

TCLBLEND_CLASSES = $(TCLBLEND_SRCS:.java=.class)
TCLJAVA_CLASSES = $(TCLJAVA_SRCS:.java=.class)

all:	prebuilt/tclJBlend.jar prebuilt/javaNative.h
    
prebuilt/tclJBlend.jar: $(TCLBLEND_CLASSES) $(TCLJAVA_CLASSES)
	@mkdir -p prebuilt
	cd src/tclblend && jar -cfM ../../prebuilt/tclJBlend.jar \
	    tcl/lang/*.class
	cd src/tcljava && jar -ufM ../../prebuilt/tclJBlend.jar \
	    tcl/lang/*.class tcl/lang/reflect/*.class

prebuilt/javaNative.h: $(TCLBLEND_CLASSES)
	@mkdir -p prebuilt
	javah -jni -force -o $@ -classpath $(CLASSPATH) \
	    tcl.lang.CObject \
	    tcl.lang.IdleHandler \
	    tcl.lang.Interp \
	    tcl.lang.Notifier \
	    tcl.lang.TclList \
	    tcl.lang.TimerHandler \
	    tcl.lang.Util

clean:
	$(RM) src/tclblend/tcl/lang/*.class
	$(RM) src/tcljava/tcl/lang/*.class
	$(RM) src/tcljava/tcl/lang/reflect/*.class

clobber:	clean
	$(RM) prebuilt/tclJBlend.jar prebuilt/javaNative.h

