#!/usr/bin/make -f
# Copyright 1997 by Oliver Elphick.
# Available for use under the same licence terms as the upstream package,
# (mutatis mutandis).

package=	postgresql
version=	6.3

# This conditional to enable compilation on Alphas as well as Intel
ifneq ($(shell dpkg --print-architecture),alpha)
TEMPLATE=linux-elf
else
TEMPLATE=linuxalpha
endif
ARCH=$(shell dpkg --print-architecture)


HERE :=		$(shell pwd)
TMPFILE := 	$(shell mktemp /tmp/postgresql.XXXXXX)
installdir=	$(HERE)/debian/tmp/usr/lib/postgresql/dumpall/6.3

build: src/config.cache
	dh_testdir
	dh_installdirs
	cd src  &&  make all
	touch build

src/config.cache:
	cd src &&\
	    echo /usr/include/ncurses /usr/include/readline | \
	    ./configure --prefix=$(HERE)/debian/tmp/usr/lib/postgresql \
	    --with-template=$(TEMPLATE) \
	    --enable-locale

clean:
	dh_testdir
	-rm -f src/config.cache
	-rm -f build
	-cd src && make distclean
	-rm -f `find . -name "*~"`
	-rm src/backend/port/tas.s \
		src/backend/port/dynloader.c \
		src/include/dynloader.h \
		src/include/os.h \
		src/Makefile.port \
		src/interfaces/libpq/libpq++.a
	-rm src/interfaces/libpq++/libpq++.so.1
	dh_clean

binary-indep:	
	# no architecture-independent elements

binary-arch:	build
	dh_testdir
	dh_testroot -a
	dh_clean -a -k
	dh_installdirs -a
	install -m 644 COPYRIGHT debian/tmp/usr/share/doc/postgresql-slink/copyright
	install -m 755 -o postgres src/bin/psql/psql $(installdir)
	install -m 755 -o postgres src/bin/pg_dump/pg_dump $(installdir)
	install -m 755 -o postgres src/backend/postgres $(installdir)
	install -m 755 -o postgres src/interfaces/libpq/libpq.so.1.1 $(installdir)
	cd $(installdir) && \
		ln -s libpq.so.1.1 libpq.so.1 && \
		ln -s libpq.so.1.1 libpq.so
	dh_installchangelogs -a
	LD_LIBRARY_PATH=`pwd`/src/interfaces/libpq dh_shlibdeps -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_installdeb -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a


# Below here is fairly generic really

binary:		binary-indep binary-arch

.PHONY: binary binary-arch binary-indep clean
