# Hacked, self-contained makefile for libpq
#

ifndef MK
MK=mk
endif

DEST_LIB_DIR=/usr1/snl/pthreads/lib

DEST_LIBA_NAME=libpq-threaded-krb.a

DEST_INCLUDE_DIR=/usr1/snl/pthreads/include/postgres

INSTALL_LIB=cp -p

# Change this line when you recompile, or send it in on the command line:
#PORTNAME=alpha
PORTNAME=sparc
#PORTNAME=linux
#PORTNAME=hpux

# Change this line for kerberos stuff
#KRBVERS=4
#KRBVERS=5

# Change this line for pthreads stuff
PTHREADS=mit
#PTHREADS=decosf1
#PTHREADS=aix
#PTHREADS=hpux

# Change this for threads stuff, too
PTHREADS_DIR=$(HOME)/pthreads
#PTHREADS_DIR=/usr/local

ifdef PTHREADS
maybe=$(MK)/$(PTHREADS)_pthreads.mk
expand_maybe=$(shell [ -f $(maybe) ] && echo $(maybe))
ifeq ("$(expand_maybe)","")
  expand_maybe=/dev/null
endif
include $(expand_maybe)
endif

CC=gcc
COPT=-O2
#COPT=-g
ifdef VPATH
VPATH_CFLAGS=$(shell echo .:$(VPATH) | sed -e 's/^/:/' -e 's/:$$//' -e 's/:/ -I/g')
endif
CFLAGS+=$(VPATH_CFLAGS) -I. -Itmp $(COPT) -DPOSTPORT=\"4321\" -DPORTNAME_$(PORTNAME) -DFRONTEND

LIBA=libpq.a

include $(MK)/kerberos.mk

maybe=$(MK)/$(PORTNAME).mk
expand_maybe=$(shell [ -f $(maybe) ] && echo $(maybe))
ifeq ("$(expand_maybe)","")
  expand_maybe=/dev/null
endif
include $(expand_maybe)

SRCS=	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 simplelists.c $(THREAD_SRCS)
OBJS=   $(SRCS:.c=.o)

HEADERFILES= port/${PORTNAME}/machine.h catalog/pg_user.h catalog/pg_lobj.h \
	storage/execipc.h storage/ipc.h storage/ipci.h \
	tmp/fastpath.h tmp/libpq-be.h tmp/libpq-fe.h \
	tmp/libpq-fs.h tmp/libpq.h tmp/postgres.h tmp/pqcomm.h \
	tmp/simplelists.h utils/dynamic_loader.h \
	utils/exc.h utils/log.h utils/geo-decls.h tmp/c.h \
	libpq/auth.h libpq/pqsignal.h $(THREAD_HEADERS)

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

all: $(LIBA)

install: install-lib install-headers

install-lib: all
	$(INSTALL_LIB) $(LIBA) $(DEST_LIB_DIR)/$(DEST_LIBA_NAME)
	$(RANLIB) $(DEST_LIB_DIR)/$(DEST_LIBA_NAME)

install-headers:
	-mkdir $(DEST_INCLUDE_DIR)
	tar cfh - $(HEADERFILES) | (cd $(DEST_INCLUDE_DIR); tar xvf -)

$(LIBA): $(LIBA)($(OBJS))
	$(RANLIB) $(LIBA)

clean:
	-/bin/rm -f *.[oa] core a.out *~ TAGS \#*\#

TAGS:
	etags *.[ch] */*.[ch] */*/*.[ch] */*/*/*.[ch]

linecount:
	wc -l $(SRCS) $(HEADERFILES)
