1+ # Copyright © The CDI Authors
2+ # Licensed under the Apache License, Version 2.0 (the "License");
3+ # you may not use this file except in compliance with the License.
4+ # You may obtain a copy of the License at
5+ # http://www.apache.org/licenses/LICENSE-2.0
6+ # Unless required by applicable law or agreed to in writing, software
7+ # distributed under the License is distributed on an "AS IS" BASIS,
8+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+ # See the License for the specific language governing permissions and
10+ # limitations under the License.
11+
112GO_CMD := go
13+ GO := $(GO_CMD )
214GO_BUILD := $(GO_CMD ) build
315GO_TEST := $(GO_CMD ) test -race -v -cover
416
@@ -8,7 +20,8 @@ GO_VET := $(GO_CMD) vet
820
921CDI_PKG := $(shell grep ^module go.mod | sed 's/^module * //g')
1022
11- BINARIES := bin/cdi bin/validate
23+ CMDS := $(patsubst ./cmd/% /,% ,$(sort $(dir $(wildcard ./cmd/* /) ) ) )
24+ BINARIES := $(patsubst % ,bin/% ,$(CMDS ) )
1225
1326ifneq ($(V ) ,1)
1427 Q := @
4558# build targets
4659#
4760
48- bin/% :
61+ $( BINARIES ) : bin/% :
4962 $(Q ) echo " Building $@ ..." ; \
50- $( GO_BUILD ) -o $@ ./$( subst bin/, cmd/, $@ )
63+ cd cmd/ $( * ) $( GO_BUILD ) -o $( abspath $@ ) ./cmd/$( * )
5164
52- bin/cdi :
53- $(Q ) echo " Building $@ ..." ; \
54- cd cmd/cdi; $(GO_BUILD ) -o $(abspath $@ ) .
65+ #
66+ # vendoring targets
67+ #
68+ .PHONY : mod-verify mod-tidy $(MOD_TIDY_TARGETS ) $(MOD_VERIFY_TARGETS )
69+
70+ MOD_TARGETS := $(CMDS ) ..
71+ MOD_TIDY_TARGETS := $(patsubst % ,mod-tidy-% ,$(MOD_TARGETS ) )
72+ MOD_VERIFY_TARGETS := $(patsubst % ,mod-verify-% ,$(MOD_TARGETS ) )
73+
74+ $(MOD_TIDY_TARGETS ) : mod-tidy-% :
75+ @$(Q ) echo " Running $@ ... in $( abspath ./cmd/$( * ) ) "
76+ @ (cd $( abspath ./cmd/$( * ) ) && ${GO} mod tidy)
77+
78+ $(MOD_VERIFY_TARGETS ) : mod-verify-% : mod-tidy-%
79+ @$(Q ) echo " Running $@ ... $( abspath ./cmd/$( * ) ) "
80+ @ (cd $( abspath ./cmd/$( * ) ) && ${GO} mod verify)
81+
82+ mod-verify : $(MOD_VERIFY_TARGETS )
83+ mod-tidy : $(MOD_TIDY_TARGETS )
5584
5685#
5786# cleanup targets
@@ -83,7 +112,13 @@ test-schema: bin/validate
83112# dependencies
84113#
85114
86- bin/validate : cmd/validate/validate.go $(wildcard schema/* .json)
115+ bin/validate : $(wildcard schema/* .json) $(wildcard cmd/validate/* .go cmd/validate/cmd/* .go) $(shell \
116+ for dir in \
117+ $$(cd ./cmd/validate; $(GO_CMD ) list -f '{{ join .Deps "\n"}}' ./... | \
118+ grep $(CDI_PKG ) /pkg/ | \
119+ sed 's:$(CDI_PKG ) :.:g' ) ; do \
120+ find $$dir -name \* .go; \
121+ done | sort | uniq)
87122
88123# quasi-automatic dependency for bin/cdi
89124bin/cdi : $(wildcard cmd/cdi/* .go cmd/cdi/cmd/* .go) $(shell \
@@ -93,3 +128,4 @@ bin/cdi: $(wildcard cmd/cdi/*.go cmd/cdi/cmd/*.go) $(shell \
93128 sed 's:$(CDI_PKG ) :.:g' ) ; do \
94129 find $$dir -name \* .go; \
95130 done | sort | uniq)
131+
0 commit comments