#!/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

# The PDF manuals cannot be built in trixie: upstream ships one doxygen
# LaTeX style file per doxygen release and the newest is for doxygen 1.15
# as found in unstable, whereas trixie has doxygen 1.9.8. Building the
# developer manual against it makes pdflatex bail out with a fatal
# "Missing $ inserted" error.
# Disable building the PDF documentation.
#
#override_dh_auto_build:
#	dh_auto_build
#
#ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
#	$(MAKE) doc
#endif

override_dh_auto_install:
	# ./configure turns the documentation on whenever the tools to build it
	# happen to be installed and the install target then builds the PDF
	# manuals as a prerequisite. BUILD_DOCS=no disables it.
	dh_auto_install -- BUILD_DOCS=no
	# 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 {} +
