#!/usr/bin/make -f

export QT_SELECT=qt5
DEB_TARGET_GNU_TYPE := $(shell dpkg-architecture -qDEB_TARGET_GNU_TYPE)
DEB_HOST_GNU_TYPE := $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE := $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

ifeq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
	QMAKE := qmake
else
	QMAKE := "/usr/lib/$(DEB_BUILD_GNU_TYPE)/qt5/bin/qmake" -qtconf "/usr/lib/$(DEB_TARGET_GNU_TYPE)/qt5/qt.conf" -spec "/usr/lib/$(DEB_TARGET_GNU_TYPE)/qt5/mkspecs/$(DEB_TARGET_GNU_TYPE)-g++" LIBS+="-lstdc++ -lm"
endif

%:
	dh $@

override_dh_update_autotools_config:
	# dh_update_autotools_config replaces libs/opus/config.{sub,guess}.
	# This is unnecessary as we don't build opus via autotools at all
	# (we use qmake). In addition, this would cause our -dev version generation
	# logic to mark Debian builds as -dirty by default.
	# Therefore, disable this behavior:
	:

override_dh_auto_configure:
	mkdir -p build-gui && cd build-gui && $(QMAKE) "CONFIG+=noupcasename" PREFIX=/usr ../Jamulus.pro
	mkdir -p build-nox && cd build-nox && $(QMAKE) "CONFIG+=headless serveronly" TARGET=jamulus-headless PREFIX=/usr ../Jamulus.pro

override_dh_auto_build:
	cd src/translation && lrelease *.ts
	cd build-gui && make -j "$$(nproc)"
	cd build-nox && make -j "$$(nproc)"

override_dh_auto_install:
	cd build-nox && make install INSTALL_ROOT=../debian/tmp
	cd build-gui && make install INSTALL_ROOT=../debian/tmp

override_dh_auto_clean:
	rm -rf build-gui
	rm -rf build-nox
	dh_clean
