# Makefile for e4java, a Java extension to use the e4Graph package.
#
# Copyright (c) 2000-2003, JYL Software Inc.
# 
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
# 
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE, EVEN IF
# JYL SOFTWARE INC. IS MADE AWARE OF THE POSSIBILITY OF SUCH DAMAGE.

# Include the parameters determined at configure time:

include ../../all/makefile.include

# Which libraries to link with the libe4java. We use the assignment
# syntax (rather than +=) to make this work with HPUX and Tru64 make.

ALLLIBS	= \
	-L${PRODUCT_DIR}/libs -le4graph \
	-L${METAKIT_LIB} -lmk4 \
	${LIBS}

# Where to find source and include files:

SRC		= ./../natives
INCLUDE		= ./../include
E4GRAPHINCLUDE	= ./../../main/include
JAVAINCLUDE	= -I${JAVA_DIR}/include -I$(JAVA_DIR)/include/$(JAVA_SYS_DIR)

# Where to put object files:

PRODOBJDIR	= ${PRODUCT_DIR}/objects/java

# Where to put libraries:

PRODLIBDIR	= ${PRODUCT_DIR}/libs

# Where to put include files:

PRODINCDIR	= ${PRODUCT_DIR}/include

# The source, include and object files for the e4Java package:

SOURCE = \
	$(SRC)/com_e4graph_Node.cpp \
	$(SRC)/com_e4graph_Storage.cpp \
	$(SRC)/com_e4graph_Vertex.cpp

OBJECTS = \
	${PRODOBJDIR}/com_e4graph_Node.o \
	${PRODOBJDIR}/com_e4graph_Storage.o \
	${PRODOBJDIR}/com_e4graph_Vertex.o

INCLUDES = -I${INCLUDE} -I${E4GRAPHINCLUDE} ${JAVAINCLUDE}

# Compile flags. Collect all the flags specified in the makefile.include
# and by users on the command line, e.g. 'make CPPFLAGS=...'.

ALLCPPFLAGS = $(CPPFLAGS) ${INCLUDES}

# Main target:

all: ${PRODLIBDIR}/libe4java${SHLIB_SUFFIX} includes

# Install the package.

install: all
	-mkdir -p $(libdir)
	cp -p ${PRODLIBDIR}/libe4java${SHLIB_SUFFIX} \
	      $(libdir)/libe4java${SHLIB_SUFFIX}.0.0.0
	-/bin/rm -f $(libdir)/libe4java${SHLIB_SUFFIX} \
		    $(libdir)/libe4java${SHLIB_SUFFIX}.0
	-ln -s libe4java${SHLIB_SUFFIX}.0.0.0 \
	       $(libdir)/libe4java${SHLIB_SUFFIX}
	-ln -s libe4java${SHLIB_SUFFIX}.0.0.0 \
	       $(libdir)/libe4java${SHLIB_SUFFIX}.0
	cp -p ../classes/e4java.jar $(libdir)

# Uninstall the package:

uninstall:
	/bin/rm -f $(libdir)/libe4java${SHLIB_SUFFIX}.0.0.0
	/bin/rm -f $(libdir)/libe4java${SHLIB_SUFFIX}
	/bin/rm -f $(libdir)/libe4java${SHLIB_SUFFIX}.0
	/bin/rm -f $(libdir)/e4java.jar

# Release engineering:

release: all
	mkdir -p $(release_tmp_dir)/lib
	cp -p ${PRODLIBDIR}/libe4java${SHLIB_SUFFIX} \
	      $(release_tmp_dir)/lib/libe4java${SHLIB_SUFFIX}.0.0.0
	cp -p ${PRODLIBDIR}/libe4java${SHLIB_SUFFIX} \
	      $(release_tmp_dir)/lib/libe4java${SHLIB_SUFFIX}
	cp -p ${PRODLIBDIR}/libe4java${SHLIB_SUFFIX} \
	      $(release_tmp_dir)/lib/libe4java${SHLIB_SUFFIX}.0
	cp -p e4java.jar $(release_tmp_dir)/lib/e4java.jar

# Build the library:

${PRODLIBDIR}/libe4java${SHLIB_SUFFIX}: ${OBJECTS}
	-@mkdir -p ${PRODLIBDIR}
	${SHLIB_LD} -o ${PRODLIBDIR}/libe4java${SHLIB_SUFFIX} \
		    ${OBJECTS} ${ALLLIBS}

# Produce the include files:

includes:
	-@mkdir -p ${PRODINCDIR}
	-@cp ${INCLUDE}/*.h ${PRODINCDIR}

# Individual file targets:

${PRODOBJDIR}/com_e4graph_Node.o: $(SRC)/com_e4graph_Node.cpp
	-@mkdir -p ${PRODOBJDIR}
	$(CXX) -c $(CXXFLAGS) $(ALLCPPFLAGS) $(SRC)/com_e4graph_Node.cpp -o $@

${PRODOBJDIR}/com_e4graph_Storage.o: $(SRC)/com_e4graph_Storage.cpp
	-@mkdir -p ${PRODOBJDIR}
	$(CXX) -c $(CXXFLAGS) $(ALLCPPFLAGS) $(SRC)/com_e4graph_Storage.cpp \
	       -o $@

${PRODOBJDIR}/com_e4graph_Vertex.o: $(SRC)/com_e4graph_Vertex.cpp
	-@mkdir -p ${PRODOBJDIR}
	$(CXX) -c $(CXXFLAGS) $(ALLCPPFLAGS) $(SRC)/com_e4graph_Vertex.cpp \
	       -o $@

# Clean:

clean:
	-/bin/rm -f ${PRODLIBDIR}/libe4java${SHLIB_SUFFIX}
	-/bin/rm -f ${OBJECTS}
	-/bin/rm -f *~ #*
