#!/usr/bin/make -f

# 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)

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CXXFLAGS += -g -O3 -Wall
else
	CXXFLAGS += -g -Wall
endif

export DEB_BUILD_OPTIONS

build: build-stamp
build-stamp:
	dh_testdir debian/rules audio sidplay.cpp
# well, ./configure isn't interactive here and doesn't take long, so it's
# carried out in order to assist building the package for people with other
# architectures and compiler environments
	CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" ./configure --prefix=/usr --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE)
# Compile sidplay
	$(MAKE)
	touch build-stamp

clean:
	dh_testroot
	dh_testdir debian/rules audio sidplay.cpp
	-rm -f build-stamp
	[ ! -f Makefile ] || $(MAKE) distclean
	dh_clean

maintainerclean: clean
	aclocal -I .
	automake
	autoconf

# Build architecture-independent files here.
binary-indep: build
# Nothing to do here.

# Build architecture-dependent files here.
binary-arch: build
	dh_testroot
	dh_testdir debian/rules audio sidplay.cpp
	dh_clean -k
	dh_installdirs
# Installation
	$(MAKE) prefix=$(CURDIR)/debian/tmp/usr install
	dh_install --list-missing --sourcedir=debian/tmp
	dh_installdocs
	dh_installman debian/sidcon.1 debian/sidplay.1 debian/sid2wav.1
	dh_installchangelogs
	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

# vim:tw=0

