# src/test/lint/Makefile -- T11 static + style gate, and the report-only
# quality tools.
#
#   make            run styleLint, asciiCheck, the staticGate self-test,
#                   shellcheck, codespell, clang-tidy and staticGate (fails
#                   on new findings)
#   make baseline   regenerate the baselines of everything `make` runs
#                   (staticGate's merge rules for each)
#   make style      styleLint only
#   make ascii      asciiCheck only
#   make static     staticGate (cppcheck + -fanalyzer; slow)
#   make cppcheck   staticGate cppcheck pass only
#   make selftest   test staticGate's baseline merge logic (fast)
#   make shellcheck shellcheck over every *.sh (qaGate.sh; seconds)
#   make codespell  codespell over sources and docs (qaGate.sh; seconds)
#   make tidy       clang-tidy (clangTidy.yaml) over the host compile
#                   database (qaGate.sh; ~2 min)
#   make tidy-baseline merge the current clang-tidy findings into
#                   clangTidyBaseline.txt
#
# Separate, slower targets (not in `make`; see claudeDocs/qaTools.md):
#   make clang         clang build of every host translation unit with
#                      extra warnings; report in obj/clang/report.txt
#                      (hostDb.py; report only)
#   make complexity    lizard: functions over CCN 15 or 100 lines,
#                      obj/qa/complexity (report only, never a gate)
#   make msan          MemorySanitizer: BASIC harnesses, basrun / bascomp
#                      runs and the basdev / formrt suites (msan.mk; runs
#                      make in product directories, so take the shared
#                      build lock around it when other builds run)
#   make valgrind      valgrind memcheck over bascomp, basrun, dvxhlpc and
#                      dvxres (valgrind.mk)
#   make qa            all of the separate targets above except the
#                      baseline merge
#
# cppcheckBaseline.txt, analyzerBaseline.txt, clangTidyBaseline.txt,
# shellcheckBaseline.txt and codespellBaseline.txt list
# accepted findings as "<count> <key>", each preceded by its
# justification comment:
#   # FP: <reason>          triaged false positive
#   # THIRDPARTY: <reason>  upstream code, not modified by DVX
#   # UNTRIAGED ...         accepted by an update, nobody has looked yet
# "make baseline" (staticGate.sh --update) MERGES rather than rewriting:
# comments stay with keys that still occur, keys now at 0 are dropped
# (their comments are printed), and every new or grown key gets an
# UNTRIAGED line.  "make static" warns loudly about UNTRIAGED entries but
# only fails on new/increased findings, so triage each UNTRIAGED entry
# (fix it or write the FP reason) before committing a baseline update.
# A qaGate.sh tool without a baseline file yet is report-only: it prints
# its findings under a banner and passes.
#
# staticGate needs cppcheck and fails (it never passes silently) when it
# is missing.  Install cppcheck, or run e.g.
#   make STATIC_SKIP_CPPCHECK=1
# to skip only the cppcheck pass deliberately (reported on stderr).

.PHONY: all style ascii static cppcheck baseline selftest shellcheck codespell tidy tidy-baseline clang complexity msan valgrind qa

all: style ascii selftest shellcheck codespell tidy static

style:
	python3 ./styleLint.py

ascii:
	./asciiCheck.sh

static:
	./staticGate.sh

cppcheck:
	./staticGate.sh --cppcheck-only

selftest:
	./staticGate.sh --self-test

shellcheck:
	./qaGate.sh shellcheck

codespell:
	./qaGate.sh codespell

baseline:
	python3 ./styleLint.py --update-baseline --summary
	./asciiCheck.sh --update
	./qaGate.sh shellcheck --update
	./qaGate.sh codespell --update
	./qaGate.sh tidy --update
	./staticGate.sh --update

tidy:
	./qaGate.sh tidy

tidy-baseline:
	./qaGate.sh tidy --update

clang:
	python3 ./hostDb.py clang

complexity:
	./qaGate.sh complexity

# Objects in parallel, then the steps in order.
msan:
	$(MAKE) -f msan.mk msan-build
	$(MAKE) -f msan.mk -j1 msan

valgrind:
	$(MAKE) -f valgrind.mk

# Report-only tools; every one runs even when another reports findings.
qa:
	-$(MAKE) clang
	-$(MAKE) complexity
	-$(MAKE) msan
	-$(MAKE) valgrind
