    # THIS IS AN MAKE INCLUDE FILE FOR USING JAVA
    # --Matt and Joel

ifndef BASEDIR
  BASEDIR = ${JESTCLASSPATH}
endif

    # What are the pros and cons of using the recommended system of
    # parallel directory structures for .class files and .java files?

    # Should we define JAVA as an environment variable as recommended by
    # "Exploring Java" p.69 ?
    # I think I prefer it this way: environment variables make things 
    # terribly unportable. An old remnant of UNIX.

    # WARNING: beware of file links, and mount points since, e.g., currently
    # the package name is determined by the pwd.

    # The JAVA properties, e.g. JAVAOSNAME and JAVAOSNAME, might be calculable
    # from actually invoking JAVA.  Would this even be desirable?



    # location of some important packages (sepio, jest, ...)
    # installation dependent
ROOTDIR       = /wrkka1/sep99
JESTCLASSPATH = ${ROOTDIR}/jest
JOINCLASSPATH = ${ROOTDIR}/join
MATTCLASSPATH = ${ROOTDIR}/sdi

JESTSOURCPATH = ${JESTCLASSPATH}
JOINSOURCPATH = ${JOINCLASSPATH}
MATTSOURCPATH = ${MATTCLASSPATH}

    # location of JGL (Java General Library)
JGLCLASSPATH  = $(JESTCLASSPATH)/jgl/jgl_1_1


#
# Platform dependency since different systems install Java at different locs #
#
ifeq "${ARCH}" "SGI"
  JAVA = /usr/java
  CPATH = /usr/java/classes:/usr/java/lib/rt.jar:/usr/java/lib/i18n.jar:/usr/java/lib/classes.zip
  JAVAOSNAME = Irix
  JAVAOSARCH = mips
endif 
ifeq "${ARCH}" "LINUX"
  JAVA = /usr/local/java
  JAVAOSARCH = i586
  JAVAOSNAME = Linux
endif
ifeq "${JDK10}" "yes" 
  JAVA = /usr/lib/java
  JAVAOSARCH = i386
endif 

   # location of the api class files
ifeq "${ARCH}" "SGI"
  APICLASSPATH = $(JAVA)/classes
  APISOURCPATH = $(JAVA)/src
endif 
ifeq "${ARCH}" "LINUX"
  APICLASSPATH = $(JAVA)/lib/classes.zip
  APISOURCPATH = $(JAVA)/src.zip
endif


# PACKAGE is the package name as calculated from pwd and various BASEDIR 
  STPWD0 = $(shell pwd) 
  STPWD1 = $(subst /tmp_mnt,,$(STPWD0)) 
  STPWD2 = $(subst /home/kana/wrkka1,/wrkka1,$(STPWD1)) 
  STPWD3 = $(subst /home/kana,/homes,$(STPWD2)) 

  PKG0   = $(STPWD3) 
  PKG1   = $(subst $(MATTCLASSPATH), ,$(PKG0)) 
  PKG2   = $(subst $(JESTCLASSPATH), ,$(PKG1))
  PKG3   = $(subst $(JOINCLASSPATH), ,$(PKG2)) 

  PACKAGE = $(patsubst .%,%,$(subst /,.,$(PKG3)))

    # official class path directories
OCLASSPATH = $(MATTCLASSPATH):$(JESTCLASSPATH):$(APICLASSPATH):$(JOINCLASSPATH)
OSOURCPATH = $(MATTSOURCPATH):$(JESTSOURCPATH):$(APISOURCPATH):$(JOINCLASSPATH)
    # total class path directories (the user may define UCLASSPATH)
CLASSPATH  = -classpath  .:$(UCLASSPATH):$(OCLASSPATH):${CPATH}
SOURCPATH  = -sourcepath .:$(USOURCPATH):$(OSOURCPATH)

    # flags for the java  interpreter
ifeq "${ARCH}" "SGI"
  JITFLAGS = -jit -tran
endif 
#
# For large problems you may want to set UJAVAXFLAGS = -mx 64m
# For verbose mode   you may want to set UJAVAXFLAGS = -verbose -verbosegc
JAVAXFLAGS = $(UJAVAXFLAGS) ${VERBOSE} $(JITFLAGS) -mx256m -cs $(CLASSPATH) 
    # flags for the javac compiler
    # for notes about -depend vs. makefile dependency checking see:
    # http://www.princeton.edu/~lieske/java/notes/notes.html
JAVACFLAGS = -depend $(CLASSPATH)

    # JAVAX -- use this to invoke java programs
JAVAX = $(JAVA)/bin/java $(JAVAXFLAGS)

JX    = $(JAVAX) $(PACKAGE)

%.jx    : %.java
	${JAVAX} $*

    # JAVAH -- for linking with C
%.javah : FORCE
	$(JAVA)/bin/javah -stubs $(CLASSPATH) $*
	$(JAVA)/bin/javah        $(CLASSPATH) $*

    # JAVAC -- compiler
