#!/usr/bin/make -f

# If set to a true value then MakeMaker's prompt function will
# always return the default without waiting for user input.
export PERL_MM_USE_DEFAULT=1

TMP     =$(CURDIR)/debian/tmp

include /usr/share/dpkg/buildflags.mk

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp

build-stamp:
	dh_testdir
	perl Makefile.PL INSTALLDIRS=vendor OPTIMIZE='$(CFLAGS) $(CPPFLAGS)' LD='$(CC) $(CFLAGS) $(LDFLAGS)'
	cd $(CURDIR)/gettext_xs && perl Makefile.PL INSTALLDIRS=vendor OPTIMIZE='$(CFLAGS) $(CPPFLAGS)' LD='$(CC) $(CFLAGS) $(LDFLAGS)'
	$(MAKE) LD_RUN_PATH=""
	$(MAKE) -C $(CURDIR)/gettext_xs
	dh_auto_test
	touch $@

clean:
	dh_testdir
	dh_testroot
	[ ! -f Makefile ] || $(MAKE) realclean
	[ ! -f Makefile ] || $(MAKE) -C $(CURDIR)/gettext_xs realclean
	rm -f xs_disabled
	dh_clean build-stamp config.log

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	$(MAKE) install DESTDIR=$(TMP) PREFIX=/usr
	$(MAKE) -C $(CURDIR)/gettext_xs install DESTDIR=$(TMP) PREFIX=/usr

binary-indep: install
	dh_testdir
	dh_testroot
	dh_install -i --exclude=xs
	dh $@

binary-arch: install
	dh $@

binary: binary-indep binary-arch

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