1+ # This file contains makefile targets to update copyrights and third party notices in the repo
2+
3+ # --- Configurable license header settings ---
4+ COPYRIGHT_YEAR ?= $(shell date +% Y)
5+ COPYRIGHT_OWNER ?= NVIDIA CORPORATION & AFFILIATES
6+ COPYRIGHT_STYLE ?= apache
7+ COPYRIGHT_FLAGS ?= -s
8+ COPYRIGHT_EXCLUDE ?= vendor deployment config bundle .*
9+ GIT_LS_FILES_EXCLUDES := $(foreach d,$(COPYRIGHT_EXCLUDE ) ,:^"$(d ) ")
10+
11+ # --- Tool paths ---
12+ BIN_DIR ?= ./bin
13+ ADDLICENSE ?= $(BIN_DIR ) /addlicense
14+ ADDLICENSE_VERSION ?= latest
15+ GO_LICENSES ?= $(BIN_DIR ) /go-licenses
16+ GO_LICENSES_VERSION ?= latest
17+
18+ # Ensure bin dir exists
19+ $(BIN_DIR ) :
20+ @mkdir -p $(BIN_DIR )
21+
22+ # Install addlicense locally
23+ .PHONY : addlicense
24+ addlicense : $(BIN_DIR )
25+ @if [ ! -f " $( ADDLICENSE) " ]; then \
26+ echo " Installing addlicense to $( ADDLICENSE) ..." ; \
27+ GOBIN=$(abspath $(BIN_DIR ) ) go install github.com/google/addlicense@$(ADDLICENSE_VERSION ) ; \
28+ else \
29+ echo " addlicense already installed at $( ADDLICENSE) " ; \
30+ fi
31+
32+ # Check headers
33+ .PHONY : copyright-check
34+ copyright-check : addlicense
35+ @echo " Checking copyright headers..."
36+ @git ls-files ' *' $(GIT_LS_FILES_EXCLUDES ) | xargs grep -ILi " $( COPYRIGHT_OWNER) " | xargs -r $(ADDLICENSE ) -check -c " $( COPYRIGHT_OWNER) " -l $(COPYRIGHT_STYLE ) $(COPYRIGHT_FLAGS ) -y $(COPYRIGHT_YEAR )
37+
38+ # Fix headers
39+ .PHONY : copyright
40+ copyright : addlicense
41+ @echo " Adding copyright headers..."
42+ @git ls-files ' *' $(GIT_LS_FILES_EXCLUDES ) | xargs grep -ILi " $( COPYRIGHT_OWNER) " | xargs -r $(ADDLICENSE ) -c " $( COPYRIGHT_OWNER) " -l $(COPYRIGHT_STYLE ) $(COPYRIGHT_FLAGS ) -y $(COPYRIGHT_YEAR )
43+
44+ # Install go-licenses tool locally
45+ .PHONY : go-licenses
46+ go-licenses : $(BIN_DIR )
47+ @if [ ! -f " $( GO_LICENSES) " ]; then \
48+ echo " Installing go-licenses to $( GO_LICENSES) ..." ; \
49+ GOBIN=$(abspath $(BIN_DIR ) ) go install github.com/google/go-licenses@$(GO_LICENSES_VERSION ) ; \
50+ else \
51+ echo " go-licenses already installed at $( GO_LICENSES) " ; \
52+ fi
53+
54+ # Generate THIRD_PARTY_NOTICES from go-licenses
55+ .PHONY : third-party-licenses
56+ third-party-licenses : go-licenses
57+ @echo " Collecting third-party licenses..."
58+ @$(GO_LICENSES ) save ./... --save_path=third_party_licenses --ignore=github.com/k8snetworkplumbingwg/cni-log
59+ @echo " Generating THIRD_PARTY_NOTICES..."
60+ @find third_party_licenses -type f -iname " LICENSE*" | sort --ignore-case | while read -r license; do \
61+ echo " ---" ; \
62+ echo " ## $$ (basename $$ (dirname " $$ license" ))" ; \
63+ echo " " ; \
64+ cat " $$ license" ; \
65+ echo " " ; \
66+ done > THIRD_PARTY_NOTICES
67+ @rm -rf third_party_licenses
68+ @echo " THIRD_PARTY_NOTICES updated."
0 commit comments