#!/usr/bin/make -f

# The example programs under examples/ are main packages that nothing needs.
# The six commands under cmd/ are what csaf-tools ships, so they are built.
# The pattern is matched against import paths when building and against
# source-relative paths when installing, hence the optional module prefix; it
# is anchored so that nothing else can match.
export DH_GOLANG_EXCLUDES := ^(github\.com/gocsaf/csaf/v3/)?examples/

# dh-go copies only *.go, go.mod, go.sum and testdata/ into the build tree, so
# every go:embed target has to be listed here.
#   csaf/schema: the CVSS schemas (csaf/validation.go).
#   cmd/csaf_checker/tmpl, cmd/csaf_provider/tmpl: the HTML templates those two
#   commands embed.
#   internal/certs/data, internal/options/data: fixtures read by those tests.
export DH_GOLANG_INSTALL_EXTRA := csaf/schema \
                                  cmd/csaf_checker/tmpl \
                                  cmd/csaf_provider/tmpl \
                                  internal/certs/data \
                                  internal/options/data

%:
	dh $@ --buildsystem=golang --with=golang

# These three validate provider metadata against the OASIS JSON schemas. The
# schemas are in non-free, and a source package in main must not build-depend
# on non-free (Policy 2.2.1), so they cannot run here. csaf-tools depends on
# csaf-oasis-schemas, so they do run for the user. Everything else runs.
override_dh_auto_test:
	dh_auto_test -- -skip 'TestShaMarking|TestContentTypeReport'

# cmd/ is built but its source is not installed. Shipping it would put the
# command-only dependencies into the -dev package, where every library user
# would pull them, and the autopkgtest builds whatever is installed.
execute_after_dh_auto_install:
	rm -rf debian/tmp/usr/share/gocode/src/github.com/gocsaf/csaf/v3/cmd
