# Unix makefile for tclblend and jacl
#
# RCS: @(#) $Id: Makefile.in,v 1.16 2000/12/22 09:47:13 mdejong Exp $

SHELL = /bin/sh

# Specify which Tcl/Java system to build (jacl or tclblend).
TCLJAVA	= @TCLJAVA@

# The directory containing the Tcl sources and headers appropriate
# for this version of Tk ("srcdir" will be replaced or has already
# been replaced by the configure script):
TCL_GENERIC_DIR = @TCL_SRC_DIR@/generic

# The directory containing the Tcl library files
TCL_LIBRARY_DIR = @TCL_SRC_DIR@/library

# The directory containing the Tcl library archive file appropriate
# for this version of Tcl:
TCL_BIN_DIR = @TCL_BIN_DIR@
TCL_BIN_TCLSH=$(TCL_BIN_DIR)/tclsh

# The directory where the Tcl library archive file is installed
TCL_INSTALL_LIB_DIR = @TCL_INSTALL_LIB_DIR@

# The full path name of the tclsh executable after it is installed
TCLSH=@TCLSH@


#----------------------------------------------------------------
# The information below is modified by the configure script when
# Makefile is generated from Makefile.in.  You shouldn't normally
# modify any of this stuff by hand.
#----------------------------------------------------------------

TOP_DIR			= @srcdir@

# Fully qualified paths for programs used in build process
JAVA			= @JAVA@
JAVA_G			= @JAVA_G@
JAVAC			= @JAVAC@
JAVAH			= @JAVAH@
JAR			= @JAR@
JDB			= @JDB@
GDB			= @GDB@
DDD			= @DDD@
XTERM			= xterm
JAVA_FLAGS		= @JAVA_FLAGS@
JAVA_G_FLAGS		= @JAVA_G_FLAGS@
JAVAC_FLAGS		= @JAVAC_FLAGS@
JAVAC_D_FLAG		= @JAVAC_D_FLAG@
JAR_EXTRACT_FLAGS	= @JAR_EXTRACT_FLAGS@
JAR_COMPRESS_FLAGS	= @JAR_COMPRESS_FLAGS@
JAR_NOCOMPRESS_FLAGS	= @JAR_NOCOMPRESS_FLAGS@
JDB_FLAGS		=
DDD_FLAGS		=
JAVA_CLASSPATH		= @JAVA_CLASSPATH@

# Include flags to pass to the compiler
# For example: -I/opt/jdk1.1.4/include -I/opt/jdk1.1.4/include/solaris
JAVA_INCLUDE_FLAGS	= @JAVA_INCLUDE_FLAGS@

# Library flags to pass to compiler
# For example: -L/opt/jdk1.1.4/lib/sparc/native_threads -ljava
JAVA_LIB_FLAGS		= @JAVA_LIB_FLAGS@

# A colon seperated list of directories to pass to rld
JAVA_LIB_RUNTIME_PATH	= @JAVA_LIB_RUNTIME_PATH@



BUILD_DIR		= @BUILD_DIR@
UNIX_DIR		= $(TOP_DIR)/unix
WIN_DIR			= $(TOP_DIR)/win
TCLBLEND_SRC_DIR	= $(TOP_DIR)/src/tclblend
TCLBLEND_BUILD_DIR	= $(BUILD_DIR)/tclblend
JACL_SRC_DIR		= $(TOP_DIR)/src/jacl
JACL_BUILD_DIR		= $(BUILD_DIR)/jacl
TCLJAVA_SRC_DIR		= $(TOP_DIR)/src/tcljava
TCLJAVA_BUILD_DIR	= $(BUILD_DIR)/tcljava
NATIVE_SRC_DIR		= $(TOP_DIR)/src/native
DEMOS_SRC_DIR		= $(TOP_DIR)/demos
DEMOS_BUILD_DIR		= $(BUILD_DIR)/demos
TEST_TCL_DIR		= $(TOP_DIR)/tests
TEST_SRC_DIR		= $(TOP_DIR)/src/tests
TEST_TCLBLEND_SRC_DIR	= $(TEST_SRC_DIR)/tclblend
TEST_JACL_SRC_DIR	= $(TEST_SRC_DIR)/jacl
TEST_TCLJAVA_SRC_DIR	= $(TEST_SRC_DIR)/tcljava
TEST_BUILD_DIR		= $(BUILD_DIR)/tests
MISC_DIR		= $(TOP_DIR)/src
CC			= @CC@
CC_OBJ_FLAG		= -c
CFLAGS			= @TCL_CFLAGS@
SHLIB_CFLAGS		= @SHLIB_CFLAGS@
SHLIB_LD		= @SHLIB_LD@
SHLIB_LD_LIBS		= @SHLIB_LD_LIBS@
SHLIB_PREFIX		= @SHLIB_PREFIX@
SHLIB_SUFFIX		= @SHLIB_SUFFIX@
SHLIB_VERSION		= @SHLIB_VERSION@
TCL_DBGX		= @TCL_DBGX@
TCLJAVA_DBGX		= @TCLJAVA_DBGX@

TCLJAVA_VERSION		= @TCLJAVA_VERSION@
TCLJAVA_NODOT_VERSION	= @TCLJAVA_NODOT_VERSION@

# directories to search for shared libs, needed for TCL_LD_SEARCH_FLAGS
LIB_RUNTIME_DIR		= $(JAVA_LIB_RUNTIME_PATH):$(TCL_INSTALL_LIB_DIR)
TCL_LD_SEARCH_FLAGS 	= @TCL_LD_SEARCH_FLAGS@
TCLBLEND_LIB_FILE 	= $(SHLIB_PREFIX)tclblend$(TCLJAVA_DBGX)$(SHLIB_SUFFIX)



# Extra shared lib stuff needed on some systems.
# If you want to run the TclBlend tests on a Linux system
# with the Blackdown JDK port you will need to install Motif or LessTif.
# Note: this is only required before Blackdown version 1.1.8

# If you are using Motif then uncomment this line

#TCLBLEND_LD_PRELOAD="@TCLBLEND_LD_PRELOAD@ libXm.so libXpm.so libXt.so libSM.so libICE.so libXext.so libX11.so"

# If you are using LessTif then uncomment this line

#TCLBLEND_LD_PRELOAD="@TCLBLEND_LD_PRELOAD@ libXt.so libXm.so libXext.so"

# If you are using neither Motif nor LessTif then comment out this line

TCLBLEND_LD_PRELOAD	= "@TCLBLEND_LD_PRELOAD@"

TCLBLEND_LD_BIND_NOW	= @TCLBLEND_LD_BIND_NOW@



# Default top-level directories in which to install architecture-
# specific files (exec_prefix) and machine-independent files such
# as scripts (prefix).  The values specified here may be overridden
# at configure-time with the --exec-prefix and --prefix options
# to the "configure" script.

prefix			= @prefix@
exec_prefix		= @exec_prefix@

# Directory containing platform dependent binaries
BIN_INSTALL_DIR 	= $(exec_prefix)/bin

# Directory where platform independent files live. This
# includes the .jar files and any .tcl files
XP_TCLJAVA_INSTALL_DIR	= $(prefix)/lib/tcljava$(TCLJAVA_VERSION)

# Directory where platform dependent files (shared libraries) live.
TCLJAVA_INSTALL_DIR	= $(exec_prefix)/lib/tcljava$(TCLJAVA_VERSION)


# Tcl used to let the configure script choose which program to use
# for installing, but there are just too many different versions of
# "install" around;  better to use the install-sh script that comes
# with the distribution, which is slower but guaranteed to work.

INSTALL			= @srcdir@/install-sh -c
INSTALL_PROGRAM		= ${INSTALL}
INSTALL_DATA		= ${INSTALL} -m 644

# AUX_CLASSPATH is used for Java Studio test coverage
# Note that AUX_CLASSPATH should have a leading colon (:),
# see the jstclblendTest rule for an example

TCLBLEND_CLASSPATH	= $(TCLJAVA_BUILD_DIR):$(TCLBLEND_BUILD_DIR):$(JAVA_CLASSPATH)$(AUX_CLASSPATH)

JACL_CLASSPATH		= $(TCLJAVA_BUILD_DIR):$(JACL_BUILD_DIR):$(JAVA_CLASSPATH)$(AUX_CLASSPATH)

TCLJAVA_CLASSPATH	= $(TCLJAVA_BUILD_DIR):$(MISC_DIR)/empty/empty.jar:$(JAVA_CLASSPATH)$(AUX_CLASSPATH)

DEMOS_CLASSPATH		= $(BUILD_DIR)/$(TCLJAVA).jar:$(BUILD_DIR)/tcljava.jar:$(JAVA_CLASSPATH)$(AUX_CLASSPATH)

TEST_CLASSPATH		= $(JAVA_CLASSPATH):$(TEST_BUILD_DIR):$(BUILD_DIR)/$(TCLJAVA).jar:$(BUILD_DIR)/tcljava.jar$(AUX_CLASSPATH)

JACL_DEBUG_CLASSPATH	=  $(TEST_CLASSPATH):$(TCLJAVA_SRC_DIR):$(JACL_SRC_DIR)
TCLBLEND_DEBUG_CLASSPATH = $(TEST_CLASSPATH):$(TCLJAVA_SRC_DIR):$(TCLBLEND_SRC_DIR)

# Libraries to use when linking: (used by SHLIB_LD_LIBS)
LIBS			= $(TCL_LD_SEARCH_FLAGS) \
				$(JAVA_LIB_FLAGS) \
				@TCL_BUILD_LIB_SPEC@ @TCL_LIBS@


CC_SWITCHES 		= \
	$(CFLAGS) $(CDEFS) -D_REENTRANT -DTCL_MEM_DEBUG \
	-I. -I$(NATIVE_SRC_DIR) -I$(TCL_GENERIC_DIR) \
	$(JAVA_INCLUDE_FLAGS) $(SHLIB_CFLAGS)

