#!/usr/bin/make -f
# $MirOS: contrib/hosted/tg/deb/libbsd-arc4random-perl/debian/rules,v 1.15 2012/01/28 17:10:57 tg Exp $

EXTRA_CFLAGS=		-Wall -Wextra -Wformat -Wno-unused-variable
#ifeq (,$(wildcard /usr/share/dpkg/buildflags.mk))
CFLAGS=			-O$(if $(findstring noopt,${DEB_BUILD_OPTIONS}),0,2) -g
CFLAGS+=		${EXTRA_CFLAGS}
# We cannot use dpkg-buildflags because Makefile.PL only
# honours OPTIMIZE for .c.o compilation, not for linking,
# and while CPPFLAGS can be added to it, there is no pro-
# vision for LDFLAGS _at all_!
#else
#DEB_CFLAGS_MAINT_APPEND=${EXTRA_CFLAGS}
#DEB_BUILD_MAINT_OPTIONS=hardening=+all
#DPKG_EXPORT_BUILDFLAGS=	Yes
#include /usr/share/dpkg/buildflags.mk
#endif

build build-arch: builddir/.build-stamp
build-indep:

builddir/.build-stamp:
	dh_testdir
	-rm -rf builddir
	mkdir builddir
	tar -cf - $$(cat MANIFEST) | (cd builddir; tar -xf -)
	cd builddir && exec perl Makefile.PL verbose INSTALLDIRS=vendor
	cd builddir && exec ${MAKE} OPTIMIZE='${CFLAGS}'
ifeq (,$(filter nocheck,${DEB_BUILD_OPTIONS}))
	cd builddir && exec ${MAKE} test
endif
	@:>$@

clean:
	dh_testdir
	dh_testroot
	-rm -rf builddir
	dh_clean

binary: binary-indep binary-arch
binary-indep:

binary-arch: builddir/.build-stamp
	dh_testdir
	dh_testroot
	if test -x "$$(which dh_prep)"; then dh_prep; else dh_clean -k; fi
	cd builddir && exec ${MAKE} install \
	    DESTDIR=${CURDIR}/debian/libbsd-arc4random-perl
	dh_installchangelogs
	dh_installdocs README TODO
	dh_install
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_perl
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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