#!/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_CODC := imx-codec

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

GCC_VER = 11

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

##

IMX_CODC_CONFIG_OPTS = $(CONFIG_OPTS) --enable-vpu --enable-armv8


%:
	dh $@

override_dh_auto_configure:
	# imx-codec
	@$(call message,"configuring imx-codec for release...",0,$(COLOR_CYAN),$(MSG_INVERSE))
	./autogen.sh $(IMX_CODC_CONFIG_OPTS)


override_dh_auto_install:
	dh_auto_install -v --buildsystem=makefile -pimx-codec    --destdir=$(IMX_CODC).release
	mv $(IMX_CODC).release/usr/lib/$(DEB_HOST_GNU_TYPE)/imx-mm/audio-codec/*.*  $(IMX_CODC).release/usr/lib/$(DEB_HOST_GNU_TYPE)
	rm -rf $(IMX_CODC).release/usr/lib/$(DEB_HOST_GNU_TYPE)/imx-mm/video-codec


override_dh_shlibdeps:
	dh_shlibdeps -pimx-codec   -X/share/imx-mm -X/lib/$(DEB_HOST_GNU_TYPE)/imx-mm/


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

