#!/usr/bin/make -f

BUILDHOME = $(CURDIR)/debian/build
PIDFILE = $(BUILDHOME)/mongod.pid

%:
	dh $@

override_dh_auto_test:
	mkdir -p $(BUILDHOME)
	if [ -x /usr/bin/mongod ]; then \
	  mongod --dbpath $(BUILDHOME) --noprealloc --nojournal --quiet --fork --logpath $(BUILDHOME)/mongod.log --pidfilepath $(PIDFILE); \
	  sleep 10; \
	fi
	dh_auto_test
	# The server process might not have actually started, since
	# the system one will already be running unless policy-rc.d
	# prevented it
	[ ! -s $(PIDFILE) ] || /bin/kill `cat $(PIDFILE)` || true

override_dh_clean:
	# shipped upstream
	dh_clean -X t/lib/MongoDBTest.pm~
	rm -rf $(BUILDHOME)
