#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

include /usr/share/dpkg/buildflags.mk

export CPPFLAGS
export CFLAGS
export CXXFLAGS
export LDFLAGS

export USE_SYSTEM_NETWORKASIO = yes
export USE_SYSTEM_FFTW2 = yes

# Removes the NORELEASE_WARNING banner.
export GITHUB_EVENT_NAME = release

# Use Debian package version for plugin version.
export GITCOMMITHASH = $(shell dpkg-parsechangelog -SVersion)

%:
	dh $@

override_dh_auto_clean:
	if [ -f config.mk ]; then \
		$(MAKE) clean; \
	fi

override_dh_auto_build:
	dh_auto_build
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	mv mha/doc/openMHAdoxygen-26.04.sty mha/doc/openMHAdoxygen.sty
	$(MAKE) doc
endif

override_dh_auto_install:
	dh_auto_install
	# Remove VCS control files from installed directory tree
	find debian/openmha/usr -type f -name '.gitignore' -delete
	# Octave/MATLAB .m files and the Java archive are data loaded by the
	# tooling, not directly executed: they must not be executable.
	find debian/openmha/usr/lib/openmha/mfiles -type f \
		\( -name '*.m' -o -name '*.jar' \) -exec chmod 0644 {} +
	# Example run scripts are meant to be executed.
	find debian/openmha/usr/share/openmha/examples -type f \
		-name '*.sh' -exec chmod 0755 {} +
