1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
GO_CMD := go
GO_BUILD := $(GO_CMD) build
GO_TEST := $(GO_CMD) test -race -v -cover
GO_LINT := golint -set_exit_status
GO_FMT := gofmt
GO_VET := $(GO_CMD) vet
CDI_PKG := $(shell grep ^module go.mod | sed 's/^module *//g')
BINARIES := bin/cdi bin/validate
ifneq ($(V),1)
Q := @
endif
#
# top-level targets
#
all: build
build: $(BINARIES)
clean: clean-binaries clean-schema
test: test-gopkgs test-schema
#
# validation targets
#
pre-pr-checks pr-checks: test fmt lint vet
fmt format:
$(Q)$(GO_FMT) -s -d -w -e .
lint:
$(Q)$(GO_LINT) -set_exit_status ./...
vet:
$(Q)$(GO_VET) ./...
#
# build targets
#
bin/%:
$(Q)echo "Building $@..."; \
$(GO_BUILD) -o $@ ./$(subst bin/,cmd/,$@)
#
# cleanup targets
#
# clean up binaries
clean-binaries:
$(Q) rm -f $(BINARIES)
# clean up schema validator
clean-schema:
$(Q)rm -f schema/validate
#
# test targets
#
# tests for go packages
test-gopkgs:
$(Q)$(GO_TEST) ./...
# tests for CDI Spec JSON schema
test-schema: bin/validate
$(Q)echo "Building in schema..."; \
$(MAKE) -C schema test
#
# dependencies
#
bin/validate: cmd/validate/validate.go $(wildcard schema/*.json)
# quasi-automatic dependency for bin/cdi
bin/cdi: $(wildcard cmd/cdi/*.go cmd/cdi/cmd/*.go) $(shell \
for dir in \
$$($(GO_CMD) list -f '{{ join .Deps "\n"}}' ./cmd/cdi/... | \
grep $(CDI_PKG)/pkg/ | \
sed 's:$(CDI_PKG):.:g'); do \
find $$dir -name \*.go; \
done | sort | uniq)
|