#-------------------------------------------------------------------------
#
# Makefile
#    Makefile for libpgtcl library
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
#    $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/Makefile.in,v 1.2 1998/01/17 23:33:32 scrappy Exp $
#
#-------------------------------------------------------------------------

SRCDIR= ../..
include $(SRCDIR)/Makefile.global

INCLUDE_OPT= \
             -I$(SRCDIR)/backend \
             -I$(SRCDIR)/include \
             -I$(LIBPQDIR) \
             -I$(TCL_INCDIR)

PORTNAME=@PORTNAME@

CFLAGS+= $(INCLUDE_OPT)
ifdef KRBVERS
CFLAGS+= $(KRBFLAGS)
endif

# Shared library stuff

install-shlib-dep :=
shlib             := 

ifeq ($(PORTNAME), linux)
  ifdef LINUX_ELF
    install-shlib-dep	:= install-shlib
    shlib		:= libpgtcl.so.1
    CFLAGS		+= $(CFLAGS_SL)
    LDFLAGS_SL		= -shared -L $(SRCDIR)/interfaces/libpq -lpq
  endif
endif

ifeq ($(PORTNAME), bsd)
  install-shlib-dep	:= install-shlib
  shlib			:= libpgtcl.so.1.0
  LDFLAGS_SL		= -x -Bshareable -Bforcearchive
  CFLAGS		+= $(CFLAGS_SL)
endif

ifeq ($(PORTNAME), i386_solaris)
  install-shlib-dep	:= install-shlib
  shlib			:= libpgtcl.so.1
  LDFLAGS_SL		= -G -z text -L $(SRCDIR)/interfaces/libpq -lpq
  CFLAGS		+= $(CFLAGS_SL)
endif

ifeq ($(PORTNAME), univel)
  install-shlib-dep	:= install-shlib
  shlib			:= libpgtcl.so.1
  LDFLAGS_SL		= -G -z text -L $(SRCDIR)/interfaces/libpq -lpq
  CFLAGS		+= $(CFLAGS_SL)
endif

OBJS= pgtcl.o pgtclCmds.o pgtclId.o


all: libpgtcl.a $(shlib)

libpgtcl.a: $(OBJS)
ifdef MK_NO_LORDER
	$(AR) $(AROPT) libpgtcl.a $(OBJS)
else
	$(AR) $(AROPT) libpgtcl.a `lorder $(OBJS) | tsort`
endif
	$(RANLIB) libpgtcl.a

$(shlib): $(OBJS)
	$(LD) $(LDFLAGS_SL) -o $@ $(OBJS) 
	ln -sf $@ libpgtcl.so

.PHONY: beforeinstall-headers install-headers
.PHONY: install install-libpgtcl

install: install-headers install-libpgtcl $(install-shlib-dep)

install-headers: beforeinstall-headers libpgtcl.h
	$(INSTALL) $(INSTLOPTS) libpgtcl.h $(HEADERDIR)/libpgtcl.h

beforeinstall-headers:
	@if [ ! -d $(HEADERDIR) ]; then mkdir $(HEADERDIR); fi

install-libpgtcl: libpgtcl.a
	$(INSTALL) $(INSTL_LIB_OPTS) libpgtcl.a $(DESTDIR)$(LIBDIR)/libpgtcl.a

install-shlib: $(shlib)
	$(INSTALL) $(INSTL_LIB_OPTS) $(shlib) \
		$(DESTDIR)$(LIBDIR)/$(shlib)
	ln -sf $(shlib) $(DESTDIR)$(LIBDIR)/libpgtcl.so

.PHONY: clean
clean: 
	rm -f $(OBJS) $(shlib) libpgtcl.a libpgtcl.so
