#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-

CONFIGURE_FLAGS =
DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)

ifeq ($(DEB_HOST_ARCH_OS),linux)
CONFIGURE_FLAGS += --with-jack --with-alsa --with-oss
STK_REALTIME = yes
else
CONFIGURE_FLAGS += --disable-realtime
STK_REALTIME =no
endif

export STK_REALTIME

RAWWAVE_PATH = /usr/share/stk/rawwaves/

CONFIGURE_FLAGS += RAWWAVE_PATH=$(RAWWAVE_PATH)

MOVE_FILES = include/RtAudio.h include/RtMidi.h include/RtError.h \
	       projects/examples/libMakefile

move_file = [ ! -f $(1) ] || mv $(1) $(2)

%:
	dh $@ --with autotools_dev --parallel

override_dh_auto_configure:
	for file in $(MOVE_FILES); do \
		$(call move_file , $${file}, $${file}.bak); \
	done
	dh_auto_configure -- $(CONFIGURE_FLAGS)
	mkdir -p src/Release
	mkdir -p projects/demo/Release

override_dh_auto_install:
	dh_auto_install
	rm -f debian/tmp/usr/include/stk/*.bak

override_dh_link:
	dh_link
# Cleanup realtime-related files
ifeq ($(STK_REALTIME),no)
	rm -rf debian/stk/usr/share/menu
	rm -rf debian/stk/usr/share/man
endif

override_dh_installchangelogs:
	dh_installchangelogs doc/ReleaseNotes.txt

override_dh_auto_clean:
	dh_auto_clean
	for file in $(MOVE_FILES); do \
		$(call move_file, $${file}.bak, $${file}); \
	done

