# makefile --
#
# Generic Makefile for building e4Graph on UNIX with GNU C++.
#
# Author: Jacob Levy, jyl@best.com
#
# 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:

ALLLIBS	= -L$(METAKIT_LIB) -lmk4 ${LIBS}

# The directories containing the source code:

INTF = ../intf
IMPL = ../impl

# The Metakit driver directory:

MKDRV = ../mkdriver

# The directory containing the include files:

INCLUDE = ../include

# What are the sources for e4Graph:

CPPSOURCES = \
	$(MKDRV)/mkstorage.cpp		\
	$(INTF)/e4refcount.cpp		\
	$(INTF)/e4id.cpp		\
	$(INTF)/e4node.cpp		\
	$(INTF)/e4storage.cpp		\
	$(INTF)/e4vertex.cpp		\
	$(INTF)/e4nvisitor.cpp		\
	$(INTF)/e4pvisitor.cpp		\
	$(INTF)/e4svisitor.cpp		\
	$(INTF)/e4vvisitor.cpp		\
	$(IMPL)/i4drivers.cpp		\
	${IMPL}/i4dstring.cpp		\
	$(IMPL)/i4intstack.cpp		\
	${IMPL}/i4node.cpp		\
	${IMPL}/i4storage.cpp		\
	${IMPL}/i4vertex.cpp		\
	${IMPL}/i4hash.cpp


# What include flags to pass to the compiler:

INCLUDES = \
	-I${INCLUDE} \
	-I${MKDRV} \
	-I${METAKIT_INC}

# Where to put object files:

PRODOBJDIR = ${PRODUCT_DIR}/objects/main

# Where to put libraries:

PRODLIBDIR = ${PRODUCT_DIR}/libs

# Where to put include files:

PRODINCDIR = ${PRODUCT_DIR}/include

# The object files:

OBJECTS = \
	${PRODOBJDIR}/mkstorage.o	\
	${PRODOBJDIR}/e4refcount.o	\
	${PRODOBJDIR}/e4id.o		\
	${PRODOBJDIR}/e4node.o		\
	${PRODOBJDIR}/e4storage.o	\
	${PRODOBJDIR}/e4vertex.o	\
	${PRODOBJDIR}/e4nvisitor.o	\
	$(PRODOBJDIR)/e4pvisitor.o	\
	${PRODOBJDIR}/e4svisitor.o	\
	${PRODOBJDIR}/e4vvisitor.o	\
	${PRODOBJDIR}/i4dstring.o	\
	${PRODOBJDIR}/i4drivers.o	\
	${PRODOBJDIR}/i4intstack.o	\
	${PRODOBJDIR}/i4node.o		\
	${PRODOBJDIR}/i4storage.o	\
	${PRODOBJDIR}/i4vertex.o	\
	${PRODOBJDIR}/i4hash.o

# What optimization options to pass to the compiler. Collect all
# the flags specified in the makefile.include and by users on
# the command line, e.g. 'make CPPFLAGS=...'.

ALLCPPFLAGS = $(CPPFLAGS) $(INCLUDES) -DE4_DLL -DDEBUG

# Main target: makes libe4graph.so:

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

# static: makes libe4graphs.a:

static: ${PRODLIBDIR}/libe4graphs.a includes

# Install the library:

install: all
	-mkdir -p $(includedir)
	cp -p ../include/e4graph.h $(includedir)/e4graph.h
	-@mkdir -p $(libdir)
	cp -p	${PRODLIBDIR}/libe4graph$(SHLIB_SUFFIX) \
		$(libdir)/libe4graph$(SHLIB_SUFFIX).0.0.0
	-/bin/rm -f $(libdir)/libe4graph$(SHLIB_SUFFIX) \
		    $(libdir)/libe4graph$(SHLIB_SUFFIX).0
	-ln -s libe4graph$(SHLIB_SUFFIX).0.0.0 \
	       $(libdir)/libe4graph$(SHLIB_SUFFIX)
	-ln -s libe4graph$(SHLIB_SUFFIX).0.0.0 \
	       $(libdir)/libe4graph$(SHLIB_SUFFIX).0

# Install the static library:

install_static: static
	-mkdir -p $(includedir)
	cp -p ../include/e4graph.h $(includedir)/e4graph.h
	-@mkdir -p $(libdir)
	cp -p ${PRODLIBDIR}/libe4graphs.a ${libdir}/libe4graphs.a

# Uninstall the library:

uninstall:
	/bin/rm -f $(includedir)/e4graph.h
	/bin/rm -f $(libdir)/libe4graph$(SHLIB_SUFFIX).0.0.0
	/bin/rm -f $(libdir)/libe4graph$(SHLIB_SUFFIX)
	/bin/rm -f $(libdir)/libe4graph$(SHLIB_SUFFIX).0
	/bin/rm -f $(libdir)/libe4graphs.a

# Release engineering:

release: all static
	mkdir -p $(release_tmp_dir)/include
	cp -p ../include/e4graph.h $(release_tmp_dir)/include/e4graph.h
	mkdir -p $(release_tmp_dir)/lib
	cp -p ${PRODLIBDIR}/libe4graph$(SHLIB_SUFFIX) \
	      $(release_tmp_dir)/lib/libe4graph$(SHLIB_SUFFIX).0.0.0
	cp -p ${PRODLIBDIR}/libe4graph$(SHLIB_SUFFIX) \
	      $(release_tmp_dir)/lib/libe4graph$(SHLIB_SUFFIX)
	cp -p ${PRODLIBDIR}/libe4graph$(SHLIB_SUFFIX) \
	      $(release_tmp_dir)/lib/libe4graph$(SHLIB_SUFFIX).0
	cp -p ${PRODLIBDIR}/e4graph.a $(release_tmp_dir)/lib/e4graph.a

# Create the library:

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

# Create the static library (e4graph.a):

${PRODLIBDIR}/libe4graphs.a: $(OBJECTS)
	-@mkdir -p ${PRODLIBDIR}
	$(AR) cr ${PRODLIBDIR}/libe4graphs.a $(OBJECTS)
	$(RANLIB) ${PRODLIBDIR}/libe4graphs.a

# Create the includes:

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

# Individual file targets:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# Clean:

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