#!/usr/bin/make -f

# Override with "debuild -eQT_VERSION=6 ..." to build the Qt6 package.
QT_VERSION ?= 5

ifeq ($(QT_VERSION),5)
QT_CMAKE_OPTION := -DENABLE_QT6=OFF
QT_RUNTIME_DEPENDS := libqt5multimedia5-plugins, qtspeech5-speechd-plugin, qml-module-qtlocation, qml-module-qtpositioning, qml-module-qtquick-window2, qml-module-qtquick-dialogs, qml-module-qtquick-controls, qml-module-qtquick-controls2, qml-module-qtquick-layouts, qml-module-qtgraphicaleffects
else ifeq ($(QT_VERSION),6)
QT_CMAKE_OPTION := -DENABLE_QT6=ON -DENABLE_PERSEUS=OFF -DENABLE_BLADERF=OFF -DENABLE_MIRISDR=OFF -DENABLE_CHANNELRX_SIGMFFILESINK=OFF  
QT_RUNTIME_DEPENDS := qt6-speech-speechd-plugin, qt6-location-plugins, qml6-module-qtlocation, qml6-module-qtpositioning, qml6-module-qtquick-window, qml6-module-qtquick-dialogs, qml6-module-qtquick-controls, qml6-module-qtquick-layouts, qml6-module-qt5compat-graphicaleffects
else
$(error QT_VERSION must be either 5 or 6)
endif

%:
	dh $@ --parallel --buildsystem=cmake+ninja

override_dh_auto_configure:
	dh_auto_configure -- -DARCH_OPT=nehalem $(QT_CMAKE_OPTION) -DENABLE_EXTERNAL_LIBRARIES=AUTO -DDEBUG_OUTPUT=ON -DBUILD_SERVER=OFF

override_dh_gencontrol:
	dh_gencontrol -- -Vqt:Depends='$(QT_RUNTIME_DEPENDS)'

# delete any external projects (such as libsigmf) that are installed
# would be better if we could prevent them from being installed in CMakeLists.txt
override_dh_install:
	-find debian/sdrangel -type d -name external -exec rm -r {} \; -exec mkdir {} \; -exec rmdir -p {} \;
	dh_install

override_dh_auto_test:
	echo "Skipping test step"

# permit the packaging with /usr/local/lib libraries (from `make install`)
# you can also use `export DEB_DH_SHLIBDEPS_ARGS_ALL=--dpkg-shlibdeps-params=--ignore-missing-info`
# not a good idea!
override_dh_shlibdeps:
	dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info