DEPEND_SWITCHES = $(CFLAGS) -I$(NATIVE_SRC_DIR) -I$(TCL_GENERIC_DIR) \
	$(JAVA_INCLUDE_FLAGS) \
	$(AC_FLAGS) $(MATH_FLAGS) \
	$(GENERIC_FLAGS) $(PROTO_FLAGS) $(MEM_DEBUG_FLAGS) \
	-DTCL_SHLIB_EXT=\"$(SHLIB_SUFFIX)\"

OBJS = \
	javaCmd.o \
	javaIdle.o \
	javaInterp.o \
	javaObj.o \
	javaList.o \
	javaNotifier.o \
	javaTimer.o \
	javaUtil.o

SRCS = \
	$(NATIVE_SRC_DIR)/javaCmd.c \
	$(NATIVE_SRC_DIR)/javaIdle.c \
	$(NATIVE_SRC_DIR)/javaInterp.c \
	$(NATIVE_SRC_DIR)/javaObj.c \
	$(NATIVE_SRC_DIR)/javaList.c \
	$(NATIVE_SRC_DIR)/javaNotifier.c \
	$(NATIVE_SRC_DIR)/javaTimer.c \
	$(NATIVE_SRC_DIR)/javaUtil.c

TCLBLEND_JNI_HEADER_CLASS_NAMES = \
	tcl.lang.CObject \
	tcl.lang.IdleHandler \
	tcl.lang.Interp \
	tcl.lang.Notifier \
	tcl.lang.TclList \
	tcl.lang.TimerHandler \
	tcl.lang.Util




#---------------------------------------
# Default is to build the tcljava target
# then build jacl or tclblend depending on
# what the variable TCLJAVA is set to
#---------------------------------------

all: tcljava $(TCLJAVA)

install: $(TCLJAVA).install.check tcljava.install $(TCLJAVA).install

uninstall: $(TCLJAVA).uninstall tcljava.uninstall

# This rule is used to query the build CLASSPATH from an external program
classpath:
	@echo "CLASSPATH $(TEST_CLASSPATH)"

#----------------------------------------------------------------
# Build Tcl Blend
#----------------------------------------------------------------

