#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

include /usr/share/dpkg/architecture.mk

TEST_SKIP_ARCHS=
TEST_IGNORE_ARCHS=arm64 armhf

export DEB_BUILD_MAINT_OPTIONS = optimize=-lto

export DEB_CFLAGS_MAINT_APPEND = -fno-strict-aliasing
export DEB_CXXFLAGS_MAINT_APPEND = -fno-strict-aliasing

DESTDIR = $(CURDIR)/debian/tmp

export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

override_dh_auto_install:
	dh_auto_install
	# rename binary
	cd $(DESTDIR)/usr/bin && mv pprof google-pprof
	cd $(DESTDIR)/usr/share/man/man1 && \
		mv pprof.1 google-pprof.1 && \
		sed -i 's/pprof/google-pprof/g' google-pprof.1
	cd $(DESTDIR)/usr/share/doc/gperftools/ && \
		sed -i 's/pprof/google-pprof/g' README
	# remove unwanted documentation
	cd $(DESTDIR)/usr/share/doc/gperftools/ && \
		rm -f ChangeLog ChangeLog.old INSTALL README_windows.txt TODO
	# remove .la files
	find $(DESTDIR) -name \*.la -exec rm {} \;

override_dh_auto_test:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
    ifneq (,$(findstring $(DEB_HOST_ARCH), $(TEST_SKIP_ARCHS)))
	@echo Skip running the tests on $(DEB_HOST_ARCH), hanging the buildds
    else ifneq (,$(findstring $(DEB_HOST_ARCH), $(TEST_IGNORE_ARCHS)))
	-dh_auto_test --no-parallel
	@echo Ignoring test results on $(DEB_HOST_ARCH)
    else
	dh_auto_test --no-parallel
    endif
endif # nocheck

%:
	dh $@ --list-missing

.PHONY: override_dh_auto_install override_dh_auto_test
