#!/usr/bin/make -f
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
export DEB_HOST_MULTIARCH
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

ifneq (,$(filter $(DEB_HOST_ARCH), armel mipsel m68k powerpc sh4))
  export DEB_LDFLAGS_MAINT_APPEND += -Wl,--no-as-needed -latomic -Wl,--as-needed
endif

%:
	dh $@ --with python3 --with numpy3 --buildsystem=cmake+ninja

override_dh_auto_configure:
	dh_auto_configure -- -DCMAKE_BUILD_TYPE=Release -DLIB_SUFFIX="/$(DEB_HOST_MULTIARCH)" -DENABLE_SYSTEM_DESKTOP=ON -DENABLE_DOXYGEN_PDF=ON

override_dh_python3:
	dh_python3 --no-ext-rename

override_dh_auto_install:
	rm -rf debian/tmp/usr/share/doc/gnuradio-doc/xml/License.xml.gz
	dh_auto_install
	rm -f debian/tmp/usr/lib/py*/site-packages/gnuradio/ctrlport/GNURadio/*remotec
	rm -f debian/tmp/usr/lib/py*/site-packages/gnuradio/ctrlport/GNURadio/*remoteo
	rm -f  debian/gnuradio/usr/share/doc/gnuradio/html/*md5
	rm -f  debian/gnuradio-doc/usr/share/doc/gnuradio-doc/html/*md5
	if [ -f debian/tmp/usr/share/doc/gnuradio*/config/thrift.conf.example ] ; then \
	 install -d debian/gnuradio/usr/share/doc/gnuradio/config &&\
	 mv debian/tmp/usr/share/doc/gnuradio*/config/* debian/gnuradio/usr/share/doc/gnuradio/config/ ; fi

#	- if case "$(DEB_BUILD_ARCH)" in *"i386"*) false;; *"hppa"*) false;; *) true;; esac; then ARGS='--timeout 10' HOME=$(CURDIR)/debian/test xvfb-run dh_auto_test ; fi
override_dh_auto_test:
	mkdir debian/test
	mkdir debian/test/.gnuradio
	- ARGS='--timeout 600' HOME=$(CURDIR)/debian/test QT_QPA_PLATFORM=offscreen dh_auto_test
	rm -rf debian/test

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

override_dh_installmime:
	dh_installmime
	rm -f debian/gnuradio/usr/share/mime/packages/gnuradio.xml

override_dh_gencontrol:
	dh_gencontrol -- -Vboost-version=`dpkg-query -W -f='$${Depends}' libboost-date-time-dev| cut -b19- |cut -b-4`

override_dh_auto_clean:
	rm -rf docs/doxygen/doxyxml/__pycache__
	rm -rf docs/doxygen/doxyxml/generated/__pycache__
	dh_auto_clean $@
