ifndef PGDIR
PGDIR= ../..
PGDIR=/usr/local/src/db/postgresql-7.1RC1
endif

top_builddir = $(PGDIR)

SRCDIR= $(PGDIR)/src

include $(SRCDIR)/Makefile.global

TARGETS= uint.sql uint$(DLSUFFIX)
# vartest
SOURCE= uint.c 
OBJ= $(SOURCE:.c=.o)
CFLAGS += -I. -g

all:	$(TARGETS)

uint$(DLSUFFIX):	$(OBJ)
	$(CC) $(CFLAGS) $(CPPFLAGS) -shared -o uint$(DLSUFFIX) $(SOURCE) $(CLIBS)

install:
	$(MAKE) all
	cp -p uint$(DLSUFFIX) $(PGLIB)/contrib
	chmod 775 $(PGLIB)/contrib/uint$(DLSUFFIX)

%.sql: %.source
	echo $(SRCDIR)
	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 ${PGLIB}/contrib ]; then O=${PGLIB}/contrib; else \
	echo "contrib directory does not exist."; fi; \
	sed -e "s:_OBJWD_:$$O:g" \
	    -e "s:_DLSUFFIX_:$(DLSUFFIX):g" \
	    -e "s/_USER_/$$USER/g" < $< > $@

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

