#!/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

VIDEOABI = $(shell cat /usr/share/xserver-xorg/videodrvdep | sed -r s/.*xorg-video-abi-\([0-9]*\).*/\\1/ 2>/dev/null)

#This is where we extract all the bits from upstream tarballs
EXTRACTDIR=upstream
D=$(EXTRACTDIR)/usr/lib/xorg/modules

#Tarball containing the X11 driver built against the required X11 ABI version
XTARBALL=tegra-drivers-abi$(VIDEOABI).tbz2

#Tarball containing the rest of libraries, firmware and config files from the NVidia L4T SDK
FSTARBALL=tegra_bins.tar.gz

%:
	dh $@

override_dh_auto_configure:
	mkdir -p $(EXTRACTDIR)
	tar -C $(EXTRACTDIR) -xjf $(XTARBALL)
	tar -C $(EXTRACTDIR) -xzf $(FSTARBALL)
	#Move tegra_drv.so to another path
	mv $(D)/drivers/tegra_drv.so $(EXTRACTDIR)/usr/lib/xorg/
	rm -Rf $(D)
	find $((EXTRACTDIR) -name *.so* | xargs -n1 execstack -c || true
	echo "/usr/lib/nvidia-tegra" > $(EXTRACTDIR)/usr/lib/ld.so.conf

override_dh_auto_clean:
	rm -Rf $(EXTRACTDIR)

override_dh_strip:
	dh_strip --exclude=tegra_drv.so
