builder.Makefile 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Copyright (c) 2020 Docker Inc.
  2. # Permission is hereby granted, free of charge, to any person
  3. # obtaining a copy of this software and associated documentation
  4. # files (the "Software"), to deal in the Software without
  5. # restriction, including without limitation the rights to use, copy,
  6. # modify, merge, publish, distribute, sublicense, and/or sell copies
  7. # of the Software, and to permit persons to whom the Software is
  8. # furnished to do so, subject to the following conditions:
  9. # The above copyright notice and this permission notice shall be
  10. # included in all copies or substantial portions of the Software.
  11. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  12. # EXPRESS OR IMPLIED,
  13. # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  15. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  16. # HOLDERS BE LIABLE FOR ANY CLAIM,
  17. # DAMAGES OR OTHER LIABILITY,
  18. # WHETHER IN AN ACTION OF CONTRACT,
  19. # TORT OR OTHERWISE,
  20. # ARISING FROM, OUT OF OR IN CONNECTION WITH
  21. # THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. GOOS?=$(shell go env GOOS)
  23. GOARCH?=$(shell go env GOARCH)
  24. PROTOS=$(shell find protos -name \*.proto)
  25. EXTENSION:=
  26. ifeq ($(GOOS),windows)
  27. EXTENSION:=.exe
  28. endif
  29. STATIC_FLAGS=CGO_ENABLED=0
  30. LDFLAGS:="-s -w"
  31. GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)
  32. BINARY?=bin/docker
  33. BINARY_WITH_EXTENSION=$(BINARY)$(EXTENSION)
  34. TAGS:=
  35. ifdef BUILD_TAGS
  36. TAGS=-tags $(BUILD_TAGS)
  37. endif
  38. all: cli
  39. protos:
  40. @protoc -I. --go_out=plugins=grpc,paths=source_relative:. ${PROTOS}
  41. cli:
  42. GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) $(TAGS) -o $(BINARY_WITH_EXTENSION) ./cli
  43. cross:
  44. @GOOS=linux GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-linux-amd64 ./cli
  45. @GOOS=darwin GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-darwin-amd64 ./cli
  46. @GOOS=windows GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-windows-amd64.exe ./cli
  47. test:
  48. @go test $(TAGS) -cover $(shell go list ./... | grep -vE 'e2e')
  49. lint:
  50. golangci-lint run --timeout 10m0s ./...
  51. FORCE:
  52. .PHONY: all protos cli cross test lint