#-------------------------------------------------------------------------
#
# 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.21 1998/09/10 04:59:00 momjian Exp $
#
#-------------------------------------------------------------------------

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

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

PORTNAME=@PORTNAME@

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

# Shared library stuff

install-shlib-dep :=
shlib             := 

LIBPQ			= -L$(SRCDIR)/interfaces/libpq -lpq

ifeq ($(PORTNAME), linux)
  install-shlib-dep	:= install-shlib
  shlib			:= libpgtcl.so.1
  CFLAGS		+= $(CFLAGS_SL)
  LDFLAGS_SL		= -shared
endif

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

ifeq ($(PORTNAME), bsdi)
  ifdef BSD_SHLIB
    ifeq ($(LDSUFFIX), .so)
      install-shlib-dep	:= install-shlib
      shlib		:= libpgtcl.so
      LD		:= shlicc
      LDFLAGS_SL	+= -O -shared
      CFLAGS		+= $(CFLAGS_SL)
    endif
    ifeq ($(LDSUFFIX), .o)
      install-shlib-dep	:= install-shlib
      shlib		:= libpgtcl.o
      LD		:= shlicc
      LDFLAGS_SL	+= -O -r
      CFLAGS		+= $(CFLAGS_SL)
    endif
  endif
endif

ifeq ($(PORTNAME), solaris)
  install-shlib-dep	:= install-shlib
  shlib			:= libpgtcl.so.1
  LDFLAGS_SL		:= -G -z text
  CFLAGS		+= $(CFLAGS_SL)
endif

ifeq ($(PORTNAME), unixware)
  install-shlib-dep	:= install-shlib
  shlib			:= libpgtcl.so.1
  LDFLAGS_SL		:= -G -z text
  CFLAGS		+= $(CFLAGS_SL)
endif

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

ifeq ($(PORTNAME), hpux)
  install-shlib-dep	:= install-shlib
  shlib			:= libpgtcl.sl
  LDFLAGS_SL		:= -b
  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) $(LIBPQ)
	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 $(LIBDIR)/libpgtcl.a

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

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

dep depend:
