#!/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 := --toolchain=hardened \
	--prefix=/usr \
	--target-os=linux \
	--enable-cross-compile \
	--extra-cflags='--static' \
	--enable-gpl \
	--enable-static \
    --disable-doc \
	--disable-ffplay \
	--disable-shared \
	--disable-libxcb \
	--disable-sdl2 \
	--disable-xlib \
	--enable-fontconfig \
	--enable-gmp \
	--enable-gnutls \
	--enable-libass \
	--enable-libbluray \
	--enable-libdrm \
	--enable-libfreetype \
	--enable-libfribidi \
	--enable-libmp3lame \
	--enable-libopus \
	--enable-libtheora \
	--enable-libvorbis \
	--enable-libwebp \
	--enable-libx264 \
	--enable-libx265 \
	--enable-libzvbi \
	--enable-omx \
	--enable-omx-rpi \
	--enable-version3 \
	--enable-vaapi \
	--enable-vdpau \

CONFIG_ARM := --enable-cross-compile \
	--cross-prefix=/usr/bin/arm-linux-gnueabihf- \
	--arch=armhf

CONFIG_x86 := --arch=amd64 \
    --enable-nvenc --enable-nvdec

HOST_ARCH := $(shell arch)
BUILD_ARCH := ${DEB_HOST_MULTIARCH}
ifeq ($(HOST_ARCH),x86_64)
	ifeq ($(BUILD_ARCH),arm-linux-gnueabihf)
		# Cross-building ARM on AMD64
		CONFIG += $(CONFIG_ARM)
	else
		# Building AMD64
		CONFIG += $(CONFIG_x86)
	endif
endif
ifeq ($(HOST_ARCH),armv7l)
	# Building ARM
	CONFIG += $(CONFIG_ARM)
endif

%:
	dh $@

override_dh_gencontrol:
	dh_gencontrol -- -v$(PACKAGEVERSION)

override_dh_auto_configure:
	./configure $(CONFIG)

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:
