#!/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

CFLAGS = -Wall -g
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
        CFLAGS += -O0
else
        CFLAGS += -O2
endif

build: build-stamp
build-stamp:
	dh_testdir
	perl Makefile.PL INSTALLDIRS=vendor
	(cd $(CURDIR)/gettext_xs && perl Makefile.PL INSTALLDIRS=vendor)
	$(MAKE) OPTIMIZE="$(CLFAGS)" LD_RUN_PATH=""
	$(MAKE) -C $(CURDIR)/gettext_xs OPTIMIZE="$(CLFAGS)"
	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 clean binary-indep binary-arch binary
