# $Id: Makefile,v 1.5 2002/09/18 15:06:04 bortzmeyer Exp $

INCLUDES_PGSQL=$(shell pg_config --includedir-server) 
INCLUDES_GADDR=../generic_addr
LIBRARIES=../generic_addr/generic_addr.o
CC_SHARED_OPTIONS=-fpic -shared -expect_unresolved="*"
CC_STATIC_OPTIONS=-static
DATABASE=test
DEBUG=-g -O0
MALLOC=palloc
FREE=pfree
CFLAGS=-Wall ${DEBUG} -DMALLOC=${MALLOC} 
CC=gcc
TARBALL=/tmp/postgresql-ip.tar

all: ip_address.so ip_address.sql 

ip_address.so: ip_address.c ${LIBRARIES}
	${CC} ${CFLAGS} -I${INCLUDES_PGSQL} -I${INCLUDES_GADDR} \
		${CC_SHARED_OPTIONS} ${LIBRARIES} -o $@ $<
 
ip_address.sql: ip_address.sql.in type_length
	sed -e "s;MODULE_PATHNAME;${PWD}/ip_address.so;" \
		-e "s;TYPE_LENGTH;`./type_length`;" $< > $@

test_ip_address: test_ip_address.c ip_address.c
	${CC} ${CFLAGS} -I${INCLUDES_PGSQL} -I${INCLUDES_GADDR} \
		${CC_STATIC_OPTIONS} ${LIBRARIES} -o $@ $<
 
palloc.o: palloc.c
	${CC} ${CFLAGS} -c -o $@ $<

type_length: type_length.c palloc.o
	${CC} ${CFLAGS} -I${INCLUDES_GADDR} \
		palloc.o -o $@ $<

install: ip_address.so ip_address.sql
	psql -f ./ip_address.sql ${DATABASE}

test:
	psql -f ./test_ip_address.sql ${DATABASE}

dist: clean
	(cd ..; tar -cv --exclude=CVS -f ${TARBALL} postgresql-ip; gzip --best --verbose --force ${TARBALL})

clean:
	rm -f *.o *.so ip_address.sql test_ip_address type_length *~

db-clean: 
	psql -f ./clean_ip_address.sql ${DATABASE}

realclean: clean db-clean
	rm -f *~

