#*******************************************************************************
# E.S.O. - ALMA project
#
# "@(#) $Id: javaMakefile,v 2.215 2005/11/16 08:22:35 vltsccm Exp $"
#
# who       when      what
# --------  --------  ----------------------------------------------
# mzampare  2005-06-06 VLTSW20050190
# mzampare  2002-11-12 VLTSW20020559 and VLTSW20020518 implemented
# mzampare  27/06/02  SHELL changed to ksh
# mzampare  26/06/02  vltMakeJava2Dependencies -> acsMakeJavaDependencies
# mzampare  20/06/02  created
#
#
#************************************************************************
#   NAME
#   javaMakefile - language specific Makefile
#
#   DESCRIPTION
#   The javaMakefile handles the targets to make, install and clean 
#   Java code (all files in the src directory of a software module 
#   with extension .java)
#
#   All the files .java are compiled calling the Java compiler. 
#   The resulting .class files are put in the ../object directory.
#   Afterwards, all the files .class existing in the ../object 
#   directory are combined in one or more  JAR archive files which are
#   created in the ../lib directory. 
#   
#   The "make install" will copy this jar file under the lib 
#   directory of the installation root (INTROOT, VLTROOT...)
#
#   The names of the jar files are determined by the user who will 
#   have to define in the module's Makefile the variable: 
#   JARFILES = <jjj1> <jjj2> .... (without extension .jar)
#   (name of the resulting jar files without extension)
#   plus corresponding directories in the form of
#   <jjj1>_DIRS = <dir11> <dir12> ... (space separated)
#   <jjj2>_DIRS = <dir21> <dir22> ...
# 
#   Additional non java files can be added specifying the directories they
#   are in, relative to the module src directory, in the following form:
#   <jjj>_EXTRAS = images
#
#    or
#
#   <jjj>_EXTRAS = sounds/rock/queen.au sounds/classic/Beethoven.au
#
#   Compiler options to the javac compiler can be passed by setting the
#   USER_JFLAGS and <jjj>_JFLAGS.
#
#   A single Jarfile may require to use the 'endorsed' behaviour, in which case
#   <jjj>_ENDORSED="on" can be used.
#
#   CLASSPATH: is generated by a custom script. It takes the initial 
#   value of CLASSPATH from the shell and augments it with all jarfiles 
#   contained in <module>/lib, $INTROOT/lib and $VLTROOT/lib, in
#   that sequence. 
#
#   Java byte compiled code goes under <module>/object, possibly 
#   under a directory structure reflecting the Java package 
#   structure. Jarfiles are created, as specified in the JARFILES 
#   variable and moved to the lib directory.
#
#   The DEBUG flag can be set, to make original Java files to be appended
#   in the jarfile.
#
#   make clean deletes all *.class files from object 
#
#   FILES
#   vltMakeJavaClasspath: Utility used by vltMakefile to dynamically 
#   generate the CLASSPATH for Java stuff, prior to compilation. 
#   acsMakeJavaDependencies: Utility used by acsMakefile to create 
#   the makefile to build a Java Jarfile
#
#
#   ENVIRONMENT
#
#   CAUTIONS
#
#   EXAMPLES
#
#   SEE ALSO
#   VLTROOT/include/vltMakefile
#             VLT wide definitions for UNIX or VxWorks
#             This file includes the javaMakefile
#
#   BUGS
#
#------------------------------------------------------------------------
#
SHELL=/bin/ksh
######################################
# phony section
######################################
.PHONY : clean_java
.PHONY : install_java
.PHONY : do_java

JavadocLink	:= http://java.sun.com/j2se/1.4.2/docs/api
JavadocOptions	:= -private -author -version -J-Xmx128m 		\
			-link $(JavadocLink) -breakiterator		\
			-source 1.4

######################################
# incrementing tasks
######################################
JARFILES_LIST = $(JARFILES) $(JARFILES_L)
TMP_DEP_JAR := $(addprefix ../object/, $(addsuffix .djar, $(JARFILES_LIST) ))

ifndef MAKE_VXWORKS
ifneq ($(strip $(JARFILES_LIST)),)
    CLEAN_TARGET := $(CLEAN_TARGET) clean_java
endif

ifneq ($(strip $(JARFILES)),)
    INSTALL_TARGET := $(INSTALL_TARGET) install_java
endif

ifneq ($(strip $(JARFILES_LIST)),)
    ALL_TARGET := $(ALL_TARGET) do_java
endif
endif
######################################
# targets specification
######################################

## install
##
install_java:
ifneq ($(strip $(JARFILES)),)
	-@$(ECHO) "install_java: java_begin $(foreach member, $(JARFILES), $(LIB)/$(member).jar  )" >>$(FILE)
	-@$(ECHO) "java_begin:" >>$(FILE)
	-@$(ECHO) "	-@echo \"\"; $(ECHO) \"......jarfiles:\"" >>$(FILE)
	-$(AT) for member in $(foreach name, $(JARFILES), $(name) ); \
		do \
		    $(ECHO) "$(LIB)/$${member}.jar: ../lib/$${member}.jar" >>$(FILE);\
		    $(ECHO) "	-\$$(AT)echo \"\t$${member}.jar\";\\" >>$(FILE);\
		    $(ECHO) "	cp ../lib/$${member}.jar $(LIB);\\" >>$(FILE);\
		    $(ECHO) "	chmod $(P644) $(LIB)/$${member}.jar" >>$(FILE);\
		done
	-@$(MAKE) -k -f $(FILE) --no-print-directory $(@)
	-@$(RM) $(FILE)
endif

##  clean
##
clean_java:
	-$(AT)$(RM) vltMake_clean_java  $(foreach member,  $(JARFILES_LIST), ../lib/$(member).jar ../object/$(member).djar ../object/$(member) ) ../object/vltMakeIndexFiles.del $(foreach member, $(JDIR), ../object/$(member) )   $(OUTPUT)
#	-$(AT)find ../object -type d ! -name object ! -name CVS | $(XARGS) -i $(RM) {}
#	-$(AT)find ../object -type f ! -name .cvsignore | $(XARGS) -i $(RM) {}
	-@$(ECHO) " .\c"


## all
##
# - for Automatic Dependencies for Jarfiles
#
../object/%.djar:
	- @echo "== Dependencies: $@"
	$(AT)vltMakeJavaDependencies $(*F) "$($(*F)_DIRS)" "$($(*F)_EXTRAS)" "$(USER_JFLAGS)" "$($(*F)_JFLAGS)" "$($(*F)_ENDORSED)" "$(DEBUG)" >../object/$*.djar

do_java:  $(TMP_DEP_JAR)
	$(AT) for member in $(foreach name, $(JARFILES_LIST), $(name) ); \
		do \
		make -f ../object/$${member}.djar ../lib/$${member}.jar;\
		done

javadoc: 
	$(AT)echo "......Javadoc:"
	$(AT)mkdir -p ../doc/api/html
	$(AT)for member in $(foreach jarfile, $(JARFILES_LIST), $($(jarfile)_DIRS)) ;\
		do \
		javadoc $(JavadocOptions) -classpath `vltMakeJavaClasspath` -d ../doc/api/html `find $${member} -type f -name \*.java` > /dev/null 2>&1 ;\
		done


