#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# This has to be exported to make some magic below work.
export DH_OPTIONS

CFLAGS=$(shell dpkg-buildflags --get CFLAGS) $(shell dpkg-buildflags --get CPPFLAGS)
LDFLAGS=$(shell dpkg-buildflags --get LDFLAGS)
CFLAGS+=$(HARDENING_CFLAGS)
LDFLAGS+=$(HARDENING_LDFLAGS)

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp:
	dh build
	touch $@

clean:
	dh $@

install: install-stamp
install-stamp: build-stamp
	dh install
	touch $@

binary-arch: install
	dh $@

binary: binary-arch binary-indep

override_dh_auto_clean:
	-(cd NKF.mod && \
	test -f Makefile && perl Makefile.PL)
	-rm -f NKF.mod/Makefile.old
	make clean

override_dh_auto_configure:
	(cd NKF.mod && \
	/usr/bin/perl Makefile.PL INSTALLDIRS=vendor OPTIMIZE="$(CFLAGS)" LD="cc $(LDFLAGS)")

override_dh_auto_build:
	make nkf CC=cc CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)"
	(cd NKF.mod && make)

override_dh_auto_test:
	make test
	make -C NKF.mod test

override_dh_auto_install:
	install -s -m 755 nkf debian/nkf/usr/bin
	./debian/nkf/usr/bin/nkf -e nkf.1j > debian/nkf.1j.tmp
	install -m 444 debian/nkf.1j.tmp debian/nkf/usr/share/man/ja/man1/nkf.1
	rm -f debian/nkf.1j.tmp
	install -m 444 nkf.1 debian/nkf/usr/share/man/man1/nkf.1
	(cd NKF.mod; make install DESTDIR=$(CURDIR)/debian/libnkf-perl/)

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