#!/usr/bin/make -f

# nostrip option implies noopt
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
   TYPE=RelWithDebInfo
else
   TYPE=Debug
endif

# Use this variable to allow options passed to cmake to be overridable
DEB_CMAKE_OPTIONS ?= -DCMAKE_VERBOSE_MAKEFILE=ON \
		-DCMAKE_BUILD_TYPE=$(TYPE) \
		-DCMAKE_INSTALL_PREFIX="/usr" \
		-DCMAKE_C_FLAGS="$(DEB_CFLAGS)" \
		-DALSOFT_CONFIG=ON \
		..

BUILD_TREE=$(CURDIR)/build-tree

.PHONY: build
%:
	dh $@

build:
	dh $@

override_dh_auto_clean:
	rm -rf $(BUILD_TREE)

override_dh_auto_configure:
	mkdir -p $(BUILD_TREE)
	cd $(BUILD_TREE) && \
		cmake $(DEB_CMAKE_OPTIONS)

override_dh_auto_build:
	$(MAKE) --directory=$(BUILD_TREE)

override_dh_auto_install:
	$(MAKE) --directory=$(BUILD_TREE) install DESTDIR=$(CURDIR)/debian/tmp

override_dh_strip:
	dh_strip --dbg-package=libopenal1-dbg

override_dh_gencontrol:
	dh_gencontrol
	sed "s/^Depends:.*$$/&\nRecommends: $$(sh debian/var_info LIBPULSE_DEPENDS)/" \
		-i "debian/libopenal1/DEBIAN/control"
	sed "s/^Recommends:.*$$/&\nSuggests: $$(sh debian/var_info LIBPORTAUDIO_DEPENDS)/" \
		-i "debian/libopenal1/DEBIAN/control"

get-orig-source:
	$(dir $_)openal-soft-get-orig-source
