#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
else
	NUMJOBS = 1
endif

%:
	dh $@

override_dh_auto_configure:
	python3 ./waf configure --prefix=/usr --no-faust \
		--cxxflags="$(shell dpkg-buildflags --get CXXFLAGS) \
			$(shell dpkg-buildflags --get CPPFLAGS)" \
		--ldflags="$(shell dpkg-buildflags --get LDFLAGS) -Wl,--as-needed" -v \
		--shared-lib --lib-dev --glade-support --enable-lfs --ladspa

override_dh_makeshlibs:
	dh_makeshlibs -V

override_dh_auto_build-arch:
	python3 ./waf build -v --jobs=$(NUMJOBS)

override_dh_auto_build-indep:
	cd $(CURDIR)/documentation ; doxygen
	# don't use dh_doxygen because it doesn't detect the docs
	cd $(CURDIR)/documentation/html && find . -name "*.md5" -delete
	cd $(CURDIR)/documentation/html && find . -name "*.map" -delete

override_dh_auto_clean:
	python3 ./waf distclean
	rm -rf build/*
	rm -rf build/.conf*
	rm -rf build/.waf*
	find . -name "*.pyc" -delete
	rm -rf documentation/html

override_dh_auto_install:
	python3 ./waf install --destdir=$(CURDIR)/debian/tmp --libdir=$(CURDIR)/debian/tmp
	rm -f $(CURDIR)/debian/tmp/usr/share/gx_head/sounds/bands/LICENSE
	rm -f $(CURDIR)/debian/tmp/usr/share/gx_head/sounds/amps/LICENSE
	rm -f $(CURDIR)/debian/tmp/usr/lib/libgxwmm.so
	rm -f $(CURDIR)/debian/tmp/usr/lib/libgxw.so
	ln -s libgxwmm.so.0.1 $(CURDIR)/debian/tmp/usr/lib/libgxwmm.so
	ln -s libgxw.so.0.1 $(CURDIR)/debian/tmp/usr/lib/libgxw.so

override_dh_missing:
	dh_missing --fail-missing
