builder.Makefile 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright 2020 The 2020 Docker, Inc.
  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. GOOS?=$(shell go env GOOS)
  12. GOARCH?=$(shell go env GOARCH)
  13. PROTOS=$(shell find protos -name \*.proto)
  14. EXTENSION:=
  15. ifeq ($(GOOS),windows)
  16. EXTENSION:=.exe
  17. endif
  18. STATIC_FLAGS=CGO_ENABLED=0
  19. LDFLAGS:="-s -w"
  20. GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)
  21. BINARY?=bin/docker
  22. BINARY_WITH_EXTENSION=$(BINARY)$(EXTENSION)
  23. TAGS:=
  24. ifdef BUILD_TAGS
  25. TAGS=-tags $(BUILD_TAGS)
  26. endif
  27. all: cli
  28. protos:
  29. @protoc -I. --go_out=plugins=grpc,paths=source_relative:. ${PROTOS}
  30. cli:
  31. GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) $(TAGS) -o $(BINARY_WITH_EXTENSION) ./cli
  32. cross:
  33. @GOOS=linux GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-linux-amd64 ./cli
  34. @GOOS=darwin GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-darwin-amd64 ./cli
  35. @GOOS=windows GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-windows-amd64.exe ./cli
  36. test:
  37. @go test $(TAGS) -cover $(shell go list ./... | grep -vE 'e2e')
  38. lint:
  39. golangci-lint run --timeout 10m0s ./...
  40. FORCE:
  41. .PHONY: all protos cli cross test lint