##  Makefile for Toba
#
#   See doc/install.html for complete installation instructions.
#   A synopsis is below.
#
#
#   Configuration:
#
#   1.  Obtain and unpack version 1.0.2 of the Java Development Kit.
#
#   2.  Set your path to include the javac and java programs
#       and your CLASSPATH to include the classes.zip file or 
#       classes directory from the JDK.
#
#   3.  Type "make targetname" to build Toba.  This may take as long as 
#       an hour.
#
#   4.  Type "make test" to compile and execute a simple test using Toba.
#
#
#   Installation (not needed to just use the bin directory where built):
#
#   1.  Type "make install INSTALL=directoryname"
#
#   2.  Check permissions and alter as desired
#


# directory for installing binaries etc. ("make install")
INSTALL = /usr/local/toba

# standard, supported targets:
TARGETS = solaris solaris_gcc linux irix 

# Configuration options.  Override in platform-specific and local configuration
# files.

include configs/basic.mk
include configs/current.mk

default: all_awt

# Under GNU make, this will remind people to set up the configuration link.
configs/current.mk:
	@echo "You have to configure for your system first.  Add a symlink"
	@echo "./configs/current.mk to one of these:"
	@cd ./configs ; ls *.mk | grep -v basic.mk | fmt
	@false

#  full build target (minus awt support, for now)
all:	$(EXTRA_TARGETS) Binaries

# full build with awt support.  Need to rebuild jtoba afterwards to
# add link to libBISS.
all_awt: all AWT RebuildJtoba

check: FORCE
	sh check.sh

# Scripts that drive toba compilations
Scripts: check
	cd bin;		$(MAKE)

# Classfiles in the toba.* hierarchy
TobaClasses:
	cd toba;	$(MAKE) classes

# Library containing translated Sun java.* and sun.* classes
SunPackages: Scripts TobaClasses
	cd packages;	$(MAKE) API SUN

# Library containing translated toba.* classes; only needed for jit
TobaPackage: Scripts SunPackages
	cd toba;	$(MAKE) package

# Garbage collector
GarbageCol:
	cd gc;		$(MAKE) -f $(GCMF) CC="$(CC)" AS="$(AS)" \
				CFLAGS="$(GCCFLAGS) $(CBUILD)" gc.a
# Object files for toba runtime support
RuntimeObj: SunPackages TobaPackage
	cd runtime;	$(MAKE) $(JIT_TARGET)

# Library containing toba runtime support
RuntimePackage: RuntimeObj GarbageCol
	cd packages;	$(MAKE) RUNTIME

# Native versions of translator, compiler, and JIT.
Binaries: RuntimePackage TobaPackage SunPackages
	cd bin;		$(MAKE) binaries $(JIT_TARGET)

# Library with BISS window toolkit support
AWT: Binaries
	cd biss;	$(MAKE)

# Forced rebuild of jit to add new library references
RebuildJtoba: FORCE
	-cd bin; rm -f jtoba ; $(MAKE) $(JIT_TARGET)

# Scout-compatible threads package for Linux
scout_threads: FORCE
	cd scout_threads;	$(MAKE)

#  test the completed build
test:	FORCE
	cd test; $(MAKE)
FORCE:

#  copy files needed to run and use Toba
#  (first line fails if Toba has not been successfully built)
install:
	ls bin/xjavac >/dev/null
	test -d $(INSTALL)                  || mkdir $(INSTALL)
	test -d $(INSTALL)/bin              || mkdir $(INSTALL)/bin
	test -d $(INSTALL)/toba             || mkdir $(INSTALL)/toba
	test -d $(INSTALL)/toba/classfile   || mkdir $(INSTALL)/toba/classfile
	test -d $(INSTALL)/toba/translator  || mkdir $(INSTALL)/toba/translator
	test -d $(INSTALL)/toba/runtime     || mkdir $(INSTALL)/toba/runtime
	test -d $(INSTALL)/toba/jit         || mkdir $(INSTALL)/toba/jit
	test -d $(INSTALL)/man              || mkdir $(INSTALL)/man
	test -d $(INSTALL)/doc              || mkdir $(INSTALL)/doc
	test -d $(INSTALL)/packages         || mkdir $(INSTALL)/packages
	cp -r ./packages/API ./packages/SUN \
	    ./packages/RUNTIME		    $(INSTALL)/packages
	if [ -d ./packages/BISS ] ; then \
	    cp -r ./packages/BISS           $(INSTALL)/packages ; fi 
	if [ -d ./packages/TOBA ] ; then \
	    cp -r ./packages/TOBA           $(INSTALL)/packages ; fi 
	cp ./bin/toba                       $(INSTALL)/bin
	cp ./toba/*.class                   $(INSTALL)/toba
	cp ./toba/classfile/*.class         $(INSTALL)/toba/classfile
	cp ./toba/translator/*.class        $(INSTALL)/toba/translator
	-cp ./toba/runtime/*.class          $(INSTALL)/toba/runtime
	-cp ./toba/jit/*.class              $(INSTALL)/toba/jit
	cp ./doc/*.html ./doc/*.gif         $(INSTALL)/doc
	cp ./man/*.[0-9]                    $(INSTALL)/man
	cd bin; $(MAKE) DIR=$(INSTALL) install


#  remove all files built

clean:
	cd runtime;	$(MAKE) clean
	cd gc;		$(MAKE) clean
	cd toba;	$(MAKE) clean
	cd packages;	$(MAKE) clean
	cd biss;	$(MAKE) clean
	cd bin;		$(MAKE) clean
	cd test;	$(MAKE) clean
	cd scout_threads; $(MAKE) clean

distclean: clean
