#-------------------------------------------------------------------------
#
# Makefile.inc--
#    Makefile for libpq library
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
#    /usr/local/devel/pglite/cvs/src/libpq/Makefile,v 1.7 1995/03/23 01:22:50 andrew Exp
#
#-------------------------------------------------------------------------

LIB=	pq

MKDIR=	../mk
include $(MKDIR)/postgres.mk

VPATH:= $(VPATH):$(srcdir)/backend/libpq:$(srcdir)/backend/utils/error:\
	$(srcdir)/backend/utils/hash:$(srcdir)/backend/lib

CFLAGS+= -DFRONTEND \
	-I$(srcdir)/backend/$(objdir) \
	-I$(srcdir)/backend/include \
	-I$(srcdir)/backend

#.ifdef KRBVERS
#CFLAGS+= ${KRBFLAGS}
#.endif

LIBSRCS= fe-dumpdata.c fe-pqexec.c fe-pqstubs.c fe-pqufs.c \
	auth.c portal.c portalbuf.c pqcomm.c pqpacket.c pqsignal.c \
	dynahash.c format.c hashfn.c dllist.c

#NOPROFILE=1

#
# We install the necessary header files from the backend directory
# into ${HEADERDIR}.  If this is installed into /usr/include/postgres
# (not the default), then frontend programs could just reference
# the header files as
#
#	#include <postgres/...>
#
# otherwise, the compile line will have to include a directive
# such as in the following example:
#
#	cc -I/usr/local/postgres/include foo.c
#
# -----
#
# We take advantage of the fact that frontend applications
# all will include "c.h" by prepending macro definitions
# to define PORTNAME and PORTNAME_name to c.h.  Otherwise
# the applications would have to define these by hand to get
# the right behavior.
#
# By the way, this is of course a total crock.  The headers
# should be laid out such that the visible public headers
# are all in a separate directory, and just that directory
# would need to be copied out or symlinked to.
#

HEADERFILES= port/$(PORTNAME)/machine.h catalog/pg_user.h \
	storage/ipc.h tcop/fastpath.h libpq/libpq-be.h include/libpq-fe.h \
	libpq/libpq-fs.h libpq/libpq.h include/postgres.h libpq/pqcomm.h \
	lib/dllist.h utils/dynamic_loader.h utils/exc.h \
	utils/geo-decls.h utils/elog.h utils/palloc.h \
	libpq/auth.h libpq/pqsignal.h

ifeq ($(PORTNAME), hpux)
HEADERFILES+= port/$(PORTNAME)/fixade.h
endif

.PHONY: beforeinstall-headers

ifndef NO_BEFOREINSTL
beforeinstall-headers:
	@-if [ ! -d $(HEADERDIR) ]; then mkdir $(HEADERDIR); fi
	@-if [ ! -d $(HEADERDIR)/port ]; then mkdir $(HEADERDIR)/port; fi
	@-if [ ! -d $(HEADERDIR)/port/$(PORTNAME) ]; \
		then mkdir $(HEADERDIR)/port/$(PORTNAME); fi
	@-if [ ! -d $(HEADERDIR)/catalog ]; \
		then mkdir $(HEADERDIR)/catalog; fi
	@-if [ ! -d $(HEADERDIR)/storage ]; \
		then mkdir $(HEADERDIR)/storage; fi
	@-if [ ! -d $(HEADERDIR)/utils ]; \
		then mkdir $(HEADERDIR)/utils; fi
	@-if [ ! -d $(HEADERDIR)/include ]; \
		then mkdir $(HEADERDIR)/include; fi
	@-if [ ! -d $(HEADERDIR)/lib ]; \
		then mkdir $(HEADERDIR)/lib; fi
	@-if [ ! -d $(HEADERDIR)/libpq ]; \
		then mkdir $(HEADERDIR)/libpq; fi
	@-if [ ! -d $(HEADERDIR)/tcop ]; \
		then mkdir $(HEADERDIR)/tcop; fi
else
beforeinstall-headers: .dosomething
endif

install-headers: beforeinstall-headers
	@for i in ${HEADERFILES}; do \
		echo "Installing $(HEADERDIR)/$$i."; \
		$(INSTALL) -c -m 444 $(srcdir)/backend/$$i $(HEADERDIR)/$$i; \
	done
	@mv -f $(HEADERDIR)/include/* $(HEADERDIR)
	@rmdir $(HEADERDIR)/include
#	XXX - installing fmgr.h depends on the backend being built
	$(INSTALL) -c -m 444 $(srcdir)/backend/$(objdir)/fmgr.h $(HEADERDIR)/fmgr.h
	@rm -f ${HEADERDIR}/c.h
	@echo "#undef PORTNAME" >  $(HEADERDIR)/c.h
	@echo "#define PORTNAME $(PORTNAME)" >> $(HEADERDIR)/c.h
	@echo "#undef PORTNAME_$(PORTNAME)" >>  $(HEADERDIR)/c.h
	@echo "#define PORTNAME_$(PORTNAME)" >> $(HEADERDIR)/c.h
	@cat $(srcdir)/backend/include/c.h >> $(HEADERDIR)/c.h
	@chmod 444 $(HEADERDIR)/c.h

install:: install-headers

include $(MKDIR)/postgres.lib.mk
