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

PQ_INCLUDE=-I$(SRCDIR)/interfaces/libpq

SO_MAJOR_VERSION=2
SO_MINOR_VERSION=3

PORTNAME=@PORTNAME@

ifdef KRBVERS
CFLAGS+= $(KRBFLAGS)
endif

# Shared library stuff
shlib := 
install-shlib-dep :=
ifeq ($(PORTNAME), linux)
  LINUX_ELF=@LINUX_ELF@
  ifdef LINUX_ELF
    install-shlib-dep := install-shlib
    shlib := libecpg.so.$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
    LDFLAGS_SL = -shared -soname libecpg.so.$(SO_MAJOR_VERSION)
  endif
endif
ifeq ($(PORTNAME), bsd)
  ifdef BSD_SHLIB
    install-shlib-dep := install-shlib
    shlib := libecpg.so.$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
    LDFLAGS_SL = -x -Bshareable -Bforcearchive
    CFLAGS += $(CFLAGS_SL)
  endif
endif
#ifeq ($(PORTNAME), solaris)
#  install-shlib-dep := install-shlib
#  shlib := libecpg.so.$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
#  LDFLAGS_SL = -G -z text
#  CFLAGS += $(CFLAGS_SL)
#endif
ifeq ($(PORTNAME), univel)
  install-shlib-dep := install-shlib
  shlib := libecpg.so.1
  LDFLAGS_SL = -G -z text
  CFLAGS += $(CFLAGS_SL)
endif

all: libecpg.a $(shlib)

$(shlib): ecpglib.sho typename.sho
	$(LD) $(LDFLAGS_SL) -o $@ ecpglib.sho typename.sho
	ln -sf $@ libecpg.so

clean:
	rm -f *.o *.sho *.a core a.out *~ $(shlib) libecpg.so

dep depend:

install: libecpg.a $(shlib) $(install-shlib-dep)
	$(INSTALL) $(INSTLOPTS) libecpg.a $(LIBDIR)

install-shlib:
	$(INSTALL) $(INSTLOPTS) $(shlib) $(LIBDIR)
	ln -sf $(shlib) $(LIBDIR)/libecpg.so

uninstall::
	rm -f $(LIBDIR)/libecpg.a $(LIBDIR)/$(shlib)

# Rules that do something
libecpg.a : libecpg.a(ecpglib.o) libecpg.a(typename.o)

ecpglib.o : ecpglib.c ../include/ecpglib.h ../include/ecpgtype.h
	$(CC) $(CFLAGS) -I../include $(PQ_INCLUDE) -c $< -o $@
typename.o : typename.c ../include/ecpgtype.h
	$(CC) $(CFLAGS) -I../include $(PQ_INCLUDE) -c $< -o $@

ecpglib.sho : ecpglib.c ../include/ecpglib.h ../include/ecpgtype.h
	$(CC) $(CFLAGS) $(CFLAGS_SL) -I../include $(PQ_INCLUDE) -c $< -o $@
typename.sho : typename.c ../include/ecpgtype.h
	$(CC) $(CFLAGS) $(CFLAGS_SL) -I../include $(PQ_INCLUDE) -c $< -o $@