tclblend.build: tclblend.clean tcljava.check
	@echo "#"
	@echo "# Making tclblend.build"
	@echo "#"
	mkdir -p $(TCLBLEND_BUILD_DIR)
	cd $(TCLBLEND_SRC_DIR) ;\
	CLASSPATH=$(TCLBLEND_CLASSPATH) \
	$(JAVAC) $(JAVAC_FLAGS) \
		$(JAVAC_D_FLAG) $(TCLBLEND_BUILD_DIR) tcl/lang/*.java

# Only use this if you are developing tclblend code and you need to recompile
# a lot. It will not clean up before building and tclblend.jar will not be
# created. you really need to know what you are doing to use this rule.
tclblend.fastbuild:
	@if test ! -d $(TCLBLEND_BUILD_DIR); then \
		echo "tclblend must be built normally before a fastbuild" ; \
		exit 1 ; \
	fi
	cd $(TCLBLEND_SRC_DIR) ;\
	CLASSPATH=$(TCLBLEND_CLASSPATH) \
	$(JAVAC) $(JAVAC_FLAGS) \
		$(JAVAC_D_FLAG) $(TCLBLEND_BUILD_DIR) tcl/lang/*.java

# tclblend.jar needs to depend on tclblend.build so that the
# classfiles get rebuilt each time the jar is built

tclblend.jar: tclblend.build
	cd $(TCLBLEND_BUILD_DIR) ;\
	CLASSPATH=$(JAVA_CLASSPATH) \
	$(JAR) $(JAR_NOCOMPRESS_FLAGS) $(BUILD_DIR)/tclblend.jar tcl


tclblend: tclblend.jar $(TCLBLEND_LIB_FILE)
	cp -f $(MISC_DIR)/pkgIndex.tcl $(BUILD_DIR)
	mkdir $(BUILD_DIR)/xputils
	cp $(MISC_DIR)/xputils/*.tcl $(BUILD_DIR)/xputils


# Build the shared library
$(TCLBLEND_LIB_FILE): $(OBJS)
	$(SHLIB_LD) -o $(TCLBLEND_LIB_FILE) $(OBJS) $(SHLIB_LD_LIBS)


# javaNative.h is created by javah in the build directory.
$(OBJS): javaNative.h

javaCmd.o: $(NATIVE_SRC_DIR)/javaCmd.c
	$(CC) $(CC_OBJ_FLAG) $(CC_SWITCHES) $(NATIVE_SRC_DIR)/javaCmd.c

javaIdle.o: $(NATIVE_SRC_DIR)/javaIdle.c
	$(CC) $(CC_OBJ_FLAG) $(CC_SWITCHES) $(NATIVE_SRC_DIR)/javaIdle.c

javaInterp.o: $(NATIVE_SRC_DIR)/javaInterp.c
	$(CC) $(CC_OBJ_FLAG) $(CC_SWITCHES) $(NATIVE_SRC_DIR)/javaInterp.c

javaObj.o: $(NATIVE_SRC_DIR)/javaObj.c
	$(CC) $(CC_OBJ_FLAG) $(CC_SWITCHES) $(NATIVE_SRC_DIR)/javaObj.c

javaList.o: $(NATIVE_SRC_DIR)/javaList.c
	$(CC) $(CC_OBJ_FLAG) $(CC_SWITCHES) $(NATIVE_SRC_DIR)/javaList.c

javaNotifier.o: $(NATIVE_SRC_DIR)/javaNotifier.c
	$(CC) $(CC_OBJ_FLAG) $(CC_SWITCHES) $(NATIVE_SRC_DIR)/javaNotifier.c

javaTimer.o: $(NATIVE_SRC_DIR)/javaTimer.c
	$(CC) $(CC_OBJ_FLAG) $(CC_SWITCHES) $(NATIVE_SRC_DIR)/javaTimer.c

javaUtil.o: $(NATIVE_SRC_DIR)/javaUtil.c
	$(CC) $(CC_OBJ_FLAG) $(CC_SWITCHES) $(NATIVE_SRC_DIR)/javaUtil.c

javaNative.h:
	CLASSPATH=$(TCLBLEND_CLASSPATH) \
	$(JAVAH) -jni -o javaNative.h $(TCLBLEND_JNI_HEADER_CLASS_NAMES)

custom.warn:
	@echo ""
	@echo "########################################################"
	@echo "Using the custom tclblend shell may or may not work"
	@echo "on your system. The green threads version of the"
	@echo "custom shell may be less reliable than the native"
	@echo "threads version. The custom shell option is for"
	@echo "developers only as it can be more difficult to"
	@echo "install and use when compared to the shared libs method."
	@echo "########################################################"
	@echo ""

custom.o: $(UNIX_DIR)/custom.c
	$(CC) -c $(CC_SWITCHES) $(UNIX_DIR)/custom.c

# Build the tclblend shared lib before building custom.o
custom: tclblend.check custom.warn custom.o
	LD_LIBRARY_PATH=$(BUILD_DIR):$(TCL_BIN_DIR):$(JAVA_ARCH_NATIVE_RUNTIME_LIBS):$(LD_LIBRARY_PATH) \
	SHLIB_PATH=$(BUILD_DIR):$(TCL_BIN_DIR):$(JAVA_ARCH_NATIVE_RUNTIME_LIBS):$(SHLIB_PATH) \
	$(CC) -o custom -g custom.o $(TCLBLEND_LIB_FILE) $(LIBS)

custom.check:
	@if test ! -f custom ; then \
		$(MAKE) TCLJAVA=$(TCLJAVA) custom ; \
	fi


# Run the green threads version of the tclblend cutom shell.
# This rule does a little trick so that the custom shell is
# linked to the green threads version of the java lib.

custom_shell_green:
	rm -f $(TCLBLEND_LIB_FILE)
	$(MAKE) JAVA_ARCH_NATIVE_LIB=$(JAVA_ARCH_GREEN_LIB) \
            JAVA_ARCH_NATIVE_RUNTIME_LIBS=$(JAVA_ARCH_GREEN_RUNTIME_LIBS) custom
	TCLLIBPATH=$(BUILD_DIR) \
	TCL_LIBRARY=$(TCL_LIBRARY_DIR) \
	LD_LIBRARY_PATH=$(BUILD_DIR):$(TCL_BIN_DIR):$(JAVA_ARCH_GREEN_RUNTIME_LIBS):$(LD_LIBRARY_PATH) \
	SHLIB_PATH=$(BUILD_DIR):$(TCL_BIN_DIR):$(JAVA_ARCH_GREEN_RUNTIME_LIBS):$(SHLIB_PATH) \
	JAVA=$(JAVA) \
	BUILD_DIR=$(BUILD_DIR) \
	CLASSPATH=$(TEST_CLASSPATH) \
	./custom


# Run the native threads version of the tclblend custom shell
# always rebuild TCLBLEND_LIB_FILE just in case it was linked to
# to the green threads libs becasue we ran custom_shell_green

custom_shell_native:
	rm -f $(TCLBLEND_LIB_FILE)
	$(MAKE) custom
	TCLLIBPATH=$(BUILD_DIR) \
	TCL_LIBRARY=$(TCL_LIBRARY_DIR) \
	LD_LIBRARY_PATH=$(BUILD_DIR):$(TCL_BIN_DIR):$(JAVA_ARCH_NATIVE_RUNTIME_LIBS):$(LD_LIBRARY_PATH) \
	SHLIB_PATH=$(BUILD_DIR):$(TCL_BIN_DIR):$(JAVA_ARCH_NATIVE_RUNTIME_LIBS):$(SHLIB_PATH) \
	JAVA=$(JAVA) \
	BUILD_DIR=$(BUILD_DIR) \
	CLASSPATH=$(TEST_CLASSPATH) \
	./custom



#
# This rule is run before installing, it is used to do any checks that
# are needed before we actually install tclblend.
#

tclblend.install.check:
	@if test ! -x $(TCLSH) ; then \
		echo "Tcl has not been installed, please install it before installing Tcl Blend" ; \
		exit 1 ; \
	fi



#
# Install tclBlend, if the user did not build tclblend already
# it would have been built by the tcljava.install rule
#
tclblend.install: tclblend.check
	@echo "#"
	@echo "# Installing tclblend"
	@echo "#"
	@if test ! -d $(XP_TCLJAVA_INSTALL_DIR) ; then \
		echo "Making directory $(XP_TCLJAVA_INSTALL_DIR)" ; \
		mkdir -p $(XP_TCLJAVA_INSTALL_DIR) ; \
		chmod 755 $(XP_TCLJAVA_INSTALL_DIR) ; \
	fi
	@echo "Installing $(TCLBLEND_LIB_FILE) in $(TCLJAVA_INSTALL_DIR)"
	@$(INSTALL_DATA) $(TCLBLEND_LIB_FILE) $(TCLJAVA_INSTALL_DIR)
	@chmod 555 $(TCLJAVA_INSTALL_DIR)/$(TCLBLEND_LIB_FILE)
	@echo "Installing tclblend.jar in $(XP_TCLJAVA_INSTALL_DIR)"
	@$(INSTALL_DATA) tclblend.jar $(XP_TCLJAVA_INSTALL_DIR)
	@echo "Installing pkgIndex.tcl in $(XP_TCLJAVA_INSTALL_DIR)"
	@$(INSTALL_DATA) pkgIndex.tcl $(XP_TCLJAVA_INSTALL_DIR)
	@echo "Installing xputils package in $(prefix)/lib"
	@rm -rf $(prefix)/lib/xputils
	@mkdir -p $(prefix)/lib/xputils
	@chmod 755 $(prefix)/lib/xputils
	@$(INSTALL_DATA) xputils/pkgIndex.tcl $(prefix)/lib/xputils
	@$(INSTALL_DATA) xputils/xputils.tcl $(prefix)/lib/xputils
	@$(INSTALL_DATA) xputils/iload.tcl $(prefix)/lib/xputils
	@echo "Installing jtclsh in $(BIN_INSTALL_DIR)"
	@$(INSTALL_PROGRAM) jtclsh $(BIN_INSTALL_DIR)
	@chmod a+rx $(BIN_INSTALL_DIR)/jtclsh
	@echo "Installing jwish in $(BIN_INSTALL_DIR)"
	@cd $(BIN_INSTALL_DIR); rm -f jwish; ln -s jtclsh jwish
	@if env $(BIN_INSTALL_DIR)/jtclsh Test.tcl; then \
		DO=NOTHING ; \
	else \
		echo "Test failed ... you may need to edit $(BIN_INSTALL_DIR)/jtclsh by hand to set the correct paths" ;   \
	fi



tclblend.uninstall:
	@echo "#"
	@echo "# Uninstalling tclblend"
	@echo "#"
	@echo "Uninstalling $(TCLJAVA_INSTALL_DIR)/$(TCLBLEND_LIB_FILE)"
	@rm -f $(TCLJAVA_INSTALL_DIR)/$(TCLBLEND_LIB_FILE)
	@echo "Uninstalling $(XP_TCLJAVA_INSTALL_DIR)/tclblend.jar"
	@rm -f $(XP_TCLJAVA_INSTALL_DIR)/tclblend.jar
	@echo "Uninstalling $(XP_TCLJAVA_INSTALL_DIR)/pkgIndex.tcl"
	@rm -f $(XP_TCLJAVA_INSTALL_DIR)/pkgIndex.tcl
	@echo "Uninstalling $(BIN_INSTALL_DIR)/jtclsh"
	@rm -f $(BIN_INSTALL_DIR)/jtclsh 
	@echo "Uninstalling $(BIN_INSTALL_DIR)/jwish"
	@rm -f $(BIN_INSTALL_DIR)/jwish
	@if env rmdir $(XP_TCLJAVA_INSTALL_DIR) 2> /dev/null; then \
		echo "Removing directory $(XP_TCLJAVA_INSTALL_DIR)" ; \
	fi



#
# Check to make sure tclblend is built
#

tclblend.check: tcljava.check
	@if test ! -f tclblend.jar ; then \
		$(MAKE) TCLJAVA=$(TCLJAVA) tclblend.jar ; \
	fi
	@ if test ! -f $(TCLBLEND_LIB_FILE) ; then \
		$(MAKE) TCLJAVA=$(TCLJAVA) $(TCLBLEND_LIB_FILE) ; \
		cp -f $(MISC_DIR)/pkgIndex.tcl $(BUILD_DIR) ; \
	fi




#----------------------------------------------------------------
# Build Jacl
#----------------------------------------------------------------

jacl: jacl.jar

jacl.build: jacl.clean tcljava.check
	mkdir -p $(JACL_BUILD_DIR)
	cd $(JACL_SRC_DIR) ;\
	CLASSPATH=$(JACL_CLASSPATH) \
	$(JAVAC) $(JAVAC_FLAGS) \
		$(JAVAC_D_FLAG) $(JACL_BUILD_DIR) \
                tcl/lang/*.java sunlabs/brazil/util/regexp/*.java
	cp -fr $(JACL_SRC_DIR)/tcl/lang/library\
		$(JACL_BUILD_DIR)/tcl/lang/library


# Only use this if you are developing jacl code and you need to recompile
# a lot. It will not clean up before building and jacl.jar will not be
# created you really need to know what you are doing to use this rule
jacl.fastbuild:
	@if test ! -d $(JACL_BUILD_DIR); then \
		echo "jacl must be built normally before a fastbuild" ; \
		exit 1 ; \
	fi
	cd $(JACL_SRC_DIR) ;\
	CLASSPATH=$(JACL_CLASSPATH) \
	$(JAVAC) $(JAVAC_FLAGS) \
		$(JAVAC_D_FLAG) $(JACL_BUILD_DIR) \
                tcl/lang/*.java sunlabs/brazil/util/regexp/*.java

# jacl.jar needs to depend on jacl.build so that the
# classfiles get rebuilt each time the jar is built
jacl.jar: jacl.build
	cd $(JACL_BUILD_DIR) ;\
	CLASSPATH=$(JAVA_CLASSPATH) \
	$(JAR) $(JAR_NOCOMPRESS_FLAGS) $(BUILD_DIR)/jacl.jar tcl sunlabs


#
# This rule is run before installing, it is used to do any checks that
# are needed before we actually install jacl. Currently, there are none.
#

jacl.install.check:


#
# Install jacl, if the user did not build jacl already
# it would have been built by the jacl.check rule
#
jacl.install: jacl.check
	@echo "#"
	@echo "# Installing jacl"
	@echo "#"
	@echo "Installing jacl.jar in $(XP_TCLJAVA_INSTALL_DIR)"
	@$(INSTALL_DATA) $(BUILD_DIR)/jacl.jar $(XP_TCLJAVA_INSTALL_DIR)
	@echo "Installing jaclsh in $(BIN_INSTALL_DIR)"
	@$(INSTALL_PROGRAM) $(BUILD_DIR)/jaclsh $(BIN_INSTALL_DIR)
	@chmod 755 $(BIN_INSTALL_DIR)/jaclsh
	@if env $(BIN_INSTALL_DIR)/jaclsh Test.tcl; then \
		DO=NOTHING ; \
	else \
		echo "Test failed ... you may need to edit $(BIN_INSTALL_DIR)/jaclsh by hand to set the correct paths" ;   \
	fi


jacl.uninstall:
	@echo "#"
	@echo "# Uninstalling jacl"
	@echo "#"
	@echo "Uninstalling $(XP_TCLJAVA_INSTALL_DIR)/jacl.jar"
	@rm -f $(XP_TCLJAVA_INSTALL_DIR)/jacl.jar
	@echo "Uninstalling $(BIN_INSTALL_DIR)/jaclsh"
	@rm -f $(BIN_INSTALL_DIR)/jaclsh 


#
# Check to make sure jacl is built
#

jacl.check: tcljava.check
	@if test ! -f jacl.jar ; then \
		$(MAKE) TCLJAVA=$(TCLJAVA) jacl ; \
	fi



#----------------------------------------------------------------
# Build the TclJava Package.
#----------------------------------------------------------------

tcljava: tcljava.jar

tcljava.build: tcljava.clean
	@echo "#"
	@echo "# Making tcljava.build"
	@echo "#"
	mkdir -p $(TCLJAVA_BUILD_DIR)
	cd $(TCLJAVA_SRC_DIR) ;\
	CLASSPATH=$(TCLJAVA_CLASSPATH) \
	$(JAVAC) $(JAVAC_FLAGS) \
		$(JAVAC_D_FLAG) $(TCLJAVA_BUILD_DIR) \
		tcl/lang/reflect/*.java
	cd $(TCLJAVA_SRC_DIR) ;\
	CLASSPATH=$(TCLJAVA_CLASSPATH) \
	$(JAVAC) $(JAVAC_FLAGS) \
	$(JAVAC_D_FLAG) $(TCLJAVA_BUILD_DIR) \
		tcl/lang/*.java
	cp -fr $(TCLJAVA_SRC_DIR)/tcl/lang/library \
		$(TCLJAVA_BUILD_DIR)/tcl/lang/library


# Only use this if you are developing tcljava code and you need to recompile
# a lot. It will not clean up before building and tcljava.jar will not be
# created. you really need to know what you are doing to use this rule.
tcljava.fastbuild:
	@if test ! -d $(TCLJAVA_BUILD_DIR); then \
		echo "tcljava must be built normally before a fastbuild" ; \
		exit 1 ; \
	fi
	cd $(TCLJAVA_SRC_DIR) ;\
	CLASSPATH=$(TCLJAVA_CLASSPATH) \
	$(JAVAC) $(JAVAC_FLAGS) \
	$(JAVAC_D_FLAG) $(TCLJAVA_BUILD_DIR) \
		tcl/lang/*.java

# tcljava.jar needs to depend on tcljava.build so that the
# classfiles get rebuilt each time the jar is built
tcljava.jar: tcljava.build
	cd $(TCLJAVA_BUILD_DIR) ;\
	CLASSPATH=$(JAVA_CLASSPATH) \
	$(JAR) $(JAR_NOCOMPRESS_FLAGS) $(BUILD_DIR)/tcljava.jar tcl


#
# Install tcljava, if the user did not build already
# then this rule will do a regular build before installing
#

tcljava.install: tcljava.check
	@echo "#"
	@echo "# Installing tcljava"
	@echo "#"
	@for i in $(TCLJAVA_INSTALL_DIR) \
		 $(BIN_INSTALL_DIR) \
		 $(XP_TCLJAVA_INSTALL_DIR) ; \
	    do \
	    if test ! -d $$i  ; then \
		echo "Making directory $$i"; \
		mkdir -p $$i; \
		chmod 755 $$i; \
		else true; \
	    fi; \
	done;
	@echo "Installing tcljava.jar in $(XP_TCLJAVA_INSTALL_DIR)"
	@$(INSTALL_DATA) $(BUILD_DIR)/tcljava.jar $(XP_TCLJAVA_INSTALL_DIR)



#
# We must be careful to only uninstall tcljava when both jacl and
# tclblend have already been uninstalled.
#

tcljava.uninstall:
	@echo "#"
	@echo "# Uninstalling tcljava"
	@echo "#"
	@if test ! -f $(XP_TCLJAVA_INSTALL_DIR)/tclblend.jar && \
		test ! -f $(XP_TCLJAVA_INSTALL_DIR)/jacl.jar ; then \
	    echo "Uninstalling $(XP_TCLJAVA_INSTALL_DIR)/tcljava.jar" ; \
	    rm -f $(XP_TCLJAVA_INSTALL_DIR)/tcljava.jar ; \
	    for i in $(XP_TCLJAVA_INSTALL_DIR) \
		 $(TCLJAVA_INSTALL_DIR) \
		 $(BIN_INSTALL_DIR) ; \
	    do \
	        if test -d $$i && env rmdir -p $$i 2> /dev/null ; then \
		    echo "Removing directory $$i" ; \
	        fi; \
	    done; \
	fi

#
# Check to make sure tcljava is built
#

tcljava.check:
	@if test ! -f tcljava.jar ; then \
		$(MAKE) TCLJAVA=$(TCLJAVA) tcljava ; \
	fi



#----------------------------------------------------------------
# Build and run regression tests files for jacl and tclblend
#----------------------------------------------------------------

check: test

test: test_$(TCLJAVA).check test_$(TCLJAVA).exec

test.build: test.clean test_tcljava.build test_$(TCLJAVA).build

test_tcljava.check:
	@if test ! -f $(BUILD_DIR)/tests/.tcljava ; then \
		$(MAKE) TCLJAVA=$(TCLJAVA) test_tcljava.build ; \
	fi

test_$(TCLJAVA).check:
	@if test ! -f $(BUILD_DIR)/tests/.$(TCLJAVA) ; then \
		$(MAKE) TCLJAVA=$(TCLJAVA) test_$(TCLJAVA).build ; \
	fi

test_jacl.build: jacl.check test_tcljava.check
	@echo "#"
	@echo "# Making test_jacl.build"
	@echo "#"
	@rm -f tests/.jacl
	cd $(TEST_JACL_SRC_DIR) ;\
	CLASSPATH=$(TEST_CLASSPATH) \
	$(JAVAC) $(JAVAC_FLAGS) \
		$(JAVAC_D_FLAG) $(TEST_BUILD_DIR) tcl/lang/*.java
	@touch tests/.jacl

test_tclblend.build: tclblend.check test_tcljava.check
	@echo "#"
	@echo "# Making test_tclblend.build"
	@echo "#"
	@rm -f tests/.tclblend
	cd $(TEST_TCLBLEND_SRC_DIR) ;\
	CLASSPATH=$(TEST_CLASSPATH) \
	$(JAVAC) $(JAVAC_FLAGS) \
		$(JAVAC_D_FLAG) $(TEST_BUILD_DIR) tests/*.java tcl/lang/*.java
	@touch tests/.tclblend

# only use test.clean on make clean or on test.build so that a shared
# build of tclblend and jacl tests can co-exist in the tests directory.
# we also must check to see that jacl or tclblend has been built at this
# point or else we would get an error while compiling the tests cases
# as the test cases make refrences to tcl.lang.Intep

test_tcljava.build: $(TCLJAVA).check
	@echo "#"
	@echo "# Making test_tcljava.build"
	@echo "#"
	@rm -f tests/.tcljava
	mkdir -p $(TEST_BUILD_DIR)
	cd $(TEST_TCLJAVA_SRC_DIR) ;\
	CLASSPATH=$(TEST_CLASSPATH) \
	$(JAVAC) $(JAVAC_FLAGS) \
		$(JAVAC_D_FLAG) $(TEST_BUILD_DIR) pkg1/*.java pkg2/*.java \
		tcl/lang/*.java tests/*.java tests/invoke/*.java \
		tests/javainfo/*.java tests/signature/*.java \
		tests/javabind/*.java tests/exec/*.java
	mkdir -p $(TEST_BUILD_DIR)/javaload
	@# workaround for bug in jikes (extra mkdir)
	mkdir -p $(TEST_BUILD_DIR)/javaload/tests/javaload
	@# workaround for bug in jikes (extra dir on CLASSPATH)
	cd $(TEST_TCLJAVA_SRC_DIR) ;\
	CLASSPATH=$(TEST_CLASSPATH):$(TEST_BUILD_DIR)/javaload \
	$(JAVAC) $(JAVAC_FLAGS) \
		$(JAVAC_D_FLAG) $(TEST_BUILD_DIR)/javaload javaload/*.java
	cd $(TEST_BUILD_DIR)/javaload; \
	CLASSPATH=$(JAVA_CLASSPATH) \
	$(JAR) $(JAR_NOCOMPRESS_FLAGS) test9.jar Test9Extension.class; \
	rm Test9Extension.class
	cd $(TEST_BUILD_DIR)/javaload; \
	CLASSPATH=$(JAVA_CLASSPATH) \
	$(JAR) $(JAR_NOCOMPRESS_FLAGS) test10.jar Test10Extension.class; \
	rm Test10Extension.class
	@touch tests/.tcljava


test_jacl.exec: test_jacl.check
	@(  echo \
	  set auto_path [concat [pwd] [set auto_path]]\; \
	  cd $(TOP_DIR)/tests\; \
	  puts \"pwd is [pwd]\"\; \
	  puts \"CLASSPATH is [set env\(CLASSPATH\)]\"\; \
	  puts \"auto_path is [set auto_path]\"\; \
	  source all.tcl\; \
	  puts \"Tests done.\"\; \
          exit; ) | \
	CLASSPATH=$(TEST_CLASSPATH) \
	$(JAVA) $(JAVA_FLAGS) \
		-DBUILD_DIR=$(BUILD_DIR) -DJAVA=$(JAVA) tcl.lang.Shell




test_tclblend.exec: test_tclblend.check
	@(  echo \
	  set auto_path [concat [pwd] [set auto_path]]\; \
	  cd $(TOP_DIR)/tests\; \
	  puts \"pwd is [pwd]\"\; \
	  puts \"CLASSPATH is [set env\(CLASSPATH\)]\"\; \
	  puts \"auto_path is [set auto_path]\"\; \
	  source all.tcl\; \
	  puts \"Tests done.\"\; \
          exit; ) | \
	LD_PRELOAD=$(TCLBLEND_LD_PRELOAD) \
	LD_BIND_NOW=$(TCLBLEND_LD_BIND_NOW) \
	LD_LIBRARY_PATH=$(BUILD_DIR):$(TCL_BIN_DIR):$(JAVA_LIB_RUNTIME_PATH):$(LD_LIBRARY_PATH) \
	SHLIB_PATH=$(BUILD_DIR):$(TCL_BIN_DIR):$(JAVA_LIB_RUNTIME_PATH):$(SHLIB_PATH) \
	KAFFELIBRARYPATH=$(BUILD_DIR):$(TCL_BIN_DIR):$(JAVA_LIB_RUNTIME_PATH) \
	TCL_LIBRARY=$(TCL_LIBRARY_DIR) \
	TCL_LIBRARY=$(TCL_LIBRARY_DIR) \
	CLASSPATH=$(TEST_CLASSPATH) \
	JAVA=$(JAVA) \
	BUILD_DIR=$(BUILD_DIR) \
	$(TCL_BIN_TCLSH)

#----------------------------------------------------------------
# shell : used to drop the user into a jacl or tclblend shell
#----------------------------------------------------------------


shell: shell_$(TCLJAVA)

shell_jacl: jacl.check
	@echo "To run test: cd $(TOP_DIR)/tests ; source all.tcl"
	CLASSPATH=$(TEST_CLASSPATH) \
	$(JAVA) $(JAVA_FLAGS) \
		-DBUILD_DIR=$(BUILD_DIR) -DJAVA=$(JAVA) tcl.lang.Shell


shell_tclblend: tclblend.check
	@echo "To run test: cd $(TOP_DIR)/tests ; source all.tcl"
	LD_PRELOAD=$(TCLBLEND_LD_PRELOAD) \
	LD_BIND_NOW=$(TCLBLEND_LD_BIND_NOW) \
	LD_LIBRARY_PATH=$(BUILD_DIR):$(TCL_BIN_DIR):$(JAVA_LIB_RUNTIME_PATH):$(LD_LIBRARY_PATH) \
	SHLIB_PATH=$(BUILD_DIR):$(TCL_BIN_DIR):$(JAVA_LIB_RUNTIME_PATH):$(SHLIB_PATH) \
	KAFFELIBRARYPATH=$(BUILD_DIR):$(TCL_BIN_DIR):$(JAVA_LIB_RUNTIME_PATH) \
	TCL_LIBRARY=$(TCL_LIBRARY_DIR) \
	TCLLIBPATH=$(BUILD_DIR) \
	CLASSPATH=$(TEST_CLASSPATH) \
	JAVA=$(JAVA) \
	BUILD_DIR=$(BUILD_DIR) \
	$(TCL_BIN_TCLSH)


#----------------------------------------------------------------
# debug : run a Jacl or Tcl Blend session inside a debugger
#----------------------------------------------------------------


# Invoke remote (two process) jdb debug session for Jacl.
# This will fire off an Xterm that Jacl will actually run in
# and it will invoke DDD-jdb to debug that interactive session

jdb_jacl: jacl.check
	@rm -f tmp.*
	@echo "echo \"Type Jacl comamnds into this shell, output will go to jdb shell.\"" >> tmp.run_jacl
	@echo "$(JAVA_G) $(JAVA_G_FLAGS) -DBUILD_DIR=$(BUILD_DIR) \
		-DJAVA=$(JAVA) tcl.lang.Shell | tee tmp.out" >> tmp.run_jacl
	@CLASSPATH=$(JACL_DEBUG_CLASSPATH) \
	    $(XTERM) -T Jacl -e /bin/sh tmp.run_jacl &
	@echo "Waiting for Java to initialize"
	@sleep 5
	@if test ! -s tmp.out ; then \
	    echo "Still waiting" ;\
	    sleep 10 ;\
	fi
	@if test ! -s tmp.out ; then \
	    echo "Still waiting" ;\
	    sleep 5 ;\
	fi
	@if test -s tmp.out ; then \
	    echo "Starting JDB, type commands into the xterms" ;\
	    echo "echo \"JDB command shell\"" >> tmp.run_jdb ;\
	    echo "grep password tmp.out | sed 's/[A-Z|a-z| ]*=//' > tmp.password" >> tmp.run_jdb ;\
	    echo "CLASSPATH=$(JACL_DEBUG_CLASSPATH) ; export CLASSPATH" >> tmp.run_jdb ;\
	    echo "$(JDB) $(JDB_FLAGS) -host localhost -password \`cat tmp.password\` 2> tmp.err_jdb" >> tmp.run_jdb ;\
	    $(XTERM) -T JDB-Jacl -e /bin/sh tmp.run_jdb & \
	else \
	    echo "Giving Up" ; \
	fi


# Invoke local (single process) jdb debug session for Jacl

jdb_local_jacl: jacl.check
	CLASSPATH=$(JACL_DEBUG_CLASSPATH) \
	$(JDB) $(JDB_FLAGS) \
		-DBUILD_DIR=$(BUILD_DIR) -DJAVA=$(JAVA) tcl.lang.Shell


gdb_jacl: jacl.check
	echo "NOT IMPLEMENTED"


# Invoke remote (two process) DDD-jdb debug session for Jacl.
# This will fire off an Xterm that Jacl will actually run in
# and it will invoke DDD-jdb to debug that interactive session

ddd_jacl: jacl.check
	@rm -f tmp.*
	@echo "echo \"Type Jacl comamnds into this shell, output will go to DDD.\"" >> tmp.run_jacl
	@echo "$(JAVA_G) $(JAVA_G_FLAGS) -DBUILD_DIR=$(BUILD_DIR) \
		-DJAVA=$(JAVA) tcl.lang.Shell | tee tmp.out" >> tmp.run_jacl
	@CLASSPATH=$(JACL_DEBUG_CLASSPATH) \
	    $(XTERM) -T Jacl -e /bin/sh tmp.run_jacl &
	@echo "Waiting for Java to initialize"
	@sleep 5
	@if test ! -s tmp.out ; then \
	    echo "Still waiting" ;\
	    sleep 10 ;\
	fi
	@if test ! -s tmp.out ; then \
	    echo "Still waiting" ;\
	    sleep 5 ;\
	fi
	@if test -s tmp.out ; then \
	    echo "Starting DDD, type commands into the debugger" ;\
	    grep password tmp.out | sed 's/[A-Z|a-z| ]*=//' > tmp.password ;\
	    CLASSPATH=$(JACL_DEBUG_CLASSPATH) \
	    $(DDD) $(DDD_FLAGS) \
	        --jdb --debugger "$(JDB) -host localhost -password `cat tmp.password` \
	        -DBUILD_DIR=$(BUILD_DIR) -DJAVA=$(JAVA)" tcl.lang.Shell & \
	else \
	    echo "Giving Up" ; \
	fi



# Invoke local (single process) DDD-jdb debug session for Jacl

ddd_local_jacl : jacl.check
	CLASSPATH=$(JACL_DEBUG_CLASSPATH) \
	$(DDD) $(DDD_FLAGS) \
		--jdb --debugger "$(JDB) -DBUILD_DIR=$(BUILD_DIR) -DJAVA=$(JAVA)" \
		tcl.lang.Shell &



# Invoke ddd to debug Tcl Blend session (you still will need to attach inside DDD)

ddd_tclblend : tclblend.check
	$(DDD) $(DDD_FLAGS) --gdb $(TCL_BIN_TCLSH) &
	@$(MAKE) TCLJAVA=tclblend shell

gdb_tclblend : tclblend.check
	@$(MAKE) TCLJAVA=tclblend shell TCL_BIN_TCLSH="$(GDB) $(TCL_BIN_TCLSH)"

# Invoke the debug session for Jacl or Tcl Blend "make ddd"

ddd : ddd_$(TCLJAVA)

# Invoke the debug session for Tcl Blend "make gdb"

gdb : gdb_$(TCLJAVA)




#----------------------------------------------------------------
# Demos
#----------------------------------------------------------------

demos: $(TCLJAVA).check demos.build demos_$(TCLJAVA).build

demos.build: demos.clean
	mkdir -p $(DEMOS_BUILD_DIR)
	cp -fr $(DEMOS_SRC_DIR)/gluepkg $(DEMOS_BUILD_DIR)/gluepkg
	cp -fr $(DEMOS_SRC_DIR)/gridDemo $(DEMOS_BUILD_DIR)/gridDemo
	cp -fr $(DEMOS_SRC_DIR)/packDemo $(DEMOS_BUILD_DIR)/packDemo
	cp -fr $(DEMOS_SRC_DIR)/simplepkg $(DEMOS_BUILD_DIR)/simplepkg
	cp -fr $(DEMOS_SRC_DIR)/watchpkg $(DEMOS_BUILD_DIR)/watchpkg
	cd $(DEMOS_BUILD_DIR)/gluepkg; \
	CLASSPATH=$(DEMOS_CLASSPATH) \
	$(JAVAC) $(JAVAC_FLAGS) *.java
	cd $(DEMOS_BUILD_DIR)/packDemo; \
	CLASSPATH=$(DEMOS_CLASSPATH) \
	$(JAVAC) $(JAVAC_FLAGS) *.java
	cd $(DEMOS_BUILD_DIR)/simplepkg; \
	CLASSPATH=$(DEMOS_CLASSPATH) \
	$(JAVAC) $(JAVAC_FLAGS) *.java
	cd $(DEMOS_BUILD_DIR)/watchpkg; \
	CLASSPATH=$(DEMOS_CLASSPATH) \
	$(JAVAC) $(JAVAC_FLAGS) *.java

# This rule must be run after the demos.build rule
demos_jacl.build:
	cp -fr $(DEMOS_SRC_DIR)/pyramidpkg $(DEMOS_BUILD_DIR)/pyramidpkg
	cd $(DEMOS_BUILD_DIR)/pyramidpkg; \
	CLASSPATH=$(DEMOS_CLASSPATH) \
	$(JAVAC) $(JAVAC_FLAGS) *.java

demos_tclblend.build:

#----------------------------------------------------------------
# Other functions
#----------------------------------------------------------------

depend:
	@if test "$(TCLJAVA)" = "jacl"; then \
	    echo "'make depend' only works with tclblend" ; \
	    exit 1 ; \
        fi
	@#create empty javaNative.h file if it is not there already
	@touch javaNative.h
	makedepend -- $(DEPEND_SWITCHES) -- $(SRCS)

jaclsh: $(TOP_DIR)/jaclsh.in
	./config.status

jtclsh: $(TOP_DIR)/jtclsh.in
	./config.status

Makefile: $(TOP_DIR)/Makefile.in
	./config.status

configure: $(TOP_DIR)/configure.in
	@echo "# running autoconf on configure.in"
	autoconf

clean: tclblend.clean jacl.clean tcljava.clean \
	demos.clean test.clean tmp.clean

tclblend.clean:
	rm -f  *.o $(TCLBLEND_LIB_FILE) custom javaNative.h
	rm -rf $(TCLBLEND_BUILD_DIR)
	rm -f  tclblend.jar
	rm -f  pkgIndex.tcl
	rm -rf xputils

jacl.clean:
	rm -rf $(JACL_BUILD_DIR)
	rm -f  jacl.jar

tcljava.clean:
	rm -rf $(TCLJAVA_BUILD_DIR)
	rm -f  tcljava.jar

demos.clean: 
	rm -rf $(DEMOS_BUILD_DIR)

test.clean:
	rm -f  $(TEST_TCL_DIR)/core $(BUILD_DIR)/core
	rm -rf $(TEST_BUILD_DIR)

tmp.clean:
	rm -rf META-INF so_locations tmp.*

distclean: clean
	rm -f config.cache config.log config.status
	rm -f lib.exp confdefs.h depend.out
	rm -f Test.class Test.tcl Test.h Test.jar
	rm -f Makefile jtclsh jaclsh tcljavaConfig.sh


#----------------------------------------------------------------
# Distributions
#----------------------------------------------------------------

# Most of the rules below will only work on the tcljava distribution,
# which consists of the combined Tcl Blend and Jacl sources.


# Target to create a proper Tcl distribution from information in the
# master source directory.  DISTDIR must be defined to indicate where
# to put the distribution.
#

DISTDIR			= /tmp/tcljava

JACL_ZIPNAME		= jacl$(TCLJAVA_NODOT_VERSION).zip
JACL_DISTNAME		= jacl$(TCLJAVA_VERSION)
JACL_DISTDIR		= $(DISTDIR)/$(JACL_DISTNAME)

TCLBLEND_ZIPNAME	= tclBlend$(TCLJAVA_NODOT_VERSION).zip
TCLBLEND_DISTNAME	= tclBlend$(TCLJAVA_VERSION)
TCLBLEND_DISTDIR	= $(DISTDIR)/$(TCLBLEND_DISTNAME)

# Permissions to set the files in the distribution to.
DIST_CHMOD_PERMS	= a+rX,u+w,go-w,g-s

# This rule will build all the distributions
dist: jaclDist tclblendDist


#this is just used for debugging the dist name generation
distnames:
	-@echo "TCLJAVA_VERSION = $(TCLJAVA_VERSION)"
	-@echo "TCLJAVA_NODOT_VERSION = $(TCLJAVA_NODOT_VERSION)"
	-@echo "JACL_ZIPNAME = $(JACL_ZIPNAME)"
	-@echo "JACL_DISTNAME = $(JACL_DISTNAME)"
	-@echo "TCLBLEND_ZIPNAME = $(TCLBLEND_ZIPNAME)"
	-@echo "TCLBLEND_DISTNAME = $(TCLBLEND_DISTNAME)"

#----------------------------------------------------------------
# tcljavaDist --
#
#	Builds the directory structure and copies files that are 
# 	common in both tclblend and jacl.
#----------------------------------------------------------------

tcljavaDist: Makefile
	@echo "#"
	@echo "# Making tcljavaDist"
	@echo "#"
	rm -rf $(DISTDIR)
	mkdir -p $(DISTDIR)
	$(MAKE) TCLJAVA=$(TCLJAVA) DISTDIR=$(DISTDIR) tcljavaDemoDist

	cp -p $(TOP_DIR)/license.terms \
		$(TOP_DIR)/license.ucb \
		$(TOP_DIR)/changes.txt \
		$(TOP_DIR)/ChangeLog \
		$(TOP_DIR)/diffs.txt \
		$(TOP_DIR)/known_issues.txt \
		$(DISTDIR)

	mkdir -p $(DISTDIR)/unix
	cp -p $(UNIX_DIR)/configure \
		$(UNIX_DIR)/configure.in \
		$(UNIX_DIR)/install-sh \
		$(UNIX_DIR)/tcljavaConfig.sh.in \
		$(UNIX_DIR)/Makefile.in \
		$(TOP_DIR)/license.terms \
		$(DISTDIR)/unix

	chmod 644 $(DISTDIR)/unix/Makefile.in $(DISTDIR)/unix/configure.in
	chmod 755 $(DISTDIR)/unix/configure 
	chmod 555 $(DISTDIR)/unix/install-sh

	@#this makefile will be modified later
	mkdir -p $(DISTDIR)/win
	cp -p $(TOP_DIR)/win/makefile.vc \
		$(DISTDIR)/win/makefile.vc
	cp -p 	$(TOP_DIR)/license.terms \
		$(DISTDIR)/win

	@# Don't just blindly recursively copy, we are bound to pick up kruft.

	mkdir -p $(DISTDIR)/src

	cp -p $(TOP_DIR)/src/*.tcl \
	       $(TOP_DIR)/src/*.java \
	       $(DISTDIR)/src

	mkdir -p $(DISTDIR)/src/empty/tcl/lang

	cp -p  $(TOP_DIR)/src/empty/tcl/lang/*.java \
		$(DISTDIR)/src/empty/tcl/lang

	cp -p $(TOP_DIR)/src/empty/empty.jar \
		$(TOP_DIR)/src/empty/README.txt \
		$(DISTDIR)/src/empty

	mkdir -p $(DISTDIR)/src/tcljava/tcl/lang
	cp -p $(TOP_DIR)/src/tcljava/tcl/lang/*.java \
		$(DISTDIR)/src/tcljava/tcl/lang

	mkdir -p $(DISTDIR)/src/tcljava/tcl/lang/library/java
	cp -p $(TOP_DIR)/src/tcljava/tcl/lang/library/java/javalock.tcl \
		$(DISTDIR)/src/tcljava/tcl/lang/library/java

	mkdir -p $(DISTDIR)/src/tcljava/tcl/lang/reflect
	cp -p $(TOP_DIR)/src/tcljava/tcl/lang/reflect/PkgInvoker.java \
		$(DISTDIR)/src/tcljava/tcl/lang/reflect

	mkdir -p $(DISTDIR)/src/tests/tcljava/tests
	cp -p $(TOP_DIR)/src/tests/tcljava/tests/*.java \
		$(DISTDIR)/src/tests/tcljava/tests

	mkdir -p $(DISTDIR)/src/tests/tcljava/tests/exec
	cp -p $(TOP_DIR)/src/tests/tcljava/tests/exec/*.java \
		$(DISTDIR)/src/tests/tcljava/tests/exec

	mkdir -p $(DISTDIR)/src/tests/tcljava/tests/invoke
	cp -p $(TOP_DIR)/src/tests/tcljava/tests/invoke/*.java \
		$(DISTDIR)/src/tests/tcljava/tests/invoke

	mkdir -p $(DISTDIR)/src/tests/tcljava/tests/javainfo
	cp -p $(TOP_DIR)/src/tests/tcljava/tests/javainfo/*.java \
		$(DISTDIR)/src/tests/tcljava/tests/javainfo

	mkdir -p $(DISTDIR)/src/tests/tcljava/tests/javabind
	cp -p $(TOP_DIR)/src/tests/tcljava/tests/javabind/*.java \
		$(DISTDIR)/src/tests/tcljava/tests/javabind

	mkdir -p $(DISTDIR)/src/tests/tcljava/tests/signature
	cp -p $(TOP_DIR)/src/tests/tcljava/tests/signature/*.java \
		$(DISTDIR)/src/tests/tcljava/tests/signature

	mkdir -p $(DISTDIR)/src/tests/tcljava/javaload
	cp -p $(TOP_DIR)/src/tests/tcljava/javaload/*.java \
		$(DISTDIR)/src/tests/tcljava/javaload

	mkdir -p $(DISTDIR)/src/tests/tcljava/pkg1
	cp -p $(TOP_DIR)/src/tests/tcljava/pkg1/*.java \
		$(DISTDIR)/src/tests/tcljava/pkg1

	mkdir -p $(DISTDIR)/src/tests/tcljava/pkg2
	cp -p $(TOP_DIR)/src/tests/tcljava/pkg2/*.java \
		$(DISTDIR)/src/tests/tcljava/pkg2

	mkdir -p $(DISTDIR)/src/tests/tcljava/tcl/lang
	cp -p $(TOP_DIR)/src/tests/tcljava/tcl/lang/*.java \
		$(DISTDIR)/src/tests/tcljava/tcl/lang

	mkdir -p $(DISTDIR)/tests/tcljava
	cp -p $(TOP_DIR)/tests/README \
		$(TOP_DIR)/tests/all \
		$(TOP_DIR)/tests/defs \
		$(DISTDIR)/tests

	cp -p $(TOP_DIR)/tests/tcljava/*.test \
		$(DISTDIR)/tests/tcljava

	mkdir -p $(DISTDIR)/docs \
		$(DISTDIR)/docs/Keywords \
		$(DISTDIR)/docs/TclJava \
		$(DISTDIR)/docs/TclJavaLib \

	cp -p $(TOP_DIR)/docs/*.html \
		$(DISTDIR)/docs
	cp -p $(TOP_DIR)/docs/Keywords/*.htm \
		$(DISTDIR)/docs/Keywords
	cp -p $(TOP_DIR)/docs/TclJava/*.html \
		$(DISTDIR)/docs/TclJava
	cp -p $(TOP_DIR)/docs/TclJavaLib/*.htm \
		$(DISTDIR)/docs/TclJavaLib


#----------------------------------------------------------------
# tcljavaDemoDist --
#
#	Builds the directory structure and copies demos that are 
# 	common in both tclblend and jacl.
#----------------------------------------------------------------

tcljavaDemoDist: Makefile
	@echo "#"
	@echo "# Making tcljavaDemoDist"
	@echo "#"
	mkdir -p $(DISTDIR)/demos/gluepkg \
		$(DISTDIR)/demos/watchpkg \
		$(DISTDIR)/demos/simplepkg \
		$(DISTDIR)/demos/gridDemo \
		$(DISTDIR)/demos/packDemo

	cp -p $(TOP_DIR)/demos/README \
		$(DISTDIR)/demos
	cp -p $(TOP_DIR)/demos/gluepkg/*.java \
		$(TOP_DIR)/demos/gluepkg/*.tcl \
		$(TOP_DIR)/demos/gluepkg/*.jar \
		$(TOP_DIR)/demos/gluepkg/README \
		$(TOP_DIR)/license.terms \
		$(DISTDIR)/demos/gluepkg
	cp -p $(TOP_DIR)/demos/simplepkg/*.java \
		$(TOP_DIR)/demos/simplepkg/*.tcl \
		$(TOP_DIR)/demos/simplepkg/README \
		$(TOP_DIR)/license.terms \
		$(DISTDIR)/demos/simplepkg
	cp -p $(TOP_DIR)/demos/watchpkg/*.java \
		$(TOP_DIR)/demos/watchpkg/*.tcl \
		$(TOP_DIR)/demos/watchpkg/README \
		$(TOP_DIR)/license.terms \
		$(DISTDIR)/demos/watchpkg
	cp -p $(TOP_DIR)/demos/gridDemo/*.tcl \
		$(TOP_DIR)/demos/gridDemo/README \
		$(DISTDIR)/demos/gridDemo
	cp -p $(TOP_DIR)/demos/packDemo/*.tcl \
		$(TOP_DIR)/demos/packDemo/*.java \
		$(TOP_DIR)/demos/packDemo/README \
		$(DISTDIR)/demos/packDemo

#----------------------------------------------------------------
# jaclDist --
#
#	Builds the directory structure and copies files that are 
# 	unique to Jacl.  Before this is done, the targets 
#	tcljavaDist and tcljavaDemoDist MUST be built.
#----------------------------------------------------------------
jaclDist: $(UNIX_DIR)/configure Makefile
	@echo "#"
	@echo "# Making jaclDist"
	@echo "#"
	$(MAKE) TCLJAVA=$(TCLJAVA) tcljavaDist DISTDIR=$(JACL_DISTDIR) TCLJAVA=jacl
	$(MAKE) TCLJAVA=$(TCLJAVA) DISTDIR=$(JACL_DISTDIR) jaclDemoDist 

	cp -p $(TOP_DIR)/README.jacl \
		$(JACL_DISTDIR)/README
	cp -p $(TOP_DIR)/unix/README.jacl \
		$(JACL_DISTDIR)/unix/README
	cp -p $(TOP_DIR)/win/README.jacl \
		$(JACL_DISTDIR)/win/README

	mkdir -p $(JACL_DISTDIR)/src/tests/jacl/tcl/lang
	cp -p $(TOP_DIR)/src/tests/jacl/tcl/lang/*.java \
		$(JACL_DISTDIR)/src/tests/jacl/tcl/lang

	mkdir -p $(JACL_DISTDIR)/src/jacl/sunlabs/brazil/util/regexp
	cp -p $(TOP_DIR)/src/jacl/sunlabs/brazil/util/regexp/*.java \
		$(JACL_DISTDIR)/src/jacl/sunlabs/brazil/util/regexp

	mkdir -p $(JACL_DISTDIR)/src/jacl/tcl/lang
	cp -p $(TOP_DIR)/src/jacl/tcl/lang/*.java \
		$(JACL_DISTDIR)/src/jacl/tcl/lang

	mkdir -p $(JACL_DISTDIR)/src/jacl/tcl/lang/library

	cp -p $(JACL_SRC_DIR)/tcl/lang/library/*.tcl \
		$(JACL_SRC_DIR)/tcl/lang/library/tclIndex \
		$(TOP_DIR)/license.terms \
		$(JACL_DISTDIR)/src/jacl/tcl/lang/library

	mkdir -p $(JACL_DISTDIR)/tests/jacl
	cp -p $(TOP_DIR)/tests/jacl/*.test \
		$(JACL_DISTDIR)/tests/jacl

	mkdir -p $(JACL_DISTDIR)/tests/tcl
	cp -p $(TOP_DIR)/tests/tcl/*.test \
		$(JACL_DISTDIR)/tests/tcl

	mkdir -p $(JACL_DISTDIR)/unix
	cp -p $(TOP_DIR)/unix/jaclsh.in \
		$(JACL_DISTDIR)/unix

	mkdir -p $(JACL_DISTDIR)/win
	cp -p $(TOP_DIR)/win/jaclsh.bat \
		$(JACL_DISTDIR)/win

	@# Substitute in TCLJAVA=jacl
	cat $(TOP_DIR)/win/makefile.vc | \
	sed -e 's/TCLJAVA[	 ]*= [a-z]*$$/TCLJAVA		= jacl/g' \
		-e 's/tclBlend@TCLJAVA_VERSION@/jacl@TCLJAVA_VERSION@/g' >\
		$(JACL_DISTDIR)/win/makefile.vc

	rm -f $(DISTDIR)/$(JACL_DISTNAME).tar.Z \
		$(DISTDIR)/$(JACL_DISTNAME).tar.gz \
		$(DISTDIR)/$(JACL_ZIPNAME) 
	cd $(DISTDIR);\
		chmod -R $(DIST_CHMOD_PERMS) $(JACL_DISTNAME); \
		tar -cf $(JACL_DISTNAME).tar $(JACL_DISTNAME); \
		compress -c $(JACL_DISTNAME).tar > $(JACL_DISTNAME).tar.Z; \
		zip -qr8 $(JACL_ZIPNAME) $(JACL_DISTNAME); \
		gzip --best $(JACL_DISTNAME).tar


#----------------------------------------------------------------
# jaclDemoDist --
#
#	Builds the directory structure and copies demos that are 
# 	only provided with jacl.
#----------------------------------------------------------------

jaclDemoDist: Makefile
	@echo "#"
	@echo "# Making jaclDemoDist"
	@echo "#"
	mkdir -p $(DISTDIR)/demos/pyramidpkg
	cp -p $(TOP_DIR)/demos/pyramidpkg/*.java \
		$(TOP_DIR)/demos/pyramidpkg/*.html \
		$(TOP_DIR)/demos/pyramidpkg/changeDefs.tcl \
		$(TOP_DIR)/demos/pyramidpkg/README \
		$(TOP_DIR)/license.terms \
		$(DISTDIR)/demos/pyramidpkg

# Sanity check by building, installing, running tests
jaclDistBuild:
	mkdir -p $(DISTDIR)/jacltest
	cd $(JACL_DISTDIR)/unix; \
		$(UNIX_DIR)/configure --prefix=$(DISTDIR)/jacltest ; \
		$(MAKE) install; \
		$(MAKE) test_jacl.build; \
		$(MAKE) test


#----------------------------------------------------------------
# tclblendDist --
#
#	Builds the directory structure and copies files that are 
# 	unique to tclblend.  Before this is done, the targets 
#	tcljavaDist and tcljavaDemoDist MUST be built.
#----------------------------------------------------------------

tclblendDist: $(UNIX_DIR)/configure Makefile
	@echo "#"
	@echo "# Making tclblendDist"
	@echo "#"
	$(MAKE) DISTDIR=$(TCLBLEND_DISTDIR) TCLJAVA=tclblend tcljavaDist

	cp -p $(TOP_DIR)/README.tclblend \
		$(TCLBLEND_DISTDIR)/README
	cp -p $(TOP_DIR)/unix/README.tclblend \
		$(TCLBLEND_DISTDIR)/unix/README
	cp -p $(TOP_DIR)/win/README.tclblend \
		$(TCLBLEND_DISTDIR)/win/README

	mkdir -p $(TCLBLEND_DISTDIR)/unix
	cp -p $(TOP_DIR)/unix/jtclsh.in \
		$(TCLBLEND_DISTDIR)/unix

	mkdir -p $(TCLBLEND_DISTDIR)/src
	cp -p $(TOP_DIR)/src/pkgIndex.tcl \
		$(TCLBLEND_DISTDIR)/src

	mkdir -p $(TCLBLEND_DISTDIR)/src/xputils
	cp -p $(TOP_DIR)/src/xputils/*.tcl \
		$(TOP_DIR)/src/xputils/*.test \
		$(TCLBLEND_DISTDIR)/src/xputils

	mkdir -p $(TCLBLEND_DISTDIR)/src/native
	cp -p $(NATIVE_SRC_DIR)/*.c \
		$(NATIVE_SRC_DIR)/*.h \
		$(TCLBLEND_DISTDIR)/src/native

	cp -p $(TOP_DIR)/configure \
		$(TOP_DIR)/configure.in \
		$(TOP_DIR)/Makefile.in \
		$(TOP_DIR)/mkIndex.tcl.in \
		$(TOP_DIR)/aclocal.m4 \
		$(TOP_DIR)/tcl.m4 \
		$(TOP_DIR)/install-sh \
		$(TOP_DIR)/mkinstalldirs \
		$(TCLBLEND_DISTDIR)

	chmod 644 $(TCLBLEND_DISTDIR)/Makefile.in \
		$(TCLBLEND_DISTDIR)/configure.in
	chmod 755 $(TCLBLEND_DISTDIR)/configure \
		$(TCLBLEND_DISTDIR)/install-sh
	chmod 755 $(TCLBLEND_DISTDIR)/mkinstalldirs
		cp -p $(UNIX_DIR)/custom.c \
		$(UNIX_DIR)/unixNotifier.c \
		$(TCLBLEND_DISTDIR)/unix

	cp -p $(WIN_DIR)/winNotifier.c \
		$(WIN_DIR)/tclRegexp.h \
		$(TCLBLEND_DISTDIR)/win

	@# Substitute in TCLJAVA=tclblend
	cat $(TOP_DIR)/win/makefile.vc | \
		sed -e 's/TCLJAVA[	 ]*= [a-z]*$$/TCLJAVA		= tclblend/g' >\
			$(TCLBLEND_DISTDIR)/win/makefile.vc

	mkdir -p $(TCLBLEND_DISTDIR)/src/tests/tclblend/tests
	mkdir -p $(TCLBLEND_DISTDIR)/src/tests/tclblend/tcl/lang

	cp -p $(TOP_DIR)/src/tests/tclblend/tests/*.java \
		$(TCLBLEND_DISTDIR)/src/tests/tclblend/tests

	cp -p $(TOP_DIR)/src/tests/tclblend/tcl/lang/*.java \
		$(TCLBLEND_DISTDIR)/src/tests/tclblend/tcl/lang

	mkdir -p $(TCLBLEND_DISTDIR)/src/tclblend/tcl/lang
	cp -p $(TCLBLEND_SRC_DIR)/tcl/lang/*.java \
		$(TCLBLEND_DISTDIR)/src/tclblend/tcl/lang

	mkdir -p $(TCLBLEND_DISTDIR)/tests/tclblend
	cp -p  $(TOP_DIR)/tests/tclblend/*.test \
		$(TCLBLEND_DISTDIR)/tests/tclblend

	rm -f   $(DISTDIR)/$(TCLBLEND_DISTNAME).tar.Z \
		$(DISTDIR)/$(TCLBLEND_DISTNAME).tar.gz \
		$(DISTDIR)/$(TCLBLEND_ZIPNAME)

	cd $(DISTDIR);\
		chmod -R $(DIST_CHMOD_PERMS) $(TCLBLEND_DISTNAME); \
		tar -cf $(TCLBLEND_DISTNAME).tar $(TCLBLEND_DISTNAME); \
		compress -c $(TCLBLEND_DISTNAME).tar > $(TCLBLEND_DISTNAME).tar.Z; \
		zip -rq8 $(TCLBLEND_ZIPNAME) $(TCLBLEND_DISTNAME); \
		gzip --best $(TCLBLEND_DISTNAME).tar


# Sanity check by building, installing, running tests
tclblendDistBuild:
	mkdir -p $(DISTDIR)/tbtest
	cd $(TCLBLEND_DISTDIR)/unix; \
		$(UNIX_DIR)/configure --prefix=$(DISTDIR)/tbtest \
			--with-tcl=$(TCL_BIN_DIR) ; \
		$(MAKE) install; \
		$(MAKE) test_tclblend.build; \
		$(MAKE) test




############################################################################
#
# Purify is a commercial software package that finds leaks and memory
# access errors in C programs.  The rules below build a purified
# executable.
# Before you run custom.pure, you will have to set the following variables:
# setenv LD_LIBRARY_PATH .:${LD_LIBRARY_PATH}
#
############################################################################

PURIFYOPTIONS = -automount-prefix=/tmp_mnt:/vol -best-effort -cache-dir=/tmp/pv -always-use-cache-dir=yes -ignore_signals=SIGPOLL -threads=yes -use_internal_locks=yes
PUREDIR =	/usr/eesww/pure/purify
PURETHREADS =	$(PUREDIR)/solaris2_threads.so
PURIFY =	$(PUREDIR)/purify

custom.pure.build:
	@$(MAKE) TCLJAVA=tclblend custom.pure 

custom.pure: .purify tclblend.check custom.check
	$(PURIFY) $(PURIFYOPTIONS) \
	$(CC) -o $@ -g custom.o $(PURETHREADS) $(TCLBLEND_LIB_FILE) $(LIBS)

# The .purify file is read by the purify program
# The first two lines must be present for purify to work properly.
# The other lines supress messages.
.purify: Makefile
	echo "ignore set_single_stepping libjava.so" > $@
	echo "registercode nop_0+0x0 Illegal254_0+0x3c libjava.so" >> $@
	echo "suppress umr GetDefaultClassPath" >> $@
	echo "suppress umr ResolveClassConstant" >> $@
	echo "suppress umr ExecuteJava" >> $@
	echo "suppress umr quickInvocation" >> $@
	echo "suppress umr execute_java_constructor" >> $@
	echo "suppress umr do_execute_java_method_vararg" >> $@
	echo "suppress umr sysThreadAlloc" >> $@
	echo "suppress umr sysDynamicLink" >> $@
	echo "suppress umr quickStaticAccess" >> $@
	echo "suppress umr Java_java_lang_System_arraycopy_stub" >> $@
	echo "suppress umr Java_java_lang_Class_getPrimitiveClass_stub" >> $@
	echo "suppress umr fillInStackTrace" >> $@
	echo "suppress umr ProcedureFindThrowTag" >> $@
	echo "suppress umr FindClass" >> $@
	echo "suppress umr Java_java_lang_Throwable_fillInStackTrace_stub" >> $@
	echo "suppress umr sysInvokeNative" >> $@
	echo "suppress umr invokeJNINativeMethod; ExecuteJava" >> $@
	echo "suppress umr jni_Invoke; jni_CallVoidMethodV" >> $@
	echo "suppress umr jni_Invoke; jni_CallObjectMethodV" >> $@
	echo "suppress umr record_lwp_regs; wait_stopped_lwps" >> $@
	echo "suppress umr scanThread; sysThreadEnumerateOver; gc0_locked" >> $@
	echo "suppress sbr scanThread; sysThreadEnumerateOver; gc0_locked" >> $@
	echo "suppress umr _start; _thread_start" >> $@
	echo "suppress umr mktime; zip_stat" >> $@
	echo "suppress umr qst; qsort; initReader" >> $@
	echo "suppress umr TclCleanupByteCode; FreeByteCodeInternalRep" >> $@

custom.pure.test.exec: .purify
	( echo set auto_path [concat [pwd] [set auto_path]]\;
	 cd $(TOP_DIR)/tests\; \
	 source all\; exit; ) | \
	LD_LIBRARY_PATH=$(BUILD_DIR):$(TCL_BIN_DIR):$(JAVA_ARCH_GREEN_RUNTIME_LIBS):$(LD_LIBRARY_PATH) \
	SHLIB_PATH=$(BUILD_DIR):$(TCL_BIN_DIR):$(JAVA_ARCH_GREEN_RUNTIME_LIBS):$(SHLIB_PATH) \
	CLASSPATH=$(TEST_CLASSPATH) \
	BUILD_DIR=$(BUILD_DIR) \
	$(BUILD_DIR)/custom.pure

QUANTIFYDIR =	/usr/eesww/pure/quantify
QUANTIFYTHREADS =	$(QUANTIFYDIR)/solaris2_threads.so
QUANTIFY =	$(QUANTIFYDIR)/quantify

custom.quantify.build:
	@$(MAKE) TCLJAVA=tclblend custom.quantify

custom.quantify: .purify tclblend.check custom.check
	$(QUANTIFY) $(PURIFYOPTIONS) \
	$(CC) -o $@ -g custom.o $(QUANTIFYTHREADS) $(TCLBLEND_LIB_FILE) $(LIBS)



#----------------------------------------------------------------
#
# Java Scope test case code coverage rules
#
#----------------------------------------------------------------

# The variables below are for the SunTest JavaScope code coverage tool
# See http://www.suntest.com/JavaScope
#
# How to get test case code coverage stats
# 0) Obtain Java Scope
# 1) Adjust the JS* variables to your settings
# 2) Run make jsall
#	Note that the step that runs the tests takes about 60 minutes.
# 3) Run javascope, jsreport or jsreport -dbsummary
# 4) Run make jsrestore
# 5) Run make clean; make; make install

# The 'jsinstr' command, which instruments Java code.
JSINSTR = 	jsinstr
JSINTRFLAGS = 	-IFLUSHCLASS=true
# The 'jsrestore' command which uninstruments Java code.
JSRESTORE =	jsrestore
# The pathname to the JavaScope.zip file
JSCLASSPATH = 	/users/ptdesign/vendors/sun/JavaScope/JavaScope.zip

jsinstr:
	$(JSINSTR) $(JSINTRFLAGS)

# If the jsoriginal directory does not exist, then instrument the Java files.
# Note that $(wildcard) is a GNU make extension 
$(TCLBLEND_SRC_DIR)/tcl/lang/jsoriginal:
	@echo "Creating $@"
	cd $(TCLBLEND_SRC_DIR)/tcl/lang; \
	if test ! -d jsoriginal ; then \
		$(JSINSTR) $(JSINTRFLAGS) *.java; \
	fi

$(TCLJAVA_SRC_DIR)/tcl/lang/jsoriginal:
	@echo "Creating $@"
	cd $(TCLJAVA_SRC_DIR)/tcl/lang; \
	if test ! -d jsoriginal ; then \
		$(JSINSTR) $(JSINTRFLAGS) *.java; \
	fi

# Compile the instrumented Java classes and include JavaScope.zip
jstclblend.depend:
	$(MAKE) tclblend.build AUX_CLASSPATH=:$(JSCLASSPATH) TCLJAVA=tclblend


# Run the test_jsimple rule with the proper classpath  
jstclblendTest:
	@$(MAKE) TCLJAVA=tclblend AUX_CLASSPATH=":$(JSCLASSPATH)" test_tclblend
	@echo "To view code coverage results, run javascope or jsreport"
	@echo "To get a summary, run jsreport -dbsummary" 


# If necessary, instrument the classes, then rebuild, then run the tests
jsall: $(TCLBLEND_SRC_DIR)/tcl/lang/jsoriginal \
		$(TCLJAVA_SRC_DIR)/tcl/lang/jsoriginal
	$(MAKE) clean
	$(MAKE) jstclblend.depend
	$(MAKE) install
	$(MAKE) jstclblendTest


# Back out the instrumentation.
jsrestore:
	cd $(TCLBLEND_SRC_DIR)/tcl/lang; $(JSRESTORE) *.java
	-rm -f $(TCLBLEND_SRC_DIR)/tcl/lang/jsoriginal/README
	-rmdir $(TCLBLEND_SRC_DIR)/tcl/lang/jsoriginal
	cd $(TCLJAVA_SRC_DIR)/tcl/lang; $(JSRESTORE) *.java
	-rm -f $(TCLJAVA_SRC_DIR)/tcl/lang/jsoriginal/README
	-rmdir $(TCLJAVA_SRC_DIR)/tcl/lang/jsoriginal




# DO NOT DELETE THIS LINE -- make depend depends on it.