%.jc    : %.java
	$(JAVA)/bin/javac    $(JAVACFLAGS) $*.java

%.class : %.java 
	${MAKE} $*.jc 

    # JDB - for debugging
%.debug : %.dbclass
	$(JAVA)/bin/jdb      $(JAVACFLAGS) $*

%.dbclass : FORCE
	$(JAVA)/bin/javac -g $(JAVACFLAGS) $*.java

#####  JAVADOC - for generating html documentation  #####

JAVADOCDIR   = $(JESTCLASSPATH)/jdocs/api
JAVADOCFLAGS = $(CLASSPATH) $(SOURCPATH) -d $(JAVADOCDIR)

.PHONY: javadoc javadocLocal javadocGlobal 
.PHONY: clean.javadoc

# document all classes in the current directory's package
# this does not update the package, index, or tree directory
# I use this command only temporary before routinely remaking 
# the entire webdoc set. 
# this rule is probably sufficient if a class is only modified 

javadocLocal javadoc : 
	cp $(JAVADOCDIR)/packages.html $(JAVADOCDIR)/packages.html.bkup 
	javadoc -noindex -notree $(JAVADOCFLAGS) $(PACKAGE) 
	cp $(JAVADOCDIR)/packages.html.bkup $(JAVADOCDIR)/packages.html

javadocTour: 
	@echo "I create the javadoc html files ..." 
	@echo "See javadoc html page for more info ..."
	@echo "You better run this on the SGI ... for the time being"
	${TOUCH} $(JAVADOCDIR)/junk.html 
	${RM} -r $(JAVADOCDIR)/*.html 
	javadocTour $(CLASSPATH) $(SOURCPATH) -d $(JAVADOCDIR) 

##### JOINING AND SPLITTING FILES IN A PACKAGE ######
PERLDIR = $(BASEDIR)/adm/shells
.PHONY : split join

split:
	$(PERLDIR)/splitpackage $(PACKAGE) < $(PACKAGE)

join :
	@-if $(EXIST) $(PACKAGE) ; then              \
	    echo "Not joined: $(PACKAGE) exists" ;   \
	else                                         \
	    $(PERLDIR)/joinpackage -r .  > $(PACKAGE) ; \
	fi ;

#%.join :
#	@-if $(EXIST) $(PACKAGE) ; then              	        \
#	    echo "Not joined: $(PACKAGE) exists" ;    	        \
#	else                                              	\
#	    $(PERLDIR)/joinpackage $* -r > $(PACKAGE) ; \
#	fi ;

##### TEST AND COMPILE RULES #####

TEST_FILES = junk $(patsubst %.java,%,$(wildcard *Test.java)) 
testjava: 
	@\
	for name in ${TEST_FILES}     ; do \
	  if [ -f $${name}.java ]; then \
	    ${MAKE} ${PACKAGE}.$${name}.jx ; \
	  fi ; \
	done

DEMO_FILES = junk $(patsubst %.java,%,$(wildcard *Demo.java)) 
demojava: 
	@\
	for name in ${DEMO_FILES}     ; do \
	  if [ -f $${name}.java ]; then \
	    ${MAKE} ${PACKAGE}.$${name}.jx ; \
	  fi ; \
	done

JAVA_FILES = junk $(patsubst %.java,%,$(wildcard *.java))
compilejava: 
	@\
	for name in ${JAVA_FILES}     ; do \
	  if [ -f $${name}.java ]; then \
	    ${MAKE}            $${name}.jc ; \
	  fi ; \
	done 

##### CLEAN RULES ######

jclean: java.clean

java.clean: 
	@-touch junk.class; rm *.class

jdistclean: jclean clean.javadoc

removejavadoc clean.javadoc:
	@-touch junk; rm junk $(STP6) $(wildcard $(javadocdir)/$(PACKAGE).html)

    # This is needed for cleaning javadoc files.
    # STP6 is a list of the html files which should be removed.
    # The procedure is complicated because we want to remove, e.g.
    # jest.delete.Class1.html, but not jest.delete.subpackage.ClassX.html
    #
    # Use, e.g., "make STP1.varvalue" to get an idea of what is happening

# STP1 = all doc files beginning with the package name
STP1 = $(wildcard $(javadocdir)/$(PACKAGE).*.html)
# STP2 = strip STP1 of the package prefix and html suffix
STP2 = $(patsubst $(javadocdir)/$(PACKAGE).%.html,%,$(STP1))
STP3 = $(subst /,.,$(sort $(filter-out ./,$(dir $(subst .,/,$(STP2))))))
STP4 = $(addprefix $(javadocdir)/$(PACKAGE).,$(STP3))
STP5 = $(addsuffix %html,$(STP4)) $(addsuffix %.html,$(STP4))
STP6 = $(filter-out $(STP5),$(STP1))
