#-------------------------------------------------------------------------
#
# Makefile
#    Makefile for libpgtcl library
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
#    $Header: /usr/local/cvsroot/pgsql/src/interfaces/libpgtcl/Makefile.in,v 1.11 1998/04/06 16:52:15 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)
  ifdef LINUX_ELF
    install-shlib-dep	:= install-shlib
    shlib		:= libpgtcl.so.1
    CFLAGS		+= $(CFLAGS_SL)
    LDFLAGS_SL		= -shared
  endif
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), i386_solaris)
  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

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_LIB_OPTS) $(shlib) \
		$(LIBDIR)/$(shlib)
	ln -sf $(shlib) $(LIBDIR)/libpgtcl.so

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

dep depend:
