#!/usr/bin/make -f
# -*- makefile -*- -*- indent-tabs-mode: t; tab-width: 3 -*-

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

#usage: $(call message,<text>,<tabs>,<color>,<inverse>)
#message colors
COLOR_BLACK=30
COLOR_RED=31
COLOR_GREEN=32
COLOR_YELLOW=33
COLOR_BLUE=34
COLOR_MAGENTA=35
COLOR_CYAN=36
COLOR_WHITE=97
COLOR_DEFAULT=39
MSG_INVERSE=1
MSG_NONINVERSE=0

define message
	( if [ -z $(NOCOLOR) ] ; then echo -ne "\e[$(3)m" ; fi ; \
	if [ "$(4)" = "$(MSG_INVERSE)" ] ; then if [ -z $(NOCOLOR) ] ; then echo -ne "\e[7m" ; fi ; echo -n ">>>" ; fi ; \
	if [ "$(2)" -gt 0 ] && [ "$(2)" -lt 10 ] ; then for a in `seq "$(2)"` ; do echo -n "   " ; done ; fi ; \
	echo -n " $(1) " ; \
	if [ "$(4)" = "$(MSG_INVERSE)" ] ; then echo -n "<<<" ; if [ -z $(NOCOLOR) ] ; then echo -ne "\e[27m" ; fi ; fi ; \
	echo ; \
	if [ -z $(NOCOLOR) ] ; then echo -ne "\e[39m" ; fi ; \
	)
endef

##########################

DEB_HOST_GNU_CPU  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_CPU)
DEB_HOST_ARCH     ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
DEB_HOST_GNU_TYPE  = $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE = $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
SHELL = /bin/bash

IMX_GST1.0_PLUG := imx-gst1.0-plugin

CONFIG_OPTS = --prefix=/usr --libdir=/usr/lib/$(DEB_HOST_GNU_TYPE) --build $(DEB_BUILD_GNU_TYPE)

GCC_VER = 9

ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
CONFIG_OPTS += --host $(DEB_HOST_GNU_TYPE)
else
export CC=/usr/lib/distcc/bin/gcc-$(GCC_VER)
export CXX=/usr/lib/distcc/bin/g++-$(GCC_VER)
endif


PLATFORM := MX8

IMX_GST1.0_PLUG_CONFIG_OPTS = $(CONFIG_OPTS) \
	PLATFORM=$(PLATFORM) \
	--disable-wma8enc \
	--disable-overlaysink \
	CPPFLAGS="-I${STAGING_KERNEL_DIR}/include/uapi \
		  -I${STAGING_KERNEL_DIR}/include \
		  -I${STAGING_KERNEL_DIR}/include/generated/uapi \
		  -I${STAGING_KERNEL_DIR}/drivers/staging/android/uapi \
		  -I/usr/include/hantro_dec"

#ifeq ($(USE_XWAYLAND),)
IMX_GST1.0_PLUG_CONFIG_OPTS += --disable-x11
#else
#IMX_GST1.0_PLUG_CONFIG_OPTS += --enable-x11
#endif

##

%:
	dh $@

override_dh_auto_configure:
	@$(call message,"configuring imx-gst1.0-plugin...",0,$(COLOR_CYAN),$(MSG_INVERSE))
	./autogen.sh $(IMX_GST1.0_PLUG_CONFIG_OPTS)


override_dh_auto_install:
	dh_auto_install -v --buildsystem=makefile -pimx-gst1.0-plugin  --destdir=$(IMX_GST1.0_PLUG).release


override_dh_shlibdeps:
	dh_shlibdeps -pimx-gst1.0-plugin -l/usr/lib/$(DEB_HOST_GNU_TYPE)/imx-mm/audio-codec


override_dh_strip:
	dh_strip -a --no-automatic-dbgsym

