#!/usr/bin/make -f
#
# don't use $(MAKE) for the sub-makes here; having MAKEFLAGS=w active for
# config/Makefile makes its subshell `make` invocation produce output, which
# causes Make to try and parse that output as Makefile contents, which breaks.

%:
	dh $@

MAKEVARS := \
	V=1 \
	DESTDIR=$(CURDIR)/debian/tmp/ \
	CFLAGS_uftrace=-fPIE \
	CFLAGS_traceevent=-fPIE \
	LDFLAGS_uftrace=-pie

override_dh_auto_configure:
	LDFLAGS=-Wl,-z,now,-z,relro ./configure --prefix=/usr --libdir=/usr/lib/uftrace

override_dh_auto_build:
	MAKEFLAGS= make $(MAKEVARS)

override_dh_auto_install:
	MAKEFLAGS= make install $(MAKEVARS)

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	@# strip out ansi codes that are apparently not opt-outable in tests/unittest.c
	MAKEFLAGS= make test $(MAKEVARS) | sed -e "$$(printf 's/\033\\[[0-9;]*m//g')"
endif

override_dh_auto_clean:
	MAKEFLAGS= make clean
	$(RM) .config
