#-------------------------------------------------------------------------
#
# Makefile--
#    Makefile for Postgres 1-byte bitmask extensions
#
# Adriaan Joubert <adriaan@albourne.com>
#
# This is an attempt to extend postgres with 1-byte bitmasks. This borrowed
# heavily from the int8 extensions and the complex type in the tutorial.
# This Makefile is a direct copy of the Makefile in the int8 contrib directory
#
#-------------------------------------------------------------------------

ifndef PGDIR
PGDIR= ../..
PGDIR=/data/build/pgsql-990529
endif

SRCDIR= $(PGDIR)/src

include $(SRCDIR)/Makefile.global

# Comment out this re-declaration of LIBDIR
#  if you are installing as the postgres superuser
#   into a specific database or into template1.
#LIBDIR= /home/tgl/lib

CFLAGS+= -I$(PGDIR)/include -I$(PGDIR)/src/include -I$(LIBPQDIR)

TARGETS= bit1.sql bit1$(DLSUFFIX)

all:	$(TARGETS)

bit1$(DLSUFFIX):	bit1.o
	$(CC) -shared -o bit1$(DLSUFFIX) bit1.o $(CLIBS)

install:
	$(MAKE) all
	cp -p bit1$(DLSUFFIX) $(LIBDIR)/contrib
	chmod 555 $(LIBDIR)/contrib/bit1$(DLSUFFIX)

%.sql: %.source
	if [ -z "$$USER" ]; then USER=$$LOGNAME; fi; \
	if [ -z "$$USER" ]; then USER=`whoami`; fi; \
	if [ -z "$$USER" ]; then echo 'Cannot deduce $$USER.'; exit 1; fi; \
	rm -f $@; \
	C=`pwd`; \
	O=$C; \
	if [ -d ${LIBDIR}/contrib ]; then O=${LIBDIR}/contrib; fi; \
	sed -e "s:_CWD_:$$C:g" \
	    -e "s:_OBJWD_:$$O:g" \
	    -e "s:_DLSUFFIX_:$(DLSUFFIX):g" \
	    -e "s/_USER_/$$USER/g" < $< > $@

clean: 
	rm -f $(TARGETS) bit1.o

