#!/usr/bin/make -f

export V=1

ORIG_VERSION := $(shell dpkg-parsechangelog -S version)
VERSION_SUFFIX := $(shell lsb_release -c -s)
# Set the current "testing" explicitly to "buster"
ifeq ($(VERSION_SUFFIX),testing)
	VERSION_SUFFIX := buster
endif
PACKAGEVERSION := "$(ORIG_VERSION)-$(VERSION_SUFFIX)"

CONFIG := --prefix=${TARGET_DIR} \
	--target-os=linux \
	--extra-version=Jellyfin \
	--disable-doc \
	--disable-ffplay \
	--disable-shared \
	--disable-libxcb \
	--disable-sdl2 \
	--disable-xlib \
	--enable-gpl \
	--enable-version3 \
	--enable-static \
	--enable-gmp \
	--enable-gnutls \
	--enable-libdrm \
	--enable-libass \
	--enable-libfreetype \
	--enable-libfribidi \
	--enable-libfontconfig \
	--enable-libbluray \
	--enable-libmp3lame \
	--enable-libopus \
	--enable-libtheora \
	--enable-libvorbis \
	--enable-libdav1d \
	--enable-libwebp \
	--enable-libvpx \
	--enable-libx264 \
	--enable-libx265 \
	--enable-libzvbi \
	--enable-libzimg \

CONFIG_ARM_COMMON := --toolchain=hardened \
	--enable-cross-compile \
	--enable-omx \
	--enable-omx-rpi \

CONFIG_ARM := ${CONFIG_ARM_COMMON} \
	--enable-mmal \
	--arch=armhf \
	--cross-prefix=/usr/bin/arm-linux-gnueabihf- \

CONFIG_ARM64 := ${CONFIG_ARM_COMMON} \
	--arch=arm64 \
	--cross-prefix=/usr/bin/aarch64-linux-gnu- \

CONFIG_x86 := --arch=amd64 \
	--enable-opencl \
	--enable-vaapi \
	--enable-amf \
	--enable-libmfx \
	--enable-vdpau \
	--enable-ffnvcodec \
	--enable-cuda \
	--enable-cuda-llvm \
	--enable-cuvid \
	--enable-nvdec \
	--enable-nvenc \

HOST_ARCH := $(shell arch)
BUILD_ARCH := ${DEB_HOST_MULTIARCH}
ifeq ($(BUILD_ARCH),x86_64-linux-gnu)
	# Native amd64 build
	CONFIG += $(CONFIG_x86)
endif
ifeq ($(BUILD_ARCH),arm-linux-gnueabihf)
	# Cross-building ARM on AMD64
	CONFIG += $(CONFIG_ARM)
endif
ifeq ($(BUILD_ARCH),aarch64-linux-gnu)
	# Cross-building ARM64 on AMD64
	CONFIG += $(CONFIG_ARM64)
endif

%:
	dh $@

override_dh_gencontrol:
	dh_gencontrol -- -v$(PACKAGEVERSION)

override_dh_auto_configure:
	./configure $(CONFIG)

override_dh_shlibdeps:
	dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info

override_dh_auto_clean:
	dh_auto_clean || true

override_dh_auto_install:
	make -j1 install-data DESTDIR=/srv/build/ffmpeg/jellyfin-ffmpeg/debian/jellyfin-ffmpeg AM_UPDATE_INFO_DIR=no 

override_dh_usrlocal:

override_dh_auto_test:

override_dh_installman:
