#!/usr/bin/make -f

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

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

ifeq "$(DEB_BUILD_ARCH)" "arm64"
	confflags += -DENABLE_AJA=FALSE
endif

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

override_dh_auto_configure:
# git clone https://github.com/obsproject/obs-amd-encoder.git
# git checkout 8823c23
	ln -s ../obs-amd-encoder-2023-03-27-8823c23 plugins/enc-amf
# git clone https://github.com/obsproject/obs-websocket.git
# git checkout 57a9c19
# git submodule update --init --recursive
	ln -s ../obs-websocket-2023-05-02-57a9c19 plugins/obs-websocket

	dh_auto_configure -- \
	-DCMAKE_BUILD_TYPE=RelWithDebInfo \
	-DCPACK_RESOURCE_FILE_LICENSE=/usr/share/common-licenses/GPL-2 \
	-DDISABLE_UPDATE_MODULE=TRUE \
	-DENABLE_BROWSER=OFF \
	-DENABLE_JACK=TRUE \
	-DENABLE_LIBFDK=TRUE \
	-DENABLE_SNDIO=OFF \
	-DQT_VERSION=5 \
	-DISABLE_UPDATE_MODULE=TRUE \
	-DOBS_LIBRARY_DESTINATION=lib/$(DEB_HOST_MULTIARCH) \
	-DOBS_MULTIARCH_SUFFIX=/$(DEB_HOST_MULTIARCH) \
	-DOBS_VERSION_OVERRIDE=$(UPSTREAM_VERSION) \
	-DAPPDATA_RELEASE_DATE=$(shell date --utc --date=@$${SOURCE_DATE_EPOCH} +'%Y-%m-%d') \
	-DUNIX_STRUCTURE=TRUE \
	$(confflags) \
	-Wno-dev

#	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
	-rm -rf plugins/enc-amf

override_dh_auto_test:
