# -*-makefile-*--------------------------------------------------------------
# $Id: lib_sh_linux.in,v 1.9 1996/10/25 18:56:57 furnish Exp $
#
# Geoffrey Furnish
# IFS, University of Texas at Austin
# 6-Jun-1995
#
# PLplot build rules for archive and shared library under Linux.
# Based on prior work by Maurice.
# -----------------------------------------------------------------------------

# -----------------------------------------------------------------------------
# Set up inference rules appropriate for building both archive and shared
# libraries. 
# -----------------------------------------------------------------------------

.cc.o:
	$(CXX) $(CXX_FLAGS) $<
	cd shared; $(CXX) $(SHLIB_CXXFLAGS) $(CXX_FLAGS) ../$<

.c.o:
	$(CC) $(CC_FLAGS) $<
	cd shared; $(CC) $(SHLIB_CCFLAGS) $(CC_FLAGS) ../$<

.f.o:
	$(F77) $(F77_FLAGS) $<
	cd shared; $(F77) $(SHLIB_F77FLAGS) $(F77_FLAGS) ../$<

# -----------------------------------------------------------------------------
# Library dependency list and targets
# -----------------------------------------------------------------------------

SOVERSION	= @SOVERSION@
LIBVERSION	:= $(shell ./version)

PLLIB_SO	= $(PLLIB_PATH)$(PLLIB_BASE)$(LIB_TAG).so.$(SOVERSION)
# Modified by Rafael Laboissiere <rafael@icp.inpg.fr> on 1998/06/13
# avoid "./" prepended to *.so name
# PLLIB_SO	= $(PLLIB_PATH)$(PLLIB_BASE).so.$(SOVERSION)
PLLIB_SO	= $(PLLIB_BASE)$(LIB_TAG).so.$(SOVERSION)
# Modified by Rafael Laboissiere <rafael@icp.inpg.fr> 
# on Thu Nov 12 18:11:45 CET 1998
# For the Debian plplot pakcage
# should include $(LIB_TAG) in SONAME and have only $(MAJOR_VERSION) at end
# SONAME		= $(PLLIB_BASE)$(LIB_TAG).so.$(SOVERSION)
# SONAME		= $(PLLIB_BASE).so.$(SOVERSION)
SONAME		= $(PLLIB_BASE)$(LIB_TAG).so.$(MAJOR_VERSION)


PLLIBS = $(PLLIB_AR) $(PLLIB_SO)
MATLIBS = $(MATLIB_AR) $(MATLIB_SO)
CXXLIBS = $(CXXLIB_AR) $(CXXLIB_SO)

libs:	$(MATLIBS) $(PLLIBS) $(CXXLIBS)

$(PLLIB_AR):	$(LIB_OBJS)
	-$(RM) $(PLLIB_AR)
	@echo ""; echo "Building archive library"; echo ""
	$(ARLIB_BUILD) $(PLLIB_AR) $(LIB_OBJS)
	$(RANLIB) $(PLLIB_AR)

$(MATLIB_AR): $(MAT_OBJS)
	-$(RM) $(MATLIB_AR)
	@echo ""; echo "Building archive library"; echo ""
	$(ARLIB_BUILD) $(MATLIB_AR) $(MAT_OBJS)
	$(RANLIB) $(MATLIB_AR)
	@echo ""

$(CXXLIB_AR): $(CXX_OBJS)
	-$(RM) $(CXXLIB_AR)
	@echo ""; echo "Building archive library"; echo ""
	$(ARLIB_BUILD) $(CXXLIB_AR) $(CXX_OBJS)
	$(RANLIB) $(CXXLIB_AR)
	@echo ""

# The following rule based (very) loosely on what I see David Engel
# did in his Linux Tcl/Tk port.  

# NOTE: We have to link with iostream in order to satisfy the
# references to cout and friends in the C++ interface class.  And we
# do /not/ link with libg++ so as to avoid conflicts between the
# libg++ String class and the DS++ String class.  Oh, but for C++
# namespace support...

$(PLLIB_SO):	$(LIB_OBJS) stupidtk.o
	-$(RM) $(PLLIB_SO)
	@echo ""; echo "Building shared library"; echo ""
	cd shared; \
	$(SHLIB_BUILD) ../$(PLLIB_SO).$(LIBVERSION) \
		-Wl,-soname -Wl,$(SONAME) \
		$(LIB_OBJS) stupidtk.o $(LDC_LIBS)
	ln -sf $(PLLIB_SO).$(LIBVERSION) $(SONAME)
#       Modified by Rafael Laboissiere <rafael@icp.inpg.fr>
#       on Thu Nov 12 20:07:46 CET 1998
#	ln -sf $(SONAME) $(PLLIB_BASE).so
	ln -sf $(SONAME) $(PLLIB_BASE)$(LIB_TAG).so
	echo $(LIBVERSION) > version.built
	./version inc
	@echo ""

#	ln -sf $(SONAME) $(PLLIB_BASE)$(LIB_TAG).so

$(MATLIB_SO): $(MAT_OBJS)
	-$(RM) $(MATLIB_SO)
	@echo ""; echo "Building shared library"; echo ""
#       Modified by Rafael Laboissiere <rafael@icp.inpg.fr>
#       on Thu Nov 12 20:07:46 CET 1998
#       When bulding the Python module we will need a shared libs 
#       libMatrix.so to link against
	cd shared; \
	$(SHLIB_BUILD) ../$(MATLIB_SO) \
		-Wl,-soname -Wl,libMatrix$(SO).$(MAJOR_VERSION) \
                $(MAT_OBJS)
	ln -sf $(MATLIB_SO) libMatrix$(SO).$(MAJOR_VERSION)
	ln -sf libMatrix$(SO).$(MAJOR_VERSION) libMatrix$(SO)
	@echo ""

$(CXXLIB_SO): $(CXX_OBJS)
	-$(RM) $(CXXLIB_SO)
	@echo ""; echo "Building shared library"; echo ""
	cd shared; \
	$(SHLIB_BUILD) ../$(CXXLIB_SO) $(CXX_OBJS)
	@echo ""

# -----------------------------------------------------------------------------
# Sick hacks.
# -----------------------------------------------------------------------------

# Needs to be compiled using K&R C.

tcpip.o:
	$(OCC) $(CC_FLAGS) tcpip.c
	cd shared; $(OCC) $(SHLIB_CCFLAGS) $(CC_FLAGS) ../tcpip.c

stupidtk.o:
	$(CC) $(CC_FLAGS) stupidtk.c
	cd shared; $(CC) $(SHLIB_CCFLAGS) $(CC_FLAGS) ../stupidtk.c

