#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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

SHELL = /bin/bash

PF = -b16

SDK_VIV  = imx-gpu-sdk
SRCDIR   = $(CURDIR)
DESTDIR  = $(CURDIR)/install
AARCH64  = aarch64-linux-gnu

DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)


%:
	dh $@ --with python2


# Default to a release build
config = Release


ifneq ($(DEB_HOST_ARCH),$(DEB_BUILD_ARCH))
#
export CC=$(DEB_HOST_MULTIARCH)-gcc
export CXX=$(DEB_HOST_MULTIARCH)-g++
export AR=$(DEB_HOST_MULTIARCH)-ar
SYSROOT = /wssd/sysroots/bionic-wl/arm64
else
#
export CC=/usr/lib/distcc/bin/gcc-7
export CXX=/usr/lib/distcc/bin/g++-7
export AR=ar
#
endif

override_dh_auto_build:
ifeq ($(DEB_HOST_ARCH),$(DEB_BUILD_ARCH))
	@sudo apt-get -y install imx-wl-default$(PF)
	@$(MAKE) -C "$(SRCDIR)" all
else
	@( SYSROOT="$(SYSROOT)" $(MAKE) -C "$(SRCDIR)" all )
endif


override_dh_auto_install:
	@( DESTDIR="$(DESTDIR)" $(MAKE) -C "$(SRCDIR)" install )


override_dh_builddeb:
	dh_builddeb -- -Zxz --compress-program=pixz
#	dh_builddeb -- -Zxz


override_dh_shlibdeps:
	#
ifneq ($(DEB_HOST_ARCH),$(DEB_BUILD_ARCH))
	(cd debian && cat shlibs-comm  > shlibs.local && cat shlibs-wl >> shlibs.local)
endif
	dh_shlibdeps -l$(SYSROOT)/usr/lib/$(AARCH64)/vivante:$(SYSROOT)/usr/lib/$(AARCH64):$(SYSROOT)/lib/$(AARCH64):$(SYSROOT)/usr/lib -- --warnings=0

