# Makefile for tGraph, a Tcl 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 libe4graph. We use the assigment
# syntax (rather than +=) to make this work for HPUX and Tru64 Make
# programs

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

# Where to find source and include files:

SRC		= ./../src
INCLUDE		= ./../include
E4GRAPHINCLUDE	= ./../../main/include

# Where to put object files:

PRODOBJDIR = ${PRODUCT_DIR}/objects/tcl

# Where to put include files:

PRODINCDIR = ${PRODUCT_DIR}/include

# Where to put libraries:

PRODLIBDIR = ${PRODUCT_DIR}/libs

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

SOURCE = \
	$(SRC)/genintrep.c \
	$(SRC)/genobject.c \
	$(SRC)/t4cinit.cpp \
	${SRC}/t4command.cpp \
	$(SRC)/t4event.cpp \
	${SRC}/t4exit.cpp \
	${SRC}/t4init.cpp \
	${SRC}/t4intrep.cpp \
	${SRC}/t4noderep.cpp \
	${SRC}/t4open.cpp \
	${SRC}/t4parse.cpp \
	${SRC}/t4storage.cpp \
	${SRC}/t4storagereg.cpp \
	${SRC}/t4storagerep.cpp \
	${SRC}/t4stored.cpp \
	${SRC}/t4version.cpp \
	${SRC}/t4vertexrep.cpp

OBJECTS = \
	${PRODOBJDIR}/genintrep.o \
	${PRODOBJDIR}/genobject.o \
	${PRODOBJDIR}/t4cinit.o \
	${PRODOBJDIR}/t4command.o \
	${PRODOBJDIR}/t4event.o \
	${PRODOBJDIR}/t4exit.o \
	${PRODOBJDIR}/t4init.o \
	${PRODOBJDIR}/t4intrep.o \
	${PRODOBJDIR}/t4noderep.o \
	${PRODOBJDIR}/t4open.o \
	${PRODOBJDIR}/t4parse.o \
	${PRODOBJDIR}/t4storage.o \
	${PRODOBJDIR}/t4storagereg.o \
	${PRODOBJDIR}/t4storagerep.o \
	${PRODOBJDIR}/t4stored.o \
	${PRODOBJDIR}/t4version.o \
	${PRODOBJDIR}/t4vertexrep.o

INCLUDES = \
	-I${INCLUDE} \
	-I${E4GRAPHINCLUDE} \
	${TCL_INC}

# 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} -DE4_TGRAPHDLL -DUSE_TCL_STUBS

# Main target:

all: ${PRODLIBDIR}/libtgraph$(SHLIB_SUFFIX) includes

# Install the package.

install: all
	-mkdir -p $(includedir)
	cp -p ../include/t4graph.h $(includedir)/t4graph.h
	cp -p ../include/t4graph_c.h $(includedir)/t4graph_c.h
	-mkdir -p $(libdir)
	cp -p ${PRODLIBDIR}/libtgraph$(SHLIB_SUFFIX) \
	      $(libdir)/libtgraph$(SHLIB_SUFFIX).0.0.0
	-/bin/rm -f $(libdir)/libtgraph$(SHLIB_SUFFIX) \
		    $(libdir)/libtgraph$(SHLIB_SUFFIX).0
	-ln -s libtgraph$(SHLIB_SUFFIX).0.0.0 \
	       $(libdir)/libtgraph$(SHLIB_SUFFIX)
	-ln -s libtgraph$(SHLIB_SUFFIX).0.0.0 \
	       $(libdir)/libtgraph$(SHLIB_SUFFIX).0
	-mkdir -p ${TCL_PKG}/tgraph1.0
	-cp ../../all/pkgIndex.tcl ${TCL_PKG}/tgraph1.0

# Uninstall the package:

uninstall:
	/bin/rm -f $(includedir)/t4graph.h
	/bin/rm -f $(includedir)/t4graph_c.h
	/bin/rm -f $(libdir)/libtgraph$(SHLIB_SUFFIX).0.0.0
	/bin/rm -f $(libdir)/libtgraph$(SHLIB_SUFFIX)
	/bin/rm -f $(libdir)/libtgraph$(SHLIB_SUFFIX).0
	/bin/rm -rf ${TCL_PKG}/tgraph1.0

# Release engineering:

release: all
	mkdir -p $(release_tmp_dir)/include
	cp -p ../include/t4graph.h $(release_tmp_dir)/include/t4graph.h
	cp -p ../include/t4graph_c.h $(release_tmp_dir)/include/t4graph_c.h
	mkdir -p $(release_tmp_dir)/lib
	cp -p ${PRODLIBDIR}/libtgraph$(SHLIB_SUFFIX) \
	      $(release_tmp_dir)/lib/libtgraph$(SHLIB_SUFFIX).0.0.0
	cp -p ${PRODLIBDIR}/libtgraph$(SHLIB_SUFFIX) \
	      $(release_tmp_dir)/lib/libtgraph$(SHLIB_SUFFIX)
	cp -p ${PRODLIBDIR}/libtgraph$(SHLIB_SUFFIX) \
	      $(release_tmp_dir)/lib/libtgraph$(SHLIB_SUFFIX).0
	mkdir -p ${release_tmp_dir}/lib/tgraph1.0
	cp -p ../../all/pkgIndex.tcl ${release_tmp_dir}/lib/tgraph1.0

# Build the library:

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

# Make the include files:

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

# Individual file targets:

${PRODOBJDIR}/genintrep.o: $(SRC)/genintrep.c
	-@mkdir -p ${PRODOBJDIR}
	$(CC) -c $(CXXFLAGS) $(ALLCPPFLAGS) $(SRC)/genintrep.c -o $@

${PRODOBJDIR}/genobject.o: $(SRC)/genobject.c
	-@mkdir -p ${PRODOBJDIR}
	$(CC) -c $(CXXFLAGS) $(ALLCPPFLAGS) $(SRC)/genobject.c -o $@

${PRODOBJDIR}/t4cinit.o: $(SRC)/t4cinit.c
	-@mkdir -p ${PRODOBJDIR}
	$(CC) -c $(CXXFLAGS) $(ALLCPPFLAGS) $(SRC)/t4cinit.c -o $@

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# Clean:

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