#  
#  COPYRIGHT 2008, KRUPCZAK.ORG, LLC.
# 
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License as
#  published by the Free Software Foundation; either version 2 of
#  the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#  General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
#  02111-1307 USA
# 
#  For more information, visit:
#  http://www.krupczak.org/

# ##############################################################
# global variables, system definitions, etc.

# We use SYSTEM environment variable to determine compilation,
# linking, and runtime environment options
# Choices: LINUX, SOLARIS, WIN32, others TBD
# doublecheck if its set
# Solaris binaries are 64-bit only for Sparc since Solaris/Sparc-32 
# is going by the wayside
# SOLARIS can also be SOLx86 since we are using SOLx86 as a
# test environment; SOLARIS is still the SYSTEM variable though

ifeq "$(origin SYSTEM)" "undefined"
     $(error SYSTEM environment variable not set)
endif

# defaults
ARCH=$(shell uname -p)
RELEASE=$(shell uname -r)
JAVADOC=javadoc -version -author
JAVAC=javac
# JFLAGS can include -Xlint for more verbose warnings
JFLAGS=
CLEANFILES=*.o core.[0-9]* core *.tree *.class
CLEANJAVAFILES=*.class
CLEANCFILES=*.o core.[0-9]* core 

# ##############################################################

all: xmp.jar

# Xmp classes for our basic protocol package
XMP_CLASSES=   Xmp.class \
               SocketOpts.class \
               XmpVar.java \
               XmpSession.class \
               XmpMessage.class \
               ExtendedBoolean.class \
	       XmpServerSession.class \
	       Queryxmp.class \
	       Serverxmp.class \
	       Cartographer.keystore

XMP_SOURCES = Xmp.java \
              SocketOpts.java \
              XmpVar.java \
              XmpSession.java \
              XmpMessage.java \
	      XmpServerSession.java \
              Queryxmp.java \
              Serverxmp.java \
              ExtendedBoolean.java

javadoc: *.java
	$(JAVADOC) $(JFLAGS) -bottom "Copyright 2013 Krupczak.org, LLC" org.krupczak.xmp *.java


Queryxmp.class: Queryxmp.java xmp.jar
	$(JAVAC) $(JFLAGS) Queryxmp.java

Serverxmp.class: Server.java xmp.jar
	$(JAVAC) $(JFLAGS) Serverxmp.java

%.class: $(XMP_SOURCES)
	$(JAVAC) $(JFLAGS) $(XMP_SOURCES)

%.html: %.java 
	$(JAVADOC) $(JFLAGS) -bottom "Copyright 2008 Krupczak.org, LLC" $*.java

release-javadoc: $(JAVA_FILES) java-doc
	cp *.html /www/htdocs/cartographer/api/

xmp.jar: $(XMP_CLASSES) Manifest.txt 
	jar cvfm ../../../$@ Manifest.txt -C ../../../ org
#	jar cvf ../../../$@ -C ../../../ org

linecount:
	wc -l *.java *.xml *.xsd *.[ch]

clean:
	rm -f $(CLEANCFILES)

clean-javadoc:
	rm -f *.html

realclean:
	rm -f $(CLEANCFILES)
	rm -f $(CLEANJAVAFILES)
	rm -f *.html *.css package-list

clean-java:
	rm -f $(CLEANJAVAFILES) xmp.jar 

etags:
	etags *[ch]
