#!/usr/bin/make -f

ifndef PERL
PERL="/usr/bin/perl"
endif

DEB_PACKAGES=Image-Base Image-Xpm Image-Xbm
DESTDIR=$(CURDIR)/debian/libimage-base-bundle-perl

# Since Image;:X{p,b}m requires Image::Base, add Image::Base to @INC
# so we can test.
export PERL5LIB=$(CURDIR)/build-tree/Image-Base/blib/lib

unpack: unpack-stamp
unpack-stamp:
	mkdir -p build-tree
	cp -pr $(DEB_PACKAGES) build-tree
	touch $@

build-indep: unpack $(patsubst %,build-%-stamp,$(DEB_PACKAGES))
build-%-stamp:
	cd build-tree/$(patsubst build-%-stamp,%,$@) && \
	$(PERL) Makefile.PL INSTALLDIRS=vendor && \
	$(MAKE) && \
	$(MAKE) test

	touch $@

# do nothing
build-arch:

build: build-indep

clean:
	rm -rf unpack-stamp build-*-stamp build-tree
	dh_clean

install: build $(patsubst %,install-%-stamp,$(DEB_PACKAGES))
install-%-stamp:
	dh_testdir
	dh_installdirs

	$(MAKE) -C build-tree/$(patsubst install-%-stamp,%,$@) install DESTDIR=$(DESTDIR)

#	MURDER DUMB /usr/lib DIRECTORY
	rm -rf $(DESTDIR)/usr/lib

# do nothing
binary-arch:


binary-indep: build install
	dh_testdir
	dh_installchangelogs
	dh_installdocs
	dh_installman
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_perl
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep
.PHONY: unpack build-indep build-arch build clean binary-indep binary-arch binary install
