#!/usr/bin/make -f
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
export DEB_HOST_MULTIARCH
DEB_DEBIAN_DIR=$(dir $(firstword $(MAKEFILE_LIST)))
VER=$(shell dpkg-parsechangelog -l$(DEB_DEBIAN_DIR)/changelog \
              | sed -rne 's,^Version: ([^-]+).*,\1,p')
GITREV=$(shell echo $(VER) | sed -rne 's,([0-9]).([0-9]).([0-9]),release_00\1_00\2_00\3,p')

%:
	dh $@ --parallel --sourcedirectory=host --builddirectory=build

override_dh_acc:
	- dh_acc $@
	- cat logs/libuhd-dev/*/log.txt

override_dh_auto_configure:
	dh_auto_configure -- -DLIB_SUFFIX="/$(DEB_HOST_MULTIARCH)" \
	                      -DPKG_LIB_DIR="/usr/lib/uhd" -DDOXYGEN_HAVE_DOT=True

# The test suite for this package is busted on powerpc.
override_dh_auto_test:
	- if [ $(DEB_BUILD_ARCH) != powerpc ]; then dh_auto_test; fi

override_dh_auto_install:
	cp debian/uhd-host.limits debian/uhd-host/etc/security/limits.d/uhd.conf
	cp debian/uhd-host.sysctl debian/uhd-host/etc/sysctl.d/uhd-usrp2.conf
	dh_auto_install
	- rm -f debian/tmp/usr/share/doc/uhd/doxygen/html/jquery.js
	ln -s /usr/share/javascript/jquery/jquery.js debian/tmp/usr/share/doc/uhd/doxygen/html/jquery.js

override_dh_makeshlibs:
	dh_makeshlibs -V 'libuhd003 (>= 3.9.5)'

get-orig-source:
	git clone git://github.com/EttusResearch/uhd.git
	cd uhd && git submodule init
	cd uhd && git submodule update
	cd uhd && git archive --format=tar --prefix=uhd-$(VER)/  $(GITREV) | xz > ../../uhd_$(VER).orig.tar.xz
	cd uhd && git checkout $(GITREV)
	cd uhd && rm -rf fpga-src/.git fpga-src/.gitignore
	cd uhd && tar cf - fpga-src | xz > ../../uhd_$(VER).orig-fpga-src.tar.xz
	rm -rf uhd
