Makefile 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. export GO111MODULE=on
  2. GOPROXY ?= https://proxy.golang.org
  3. export GOPROXY
  4. BUILD_TAG = devel
  5. ARCH ?= $(shell uname -m)
  6. BIN := yay
  7. DESTDIR :=
  8. GO ?= go
  9. PKGNAME := yay
  10. PREFIX := /usr/local
  11. MAJORVERSION := 9
  12. MINORVERSION := 4
  13. PATCHVERSION := 7
  14. VERSION ?= ${MAJORVERSION}.${MINORVERSION}.${PATCHVERSION}
  15. LOCALEDIR := po
  16. SYSTEMLOCALEPATH := $(DESTDIR)$(PREFIX)/share/locale/
  17. LANGS := pt en
  18. POTFILE := default.pot
  19. POFILES := $(addprefix $(LOCALEDIR)/,$(addsuffix .po,$(LANGS)))
  20. MOFILES := $(POFILES:.po=.mo)
  21. GOFLAGS := -v -mod=mod
  22. EXTRA_GOFLAGS ?=
  23. LDFLAGS := $(LDFLAGS) -X "main.yayVersion=${VERSION}" -X "main.localePath=${SYSTEMLOCALEPATH}"
  24. RELEASE_DIR := ${PKGNAME}_${VERSION}_${ARCH}
  25. PACKAGE := $(RELEASE_DIR).tar.gz
  26. SOURCES ?= $(shell find . -name "*.go" -type f)
  27. .PRECIOUS: ${LOCALEDIR}/%.po
  28. .PHONY: default
  29. default: build
  30. .PHONY: all
  31. all: | clean release
  32. .PHONY: clean
  33. clean:
  34. $(GO) clean $(GOFLAGS) -i ./...
  35. rm -rf $(BIN) $(PKGNAME)_*
  36. .PHONY: test
  37. test:
  38. $(GO) vet $(GOFLAGS) ./...
  39. @test -z "$$(gofmt -l *.go)" || (echo "Files need to be linted. Use make fmt" && false)
  40. $(GO) test $(GOFLAGS) --race -covermode=atomic . ./pkg/...
  41. .PHONY: build
  42. build: $(BIN)
  43. .PHONY: release
  44. release: $(PACKAGE)
  45. .PHONY: docker-release-all
  46. docker-release-all:
  47. make docker-release-armv7h ARCH=armv7h
  48. make docker-release-x86_64 ARCH=x86_64
  49. make docker-release-aarch64 ARCH=aarch64
  50. .PHONY: docker-release-armv7h
  51. docker-release-armv7h:
  52. docker build --build-arg="BUILD_TAG=arm32v7-devel" -t yay-$(ARCH):${VERSION} .
  53. docker run -e="ARCH=$(ARCH)" --name yay-$(ARCH) yay-$(ARCH):${VERSION} make release VERSION=${VERSION}
  54. docker cp yay-$(ARCH):/app/${PACKAGE} $(PACKAGE)
  55. docker container rm yay-$(ARCH)
  56. .PHONY: docker-release-aarch64
  57. docker-release-aarch64:
  58. docker build --build-arg="BUILD_TAG=arm64v8-devel" -t yay-$(ARCH):${VERSION} .
  59. docker run -e="ARCH=$(ARCH)" --name yay-$(ARCH) yay-$(ARCH):${VERSION} make release VERSION=${VERSION}
  60. docker cp yay-$(ARCH):/app/${PACKAGE} $(PACKAGE)
  61. docker container rm yay-$(ARCH)
  62. .PHONY: docker-release-x86_64
  63. docker-release-x86_64:
  64. docker build --build-arg="BUILD_TAG=devel" -t yay-$(ARCH):${VERSION} .
  65. docker run -e="ARCH=$(ARCH)" --name yay-$(ARCH) yay-$(ARCH):${VERSION} make release VERSION=${VERSION}
  66. docker cp yay-$(ARCH):/app/${PACKAGE} $(PACKAGE)
  67. docker container rm yay-$(ARCH)
  68. .PHONY: docker-build
  69. docker-build:
  70. docker build -t yay-$(ARCH):${VERSION} .
  71. docker run -e="ARCH=$(ARCH)" --name yay-$(ARCH) yay-$(ARCH):${VERSION} make build VERSION=${VERSION}
  72. docker cp yay-$(ARCH):/app/${BIN} $(BIN)
  73. docker container rm yay-$(ARCH)
  74. .PHONY: test-vendor
  75. test-vendor: vendor
  76. @diff=$$(git diff vendor/); \
  77. if [ -n "$$diff" ]; then \
  78. echo "Please run 'make vendor' and commit the result:"; \
  79. echo "$${diff}"; \
  80. exit 1; \
  81. fi;
  82. .PHONY: lint
  83. lint:
  84. golangci-lint run
  85. golint -set_exit_status . ./pkg/...
  86. .PHONY: fmt
  87. fmt:
  88. go fmt ./...
  89. .PHONY: install
  90. install: build ${MOFILES}
  91. install -Dm755 ${BIN} $(DESTDIR)$(PREFIX)/bin/${BIN}
  92. install -Dm644 doc/${PKGNAME}.8 $(DESTDIR)$(PREFIX)/share/man/man8/${PKGNAME}.8
  93. install -Dm644 completions/bash $(DESTDIR)$(PREFIX)/share/bash-completion/completions/${PKGNAME}
  94. install -Dm644 completions/zsh $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_${PKGNAME}
  95. install -Dm644 completions/fish $(DESTDIR)$(PREFIX)/share/fish/vendor_completions.d/${PKGNAME}.fish
  96. for lang in ${LANGS}; do \
  97. install -Dm644 ${LOCALEDIR}/$${lang}.mo $(DESTDIR)$(PREFIX)/share/locale/$$lang/LC_MESSAGES/${PKGNAME}.mo; \
  98. done
  99. .PHONY: uninstall
  100. uninstall:
  101. rm -f $(DESTDIR)$(PREFIX)/bin/${BIN}
  102. rm -f $(DESTDIR)$(PREFIX)/share/man/man8/${PKGNAME}.8
  103. rm -f $(DESTDIR)$(PREFIX)/share/bash-completion/completions/${PKGNAME}
  104. rm -f $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_${PKGNAME}
  105. rm -f $(DESTDIR)$(PREFIX)/share/fish/vendor_completions.d/${PKGNAME}.fish
  106. for lang in ${LANGS}; do \
  107. rm -f $(DESTDIR)$(PREFIX)/share/locale/$$lang/LC_MESSAGES/${PKGNAME}.mo; \
  108. done
  109. $(BIN): $(SOURCES)
  110. $(GO) build $(GOFLAGS) -ldflags '-s -w $(LDFLAGS)' $(EXTRA_GOFLAGS) -o $@
  111. $(RELEASE_DIR):
  112. mkdir $(RELEASE_DIR)
  113. $(PACKAGE): $(BIN) $(RELEASE_DIR)
  114. cp -t $(RELEASE_DIR) ${BIN} doc/${PKGNAME}.8 completions/* ${MOFILES}
  115. tar -czvf $(PACKAGE) $(RELEASE_DIR)
  116. locale: ${MOFILES}
  117. ${LOCALEDIR}/${POTFILE}: ${SOURCES}
  118. xgotext -in . -out po
  119. # xgettext --from-code=UTF-8 -Lc -sc -d ${PKGNAME} -kGet -o ${LOCALEDIR}/${PKGNAME}.pot ${SOURCES}
  120. ${LOCALEDIR}/%.po: ${LOCALEDIR}/${POTFILE}
  121. test -f $@ || msginit -l $* -i $< -o $@
  122. msgmerge -U $@ $<
  123. touch $@
  124. ${LOCALEDIR}/%.mo: ${LOCALEDIR}/%.po
  125. msgfmt $< -o $@