
# Coverage targets

.PHONY: clean-gcno clean-gcda \
	coverage-html generate-coverage-html clean-coverage-html \
	coverage-gcovr generate-coverage-gcovr clean-coverage-gcovr

clean-local: clean-gcno clean-coverage-html clean-coverage-gcovr

if HAVE_GCOV

clean-gcno:
	@echo Removing old coverage instrumentation
	-find -name '*.gcno' -print | xargs -r rm

clean-gcda:
	@echo Removing old coverage results
	-find -name '*.gcda' -print | xargs -r rm
  
coverage-html: clean-gcda
	-$(MAKE) $(AM_MAKEFLAGS) -k check
	$(MAKE) $(AM_MAKEFLAGS) generate-coverage-html
  
generate-coverage-html:
	@echo Collecting coverage data
	$(LCOV) --directory $(top_builddir) --capture --output-file coverage.info --no-checksum --compat-libtool
	LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info
  
clean-coverage-html: clean-gcda
	-$(LCOV) --directory $(top_builddir) -z
	-rm -rf coverage.info coveragereport

if HAVE_GCOVR

coverage-gcovr: clean-gcda
	-$(MAKE) $(AM_MAKEFLAGS) -k check
	$(MAKE) $(AM_MAKEFLAGS) generate-coverage-gcovr
	
generate-coverage-gcovr:
	@echo Generating coverage GCOVR report
	$(GCOVR) -x -r $(top_builddir) -o $(top_builddir)/coverage.xml
	
clean-coverage-gcovr: clean-gcda
	-rm -rf $(top_builddir)/coverage.xml

endif # HAVE_GCOVR

endif # HAVE_GCOV
