builder.Makefile 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Copyright 2020 Docker Compose CLI 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. GOOS?=$(shell go env GOOS)
  12. GOARCH?=$(shell go env GOARCH)
  13. PKG_NAME := github.com/docker/compose/v2
  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 $(PKG_NAME)/internal.Version=${GIT_TAG}"
  21. GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)
  22. COMPOSE_BINARY?=bin/docker-compose
  23. COMPOSE_BINARY_WITH_EXTENSION=$(COMPOSE_BINARY)$(EXTENSION)
  24. WORK_DIR:=$(shell mktemp -d)
  25. TAGS:=
  26. ifdef BUILD_TAGS
  27. TAGS=-tags $(BUILD_TAGS)
  28. LINT_TAGS=--build-tags $(BUILD_TAGS)
  29. endif
  30. .PHONY: compose-plugin
  31. compose-plugin:
  32. GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY_WITH_EXTENSION) ./cmd
  33. .PHONY: cross
  34. cross:
  35. GOOS=linux GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-x86_64 ./cmd
  36. GOOS=linux GOARCH=arm64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-aarch64 ./cmd
  37. GOOS=linux GOARM=6 GOARCH=arm $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-armv6 ./cmd
  38. GOOS=linux GOARM=7 GOARCH=arm $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-armv7 ./cmd
  39. GOOS=linux GOARCH=s390x $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-s390x ./cmd
  40. GOOS=darwin GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-darwin-x86_64 ./cmd
  41. GOOS=darwin GOARCH=arm64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-darwin-aarch64 ./cmd
  42. GOOS=windows GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-windows-x86_64.exe ./cmd
  43. .PHONY: test
  44. test:
  45. go test $(TAGS) -cover $(shell go list $(TAGS) ./... | grep -vE 'e2e')
  46. .PHONY: lint
  47. lint:
  48. golangci-lint run $(LINT_TAGS) --timeout 10m0s ./...
  49. .PHONY: check-license-headers
  50. check-license-headers:
  51. ./scripts/validate/fileheader
  52. .PHONY: check-go-mod
  53. check-go-mod:
  54. ./scripts/validate/check-go-mod