#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

UPSTREAM_VERSION := $(shell echo $(DEB_VERSION) | sed -r 's/[^:]+://; s/-[^-]+$$//')

ifneq "$(DEB_BUILD_ARCH)" "amd64"
	confflags += -DENABLE_AJA=FALSE
endif
ifeq (,$(filter-out amd64,$(DEB_HOST_ARCH_CPU)))
	confflags += -DENABLE_QSV11=ON
else
	confflags += -DENABLE_QSV11=OFF
endif

%:
	dh $@ -Scmake+ninja --with quilt

override_dh_auto_configure:

# from https://github.com/obsproject/obs-studio/tree/master/plugins
#
# git clone https://github.com/obsproject/obs-websocket.git
# cd obs-websocket && git checkout 1c9306b
# git submodule update --init --recursive
# rm -rf .git* && cd ..
# mv obs-websocket obs-websocket-5-6-3
	cd plugins && ln -s ../obs-websocket-5-6-3 obs-websocket

	dh_auto_configure -- \
	-DAPPDATA_RELEASE_DATE=$(shell date --utc --date=@$${SOURCE_DATE_EPOCH} +'%Y-%m-%d') \
	-DCMAKE_BUILD_TYPE=RelWithDebInfo \
	-DCMAKE_COMPILE_WARNING_AS_ERROR=OFF \
	-DCMAKE_SKIP_RPATH=ON \
	-DCPACK_RESOURCE_FILE_LICENSE=/usr/share/common-licenses/GPL-2 \
	-DENABLE_BROWSER=OFF \
	-DENABLE_JACK=ON \
	-DENABLE_LIBFDK=ON \
	-DENABLE_SNDIO=OFF \
	-DENABLE_VLC=ON \
	-DOBS_INSTALL_PREFIX=/usr \
	-DOBS_LIBRARY_DESTINATION=lib/$(DEB_HOST_MULTIARCH) \
	-DOBS_VERSION_OVERRIDE=$(UPSTREAM_VERSION) \
	-Wno-dev \
	$(confflags)

#	exit 1

override_dh_auto_build:
	dh_auto_build

	rst2man debian/obs.rst > debian/obs.1

override_dh_install:
	rm debian/tmp/usr/share/obs/obs-plugins/decklink-captions/.keepme

	dh_install

	rm -rf debian/obs-studio/usr/share/obs/obs-studio/license

execute_after_dh_auto_install:
	chmod 644 debian/tmp/usr/share/obs/obs-studio/OBSPublicRSAKey.pem

override_dh_python3:
	dh_python3 -pobs-plugins usr/share/obs/obs-plugins/frontend-tools/scripts
	dh_python3 -pobs-plugins usr/lib/$(DEB_HOST_MULTIARCH)/obs-scripting

override_dh_clean:
	dh_clean debian/obs.1 cmake/.CMakeBuildNumber \
	obs-websocket-*/src/plugin-macros.generated.h

	-rm -rf plugins/obs-websocket

override_dh_auto_test:
