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
+
1
12
GO_CMD := go
2
13
GO_BUILD := $(GO_CMD ) build
3
14
GO_TEST := $(GO_CMD ) test -race -v -cover
@@ -8,7 +19,8 @@ GO_VET := $(GO_CMD) vet
8
19
9
20
CDI_PKG := $(shell grep ^module go.mod | sed 's/^module * //g')
10
21
11
- BINARIES := bin/cdi bin/validate
22
+ CMDS := $(patsubst ./cmd/% /,% ,$(sort $(dir $(wildcard ./cmd/* /) ) ) )
23
+ BINARIES := $(patsubst % ,bin/% ,$(CMDS ) )
12
24
13
25
ifneq ($(V ) ,1)
14
26
Q := @
45
57
# build targets
46
58
#
47
59
48
- bin/% :
49
- $(Q ) echo " Building $@ ..." ; \
50
- $(GO_BUILD ) -o $@ ./$(subst bin/,cmd/,$@ )
60
+ $(BINARIES ) : bin/% :
61
+ $(Q ) echo " Building $@ ..."
62
+ $(Q ) (cd cmd/$( * ) && $( GO_BUILD) -o $( abspath $@ ) .)
63
+
64
+ #
65
+ # go module tidy and verify targets
66
+ #
67
+ .PHONY : mod-tidy $(CMD_MOD_TIDY_TARGETS ) mod-tidy-root
68
+ .PHONY : mod-verify $(CMD_MOD_VERIFY_TARGETS ) mod-verify-root
69
+
70
+ CMD_MOD_TIDY_TARGETS := mod-tidy-cdi mod-tidy-validate
71
+ CMD_MOD_VERIFY_TARGETS := mod-verify-cdi mod-verify-validate
72
+
73
+ mod-tidy-root :
74
+ $(Q ) echo " Running $@ ..." ; \
75
+ $(GO_CMD ) mod tidy
76
+
77
+ $(CMD_MOD_TIDY_TARGETS ) : mod-tidy-% : mod-tidy-root
78
+ $(Q ) echo " Running $@ ... in $( abspath ./cmd/$( * ) ) " ; \
79
+ (cd $( abspath ./cmd/$( * ) ) && $( GO_CMD) mod tidy)
80
+
81
+ mod-verify-root : mod-tidy-root
82
+ $(Q ) echo " Running $@ ..." ; \
83
+ $(GO_CMD ) mod verify
51
84
52
- bin/cdi :
53
- $(Q ) echo " Building $@ ..." ; \
54
- cd cmd/cdi; $(GO_BUILD ) -o $(abspath $@ ) .
85
+ $(CMD_MOD_VERIFY_TARGETS ) : mod-verify-% : mod-tidy-% mod-verify-root
86
+ $(Q ) echo " Running $@ ... in $( abspath ./cmd/$( * ) ) " ; \
87
+ (cd $( abspath ./cmd/$( * ) ) && pwd && $( GO_CMD) mod verify)
88
+
89
+ mod-verify : $(CMD_MOD_VERIFY_TARGETS )
90
+ mod-tidy : $(CMD_MOD_TIDY_TARGETS )
55
91
56
92
#
57
93
# cleanup targets
@@ -83,7 +119,13 @@ test-schema: bin/validate
83
119
# dependencies
84
120
#
85
121
86
- bin/validate : cmd/validate/validate.go $(wildcard schema/* .json)
122
+ bin/validate : $(wildcard schema/* .json) $(wildcard cmd/validate/* .go cmd/validate/cmd/* .go) $(shell \
123
+ for dir in \
124
+ $$(cd ./cmd/validate; $(GO_CMD ) list -f '{{ join .Deps "\n"}}' ./... | \
125
+ grep $(CDI_PKG ) /pkg/ | \
126
+ sed 's:$(CDI_PKG ) :.:g' ) ; do \
127
+ find $$dir -name \* .go; \
128
+ done | sort | uniq)
87
129
88
130
# quasi-automatic dependency for bin/cdi
89
131
bin/cdi : $(wildcard cmd/cdi/* .go cmd/cdi/cmd/* .go) $(shell \
@@ -93,3 +135,4 @@ bin/cdi: $(wildcard cmd/cdi/*.go cmd/cdi/cmd/*.go) $(shell \
93
135
sed 's:$(CDI_PKG ) :.:g' ) ; do \
94
136
find $$dir -name \* .go; \
95
137
done | sort | uniq)
138
+
0 commit comments