#!/usr/bin/make -f
# debian/rules for flac

include /usr/share/dpatch/dpatch.make

top_srcdir:=$(shell pwd)
tmp:=debian/tmp
tmp_absolute:=$(top_srcdir)/$(tmp)

CFLAGS=-g

ifeq "$(findstring debug,$(DEB_BUILD_OPTIONS))" ""
CFLAGS += -O2
else
CFLAGS += -O0
endif

DEB_HOST_ARCH=$(shell dpkg-architecture -qDEB_HOST_ARCH)

ifeq ($(DEB_HOST_ARCH),powerpc)
EXTRA_CONFIGURE_ARGS:=--disable-asm-optimizations
else
ifeq ($(DEB_HOST_ARCH),m68k)
CFLAGS += -fno-inline-functions
else
EXTRA_CONFIGURE_ARGS=
endif
endif

configure: configure-stamp
configure-stamp:
	dh_testdir

	CFLAGS="$(CFLAGS)" CXXFLAGS="$(CFLAGS)" ./configure --prefix=/usr \
		--mandir=/usr/share/man $(EXTRA_CONFIGURE_ARGS)
	touch $@

build: patch configure-stamp build-stamp
build-stamp:
	dh_testdir

	touch man/flac.1
	# Add here commands to compile the package.
	$(MAKE)

	touch $@

clean: unpatch
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	# Add here commands to clean up after the build process.
	-$(MAKE) distclean

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	$(MAKE) DESTDIR=$(tmp_absolute) install

	dh_install --sourcedir=$(tmp)

	mv debian/libflac-doc/usr/share/doc/flac-1.1.2 \
		debian/libflac-doc/usr/share/doc/libflac-doc

binary-indep: build install
	dh_testdir -i
	dh_testroot -i
	dh_installdocs -i
	dh_installchangelogs -i
	dh_compress -i -X.html
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdebconf -a
	dh_installchangelogs -a
	dh_installdocs -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_makeshlibs -a -Xxmms-flac
	dh_link -a
	dh_installdeb -a
	dh_shlibdeps -a -ldebian/libflac7/usr/lib:debian/libflac++5/usr/lib
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

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