#!/usr/bin/make -f

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

DEB_HOST_GNU_SYSTEM := $(shell dpkg-architecture -qDEB_HOST_GNU_SYSTEM)

ifeq ($(DEB_HOST_GNU_SYSTEM), linux-gnu)
	target = linux
else
	target = generic
endif

CFLAGS = -Wall -g -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -pipe -fomit-frame-pointer
	ifeq ($(target), generic)
		CFLAGS += -O6
	else
		CFLAGS += -O9 -finline-functions -funroll-loops -fstrength-reduce
	endif
endif

build: build-stamp
build-stamp:
	dh_testdir

	# Building package
	$(MAKE) $(target) CFLAGS="$(CFLAGS)"

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	# Cleaning package
	-$(MAKE) clean
	-$(MAKE) distclean

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Installing package
	$(MAKE) DESTDIR=$(CURDIR)/debian/wipe install

binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs CHANGES
	dh_installdocs
	dh_installexamples
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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