builder.Makefile 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. GIT_TAG=$(shell git describe --tags --match "v[0-9]*")
  20. LDFLAGS="-s -w -X main.version=${GIT_TAG}"
  21. GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)
  22. BINARY?=bin/docker
  23. BINARY_WITH_EXTENSION=$(BINARY)$(EXTENSION)
  24. TAGS:=
  25. ifdef BUILD_TAGS
  26. TAGS=-tags $(BUILD_TAGS)
  27. endif
  28. all: cli
  29. protos:
  30. protoc -I. --go_out=plugins=grpc,paths=source_relative:. ${PROTOS}
  31. cli:
  32. GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) $(TAGS) -o $(BINARY_WITH_EXTENSION) ./cli
  33. cross:
  34. GOOS=linux GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-linux-amd64 ./cli
  35. GOOS=darwin GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-darwin-amd64 ./cli
  36. GOOS=windows GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-windows-amd64.exe ./cli
  37. test:
  38. go test $(TAGS) -cover $(shell go list ./... | grep -vE 'e2e')
  39. lint:
  40. golangci-lint run --timeout 10m0s ./...
  41. FORCE:
  42. .PHONY: all protos cli cross test lint