#!/usr/bin/make -f
# Ron Lee 2003 - 2012

#export DH_VERBOSE=1
export DH_OPTIONS

SHELL = /bin/bash

NUM_CPUS = $(shell getconf _NPROCESSORS_ONLN 2>/dev/null)
PARALLEL = $(subst parallel=,,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
NJOBS    = -j$(or $(PARALLEL),$(NUM_CPUS),1)


ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

PKG_CONFIG_PATH=/opt/kxstudio/lib/pkgconfig
export PKG_CONFIG_PATH


objdir := objs


clean:
	dh_testdir
	dh_testroot
	$(RM) *-stamp
	$(RM) -r $(objdir)
	dh_clean


$(objdir)/config.status: configure
	dh_testdir
	mkdir -p $(objdir)
	cd $(objdir) &&	../configure --host=$(DEB_HOST_GNU_TYPE)	\
				     --build=$(DEB_BUILD_GNU_TYPE)	\
				     --prefix=/usr CFLAGS="-fPIC"

build: build-arch
build-arch: build-arch-stamp
build-indep:

build-arch-stamp: $(objdir)/config.status
	dh_testdir
	$(MAKE) $(NJOBS) -C $(objdir)
	touch $@


binary: binary-arch

binary-indep:

binary-arch: DH_OPTIONS = -a
binary-arch: build-arch
	dh_testdir
	dh_testroot
	dh_install $(objdir)/{opusdec,opusenc,opusinfo} usr/bin
	dh_installman man/{opusdec,opusenc,opusinfo}.1
	dh_installdocs
	dh_installchangelogs
	dh_strip --dbg-package=opus-tools-dbg
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb


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