##  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
#
#
#  Copyright 1996, 1997 Arizona Board of Regents; see COPYRIGHT file for 
#  details.


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

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

# default make target gives a message
what:
	@echo ""
	@echo "   Make what?  Specify one of these targets:"
	@echo "      $(TARGETS)"
	@echo ""

WINPROC = lang_Win32Process.c
UNIXPROC = lang_UNIXProcess.c lang_ProcessReaper.c

# default configuration options, overridden below
#	THREADS	threads package
#	CC	C compiler for build and Toba use
#	CBUILD	C flags for build
#	CTOBA	C flags used by Toba when calling $CC
#	TBUILD	Toba flags for build
#	LIBS	libraries for linking Toba programs
#	SLOPT	ld option for creating a shared library
#	RPOPT	$CC option prefix for embedding a shared library path
#	LTARG	Library make targets
#	GCMF	Makefile to use in gc directory
#	PROC	Process source files
#	SUFFIX	Suffix appended to executables by the linker (ie. ".exe")
THREADS = null
CC = cc
CBUILD = -O
CTOBA = 
TBUILD = -O
LIBS = -lm
SLOPT = -shared
RPOPT = -rpath
LTARG = shared
GCMF = Makefile
PROC = $(UNIXPROC)
SUFFIX =


# target for Solaris using Solaris Threads
solaris:
	$(MAKE) all_awt \
	  THREADS=sol \
	  CBUILD="-D_REENTRANT -DSOLARIS_THREADS -DBINARY_LOADER -xlibmieee -Xa -O -K pic" \
	  CTOBA="-D_REENTRANT -DSOLARIS_THREADS -xlibmieee -Xa" \
	  TBUILD="-O -A'-K pic'" \
	  SLOPT="-G"  RPOPT="-R "  LIBS="-lm -lnsl -lsocket -ldl -lthread" \
	  XLIBS="-L/usr/openwin/lib -lX11" XINC="-I /usr/openwin/include"

# target for Solaris using GCC and Solaris Threads
solaris_gcc:
	$(MAKE) all_awt \
	  THREADS=sol \
	  CC=gcc \
	  CBUILD="-D_REENTRANT -DSOLARIS_THREADS -DBINARY_LOADER -O3 -fpic" \
	  CTOBA="-D_REENTRANT -DSOLARIS_THREADS -ansi" \
	  TBUILD="-O -A-fpic" \
	  SLOPT="-G"  RPOPT="-R "  LIBS="-lm -lnsl -lsocket -ldl -lthread" \
	  XLIBS="-L/usr/openwin/lib -lX11" XINC="-I /usr/openwin/include"

# target for Solaris with no threads 
solaris_nothreads:
	$(MAKE) all \
	  THREADS=null \
	  CBUILD="-DNOTHREADS -DBINARY_LOADER -xlibmieee -Xa -K pic" \
	  CTOBA="-DNOTHREADS -xlibmieee -Xa" \
	  TBUILD="-O -A'-K pic'" \
	  SLOPT="-G"  RPOPT="-R "  LIBS="-lm -lnsl -lsocket -ldl" \
	  XLIBS="-L/usr/openwin/lib -lX11" XINC="-I /usr/openwin/include"

# target for Linux with no threads
linux linux_nothreads:
	$(MAKE) all \
	  THREADS=null \
	  CBUILD="-DNOTHREADS -DBINARY_LOADER -O3 -fpic" \
	  CTOBA="-DNOTHREADS -ansi" \
	  TBUILD="-O -A-fpic" \
	  SLOPT="-shared"  RPOPT="-Wl,-rpath -Wl,"  LIBS="-lm -ldl"

# target for irix with no threads
irix irix_nothreads:
	$(MAKE) all \
	  THREADS=null \
	  CBUILD="-DNOTHREADS -DBINARY_LOADER -KPIC" \
	  CTOBA="-DNOTHREADS -ansi" \
	  TBUILD="-g -A-KPIC" \
	  SLOPT="-shared"  RPOPT="-rpath "  LIBS="-lm -ldl"

# target for win32 with no threads
win32 win32_nothreads:
	$(MAKE) all \
	  THREADS=null \
	  CC=gcc \
	  CBUILD="-DNOTHREADS -DNT_OPEN_HACK" \
	  CTOBA="-DNOTHREADS" \
	  TBUILD="" \
	  LTARG="static" SLOPT="" RPOPT="" LIBS="-lm -lcygwin" \
	  PROC="$(WINPROC)" \
	  SUFFIX=".exe"

# recursive flags
RFLAGS = CC=$(CC) CBUILD="$(CBUILD)" TBUILD="$(TBUILD)"
GCFLAGS = -DJAVA_FINALIZATION -DALL_INTERIOR_POINTERS -DSILENT

#  full build target (minus awt support, for now)
all:	
	sh check.sh
	cd bin;		$(MAKE) CC="$(CC)" CTOBA="$(CTOBA)" \
	  LTARG=$(LTARG) RPOPT="$(RPOPT)" SLOPT="$(SLOPT)" SUFFIX="$(SUFFIX)"
	cd toba;	$(MAKE) $(RFLAGS) classes
	cd packages;	$(MAKE) $(RFLAGS) API SUN
	cd toba;	$(MAKE) $(RFLAGS) package
	cd runtime;	$(MAKE) $(RFLAGS) THREADS=$(THREADS) PROC="$(PROC)"
	cd gc;		$(MAKE) -f $(GCMF) \
				$(RFLAGS) CFLAGS="$(GCFLAGS) $(CBUILD)"
	cd packages;	$(MAKE) $(RFLAGS) RUNTIME LIBS="$(LIBS)"
	cd bin;		$(MAKE) $(RFLAGS) SUFFIX="$(SUFFIX)" \
				xtoba$(SUFFIX) xjavac$(SUFFIX)

# full build with awt support
all_awt: all
	cd biss;	$(MAKE) XLIBS="$(XLIBS)"


#  test the completed build
test:	FORCE
	cd test; $(MAKE) $(RFLAGS)
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)/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 \
	    ./packages/TOBA                 $(INSTALL)/packages
	if [ -d ./packages/BISS ] ; then \
	    cp -r ./packages/BISS           $(INSTALL)/packages ; fi 
	cp ./bin/toba                       $(INSTALL)/bin
	cp ./toba/*.class                   $(INSTALL)/toba
	cp ./doc/*.html ./doc/*.gif         $(INSTALL)/doc
	cp ./man/*.[0-9]                    $(INSTALL)/man
	cd bin; $(MAKE) install DIR=$(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
