#
# normal usage:
#   make
#
# 2010-07-01 need to work on LINT

# 2008-04-22 (added JAVACFLAGS and de-linted)
# 
# to see lint:
#   make JAVACFLAGS=-Xlint
# note: lots of warnings about
#   "[unchecked] unchecked conversion ..."
#   "[cast] redundant cast ..."
# which can be ignored.
# can disable those via
#   make JAVACFLAGS="-Xlint -Xlint:-unchecked -Xlint:-cast"
#
# usually usage (which could be better automated):
#   make JAVACFLAGS=-Xlint >&! Lint.new
#   tkdiff Lint Lint.new
#   (fix any problems; update Lint if needed, e.g., cp Lint.new Lint)

# any options for javac, e.g., see lint above.
JAVACFLAGS =

# advantage of having all *.java files in one directory is that
# can have a single RJ package.
# In constrast, if split into directories, each directory must be
# a separate package.  Then users need to import multiple packages
# (a pain).  Also, such packages must some parts public just so they're
# accessible to other code; that means visible to user
# (and in javadocs).

# I stubbornly want directories in RJ's source just to group
# related files together (and help keep me sane?).
# But, as I understand things (I could be wrong), files that go in a single
# package must be in one directory (or their names get mixed up,
# e.g., got classNotFound error with wrong name for VM/RJ_impl vs. RJ_impl).
# I thought jar's -C sounded promising, but it seems to remove all
# directory info and works for only 1 file (or entire directory) at a time,
# neither of which would be good.
#
# CAUTION: source has some hardwired strings with "edu.ucdavis.rj"
# make sure to change those (back to, e.g., edu.ucdavis.rj.VM)
# if undue this scheme.  Watch out for the one in RemoteRefs.java.
# best to grep for "edu".
#
# so, expedient solution: copy all Java files to one directory,
# build it there, and all should be well.
#
# there might be better ways to do this,
# but I didn't see any and got tired of trying.


# name of jar file to create
JARNAME=rj.jar

# where the code lives
# top-level directory:
CODE=edu/ucdavis/rj

# actual .java and backup (~ suffix) files.
# makes some assumptions: e.g., all directories have good stuff.
ALLCODEJAVA=$(CODE)/*.java $(CODE)/*/*.java
ALLCODEBK=$(CODE)/*~ $(CODE)/*/*~

PROPSFILE=resources/rj.properties
PROPS=$(CODE)/VM/$(PROPSFILE)
BUILDPROPS=$(CODE)/$(PROPSFILE)

# shouldn't need this anymore (since should be building elsewhree),
# but just in case need to clean.
ALLCODECLASS=$(CODE)/*.class $(CODE)/*/*.class

# directory in which to build and translate code
BUILDCODE=build/$(CODE)




all: makejavadoc compiler
	echo Makefile needs some work...

compiler:
	# first do an "include" to build Version.java.
	echo    ""                                    >  $(CODE)/VersionStrings
	echo -n "    private String versionNumber = " >> $(CODE)/VersionStrings
	echo    "\""`cat versionNumber`"\";"          >> $(CODE)/VersionStrings
	echo -n "    private String versionInfo = "   >> $(CODE)/VersionStrings
	echo    "\""`cat versionInfo`"\";"            >> $(CODE)/VersionStrings
	echo -n "    private String versionDate = "   >> $(CODE)/VersionStrings
	echo    "\""`date +%Y-%m-%d.%T`"\";"          >> $(CODE)/VersionStrings
	cat $(CODE)/VersionHead $(CODE)/VersionStrings $(CODE)/VersionTail > $(CODE)/Version.java

	echo "rj.version=\\"                          >  $(PROPS)
	echo -n "`cat versionNumber`"                 >> $(PROPS)
	echo -n " "                                   >> $(PROPS)
	echo -n "`cat versionInfo`"                   >> $(PROPS)
	echo -n " ("                                  >> $(PROPS)
	echo -n "`date +%Y-%m-%d.%T`"                 >> $(PROPS)
	echo    ")"                                   >> $(PROPS)

	# now copy to build directory.
	# make sure it's not there.
	\rm -rf build
	mkdir -p $(BUILDCODE)
	cp $(ALLCODEJAVA) $(BUILDCODE)
	mkdir $(BUILDCODE)/resources
	cp $(PROPS) $(BUILDCODE)/resources
	# the following work since $(CODE)
	# are now relative to build.
	cd build; javac $(JAVACFLAGS) $(CODE)/*.java
	# and make the jar
	# (doing so components will have edu/... names,
	#  not build/edu/... names)
	cd build; jar cf0 $(JARNAME) $(CODE)/*.class $(BUILDPROPS)
	cd build; \mv $(JARNAME) ..
	echo "add jar i $(JARNAME)????"
	jar i $(JARNAME)
	echo "rm build????"
	## \rm -rf build

clean:
	rm -rf $(ALLCODECLASS)

cleanbk:
	rm -rf $(ALLCODEBK)

makejavadoc:
	echo needs work....... but run with and without private
	echo add package-level Package Comment File
	javadoc -d javadoc/private -private $(ALLCODEJAVA)
	# use @publicFiles so that users don't see some files
	# that need to be public due to access for serializable.
	echo "MAKE SURE @publicFiles is uptodate"
	# javadoc -d javadoc/public           $(ALLCODEJAVA)
	javadoc -d javadoc/public           @publicFiles
