#!/usr/bin/make -f
# debian/rules for cuetools
# (C) 2003 Joshua Kwan <joshk@triplehelix.org>

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

CFLAGS = -Wall -W -g

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

ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
crossflags := --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE)
endif

configure: configure-stamp
configure-stamp:
	./configure $(crossflags) --prefix=/usr --mandir=/usr/share/man
	>$@

build: build-stamp
build-stamp: configure-stamp
	dh_testdir
	$(MAKE)
	>$@

clean:
	dh_testdir
	dh_testroot
	[ ! -f Makefile ] || $(MAKE) distclean
	rm -f build-stamp configure-stamp
	dh_clean

install: build-stamp
	dh_testdir
	dh_testroot
	dh_clean -k
	$(MAKE) install DESTDIR=$(CURDIR)/debian/cuetools
	install -m 755 -o 0 -g 0 extras/cuetag.sh $(CURDIR)/debian/cuetools/usr/bin/cuetag

binary-indep:

binary-arch: build-stamp install
	dh_testdir
	dh_testroot
	dh_strip
	dh_installman
	dh_installchangelogs NEWS
	dh_installdocs README
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

get-orig-source:
	@@dh_testdir
	@@[ -d ../tarballs/. ]||mkdir -p ../tarballs
	@@uscan --force-download --destdir ../tarballs

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