#!/usr/bin/make -f
# -*- makefile -*-
# debian/rules for the Praat

DEBDIR = $(CURDIR)/debian
DOCSDIR = $(DEBDIR)/praat-doc/usr/share/doc/praat/docs

include /usr/share/dpkg/architecture.mk
-include /usr/share/dpkg/buildtools.mk
PKG_CONFIG ?= pkg-config

export PREFIX = /usr

ifneq (,$(filter $(DEB_HOST_ARCH), i386))
    export DEB_CXXFLAGS_MAINT_APPEND=-ffloat-store
endif

ifneq (,$(filter $(DEB_HOST_ARCH), armel))
    export DEB_LDFLAGS_MAINT_APPEND=-latomic
endif

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@

%.1: $(DEBDIR)/%.md
	# Generate the man page from the Markdown source
	pandoc --standalone --to man $< -o $@

execute_before_dh_installman: praat.1 praat_nogui.1 praat-launch.1

override_dh_auto_build:
	$(DH_OVERRIDDEN_COMMAND)
	rm -f sys/*.o foned/FunctionEditor.o
	PRAAT_GRAPHICS=nogui PRAAT_SOUND=none $(DH_OVERRIDDEN_COMMAND)

execute_after_dh_installchangelogs:
	# Build and install the upstream changelog
	sed -n '/^R"~~~(/,/^)~~~"/{/^R"~~~(/!{/^)~~~"/!p}}' fon/manual_whatsnew.cpp > debian/what-is-new
	dh_installchangelogs debian/what-is-new

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	PRAAT=$(CURDIR)/praat_nogui debian/tests/run-tests
endif

execute_after_dh_installdeb-indep:
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	# Remove extra license file
	rm $(DOCSDIR)/LICENSE.txt
	# Remove duplicated file (identical to index.html)
	rm $(DOCSDIR)/Welcome.html $(DOCSDIR)/praat.html
endif
