Makefile 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. export GO111MODULE=on
  2. PKGNAME := yay
  3. BIN := yay
  4. PREFIX := /usr/local
  5. DESTDIR :=
  6. GO ?= go
  7. GOFLAGS := -v
  8. EXTRA_GOFLAGS ?=
  9. LDFLAGS := $(LDFLAGS) -X "main.version=${VERSION}"
  10. MAJORVERSION := 9
  11. MINORVERSION := 3
  12. PATCHVERSION := 2
  13. ARCH ?= $(shell uname -m)
  14. VERSION ?= ${MAJORVERSION}.${MINORVERSION}.${PATCHVERSION}
  15. RELEASE_DIR := ${PKGNAME}_${VERSION}_${ARCH}
  16. PACKAGE := $(RELEASE_DIR).tar.gz
  17. SOURCES ?= $(shell find . -name "*.go" -type f)
  18. .PHONY: all
  19. all: | clean package
  20. .PHONY: default
  21. default: build
  22. .PHONY: clean
  23. clean:
  24. $(GO) clean -i ./...
  25. rm -rf $(BIN) $(PKGNAME)_$(VERSION)_*
  26. .PHONY: test
  27. test: test-vendor
  28. $(GO) vet .
  29. @test -z "$$(gofmt -l $(SRC))" || (echo "Files need to be linted. Use make fmt" && false)
  30. $(GO) test -mod=vendor --race -covermode=atomic -v . ./pkg/...
  31. .PHONY: build
  32. build: $(BIN)
  33. .PHONY: release
  34. release: $(PACKAGE)
  35. $(BIN): $(SOURCES)
  36. $(GO) build -mod=vendor -ldflags '-s -w $(LDFLAGS)' $(GOFLAGS) $(EXTRA_GOFLAGS) -o $@
  37. $(RELEASE_DIR):
  38. mkdir $(RELEASE_DIR)
  39. $(PACKAGE): $(BIN) $(RELEASE_DIR)
  40. cp -t $(RELEASE_DIR) ${BIN} doc/${PKGNAME}.8 completions/*
  41. tar -czvf $(PACKAGE) $(RELEASE_DIR)
  42. .PHONY: docker-release-all
  43. docker-release-all:
  44. make docker-release ARCH=x86_64
  45. make docker-release ARCH=armv7h
  46. make docker-release ARCH=aarch64
  47. .PHONY: docker-release
  48. docker-release:
  49. docker build --target builder_env --build-arg BUILD_ARCH="$(ARCH)" -t yay-$(ARCH):${VERSION} .
  50. docker run -e="ARCH=$(ARCH)" --name yay-$(ARCH) yay-$(ARCH):${VERSION} make release
  51. docker cp yay-$(ARCH):/app/${PACKAGE} $(PACKAGE)
  52. docker container rm yay-$(ARCH)
  53. .PHONY: docker-build
  54. docker-build:
  55. docker build --target builder --build-arg BUILD_ARCH="$(ARCH)" -t yay-$(ARCH):${VERSION} .
  56. docker create --name yay-build-${ARCH} yay-build-${ARCH}:${VERSION}
  57. docker cp yay-build-${ARCH}:/app/${BIN} ${BIN}
  58. docker container rm yay-build-${ARCH}
  59. .PHONY: test-vendor
  60. test-vendor: vendor
  61. @diff=$$(git diff vendor/); \
  62. if [ -n "$$diff" ]; then \
  63. echo "Please run 'make vendor' and commit the result:"; \
  64. echo "$${diff}"; \
  65. exit 1; \
  66. fi;
  67. .PHONY: vendor
  68. vendor:
  69. $(GO) mod tidy && $(GO) mod vendor
  70. .PHONY: install
  71. install:
  72. install -Dm755 ${BIN} $(DESTDIR)$(PREFIX)/bin/${BIN}
  73. install -Dm644 doc/${PKGNAME}.8 $(DESTDIR)$(PREFIX)/share/man/man8/${PKGNAME}.8
  74. install -Dm644 completions/bash $(DESTDIR)$(PREFIX)/share/bash-completion/completions/${PKGNAME}
  75. install -Dm644 completions/zsh $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_${PKGNAME}
  76. install -Dm644 completions/fish $(DESTDIR)$(PREFIX)/share/fish/vendor_completions.d/${PKGNAME}.fish
  77. .PHONY: uninstall
  78. uninstall:
  79. rm -f $(DESTDIR)$(PREFIX)/bin/${BIN}
  80. rm -f $(DESTDIR)$(PREFIX)/share/man/man8/${PKGNAME}.8
  81. rm -f $(DESTDIR)$(PREFIX)/share/bash-completion/completions/${PKGNAME}
  82. rm -f $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_${PKGNAME}
  83. rm -f $(DESTDIR)$(PREFIX)/share/fish/vendor_completions.d/${PKGNAME}.fish