## Copyright (C) 1996-2026 The Squid Software Foundation and contributors
##
## Squid software is distributed under GPLv2+ license and includes
## contributions from numerous individuals and organizations.
## Please see the COPYING and CONTRIBUTORS files for details.
##

# A space-separated list of header files to be skipped by
# testHeaders during "make check"
EXCLUDE_FROM_HDR_TESTING =


# to test header files in addition to those tested by default,
# add an empty target named 'testHeaders' depending on the additional
# headers to test

testHeaders: $(SOURCES) $(noinst_HEADERS) $(EXTRA_DIST) $(top_srcdir)/test-suite/testHeader.cc.in
	$(MAKE) $(^:.h=.hdrtest) && cp $(TRUE) $@

.h.hdrtest:
	@SrcFilePath=`echo $< | $(SED) 's%^$(top_srcdir)/%%'`; \
	SrcFileName=`basename $$SrcFilePath`; \
	TargetFileName=tmp$$$$-`basename $@`; \
	if test "$(EXCLUDE_FROM_HDR_TESTING)" != "" && echo "$(EXCLUDE_FROM_HDR_TESTING)" | $(TR) ' ' '\n' | $(FGREP) -x -q "$$SrcFileName" ; then \
		echo "header-test: skip - $$SrcFilePath"; \
		exit 0; \
	fi; \
	$(SED) "s%[@]HEADER[@]%${<}%" "$(top_srcdir)/test-suite/testHeader.cc.in" >"$$TargetFileName.cc" && \
	echo "$(CXXCOMPILE) -c -o" "$$TargetFileName" "$$TargetFileName.cc" && \
	if $(CXXCOMPILE) -c -o "$$TargetFileName" "$$TargetFileName.cc" ; \
		then echo "header-test: ok - $$SrcFilePath"; $(RM) "$$TargetFileName.cc" "$$TargetFileName"; \
		else echo "header-test: not ok - $$SrcFilePath"; exit 1; fi

TESTS += testHeaders
CLEANFILES += testHeaders
