yay/Makefile

151 lines
4.3 KiB
Makefile
Raw Normal View History

export GO111MODULE=on
2020-03-13 10:55:30 +01:00
GOPROXY ?= https://proxy.golang.org
export GOPROXY
2020-02-28 00:08:35 +01:00
BUILD_TAG = devel
2019-10-04 21:43:42 +02:00
ARCH ?= $(shell uname -m)
BIN := yay
DESTDIR :=
GO ?= go
2019-10-04 21:43:42 +02:00
PKGNAME := yay
PREFIX := /usr/local
2018-12-03 15:51:17 +01:00
MAJORVERSION := 9
2019-10-21 15:34:06 +02:00
MINORVERSION := 4
2020-05-08 18:13:51 +02:00
PATCHVERSION := 7
VERSION ?= ${MAJORVERSION}.${MINORVERSION}.${PATCHVERSION}
2020-05-08 18:13:51 +02:00
LOCALEDIR := po
SYSTEMLOCALEPATH := $(PREFIX)/share/locale/
2020-06-03 19:00:30 +02:00
LANGS := pt en zh_CN
2020-05-30 00:43:18 +02:00
POTFILE := default.pot
POFILES := $(addprefix $(LOCALEDIR)/,$(addsuffix .po,$(LANGS)))
MOFILES := $(POFILES:.po=.mo)
2020-02-28 00:08:35 +01:00
GOFLAGS := -v -mod=mod
2019-10-04 21:43:42 +02:00
EXTRA_GOFLAGS ?=
2020-05-30 00:43:18 +02:00
LDFLAGS := $(LDFLAGS) -X "main.yayVersion=${VERSION}" -X "main.localePath=${SYSTEMLOCALEPATH}"
2019-10-04 21:43:42 +02:00
RELEASE_DIR := ${PKGNAME}_${VERSION}_${ARCH}
PACKAGE := $(RELEASE_DIR).tar.gz
2020-05-30 00:43:18 +02:00
SOURCES ?= $(shell find . -name "*.go" -type f)
2016-12-02 19:22:21 +01:00
.PRECIOUS: ${LOCALEDIR}/%.po
.PHONY: default
2016-09-05 04:32:57 +02:00
default: build
.PHONY: all
all: | clean release
.PHONY: clean
clean:
$(GO) clean $(GOFLAGS) -i ./...
2020-02-28 00:08:35 +01:00
rm -rf $(BIN) $(PKGNAME)_*
.PHONY: test
test:
$(GO) vet $(GOFLAGS) ./...
2019-10-04 21:43:42 +02:00
@test -z "$$(gofmt -l *.go)" || (echo "Files need to be linted. Use make fmt" && false)
$(GO) test $(GOFLAGS) --race -covermode=atomic . ./pkg/...
.PHONY: build
build: $(BIN)
.PHONY: release
release: $(PACKAGE)
.PHONY: docker-release-all
docker-release-all:
2020-02-28 00:08:35 +01:00
make docker-release-armv7h ARCH=armv7h
make docker-release-x86_64 ARCH=x86_64
make docker-release-aarch64 ARCH=aarch64
2018-02-17 19:25:43 +01:00
2020-02-28 00:08:35 +01:00
.PHONY: docker-release-armv7h
docker-release-armv7h:
docker build --build-arg="BUILD_TAG=arm32v7-devel" -t yay-$(ARCH):${VERSION} .
docker run -e="ARCH=$(ARCH)" --name yay-$(ARCH) yay-$(ARCH):${VERSION} make release VERSION=${VERSION}
docker cp yay-$(ARCH):/app/${PACKAGE} $(PACKAGE)
docker container rm yay-$(ARCH)
.PHONY: docker-release-aarch64
docker-release-aarch64:
docker build --build-arg="BUILD_TAG=arm64v8-devel" -t yay-$(ARCH):${VERSION} .
docker run -e="ARCH=$(ARCH)" --name yay-$(ARCH) yay-$(ARCH):${VERSION} make release VERSION=${VERSION}
docker cp yay-$(ARCH):/app/${PACKAGE} $(PACKAGE)
docker container rm yay-$(ARCH)
.PHONY: docker-release-x86_64
docker-release-x86_64:
docker build --build-arg="BUILD_TAG=devel" -t yay-$(ARCH):${VERSION} .
docker run -e="ARCH=$(ARCH)" --name yay-$(ARCH) yay-$(ARCH):${VERSION} make release VERSION=${VERSION}
docker cp yay-$(ARCH):/app/${PACKAGE} $(PACKAGE)
docker container rm yay-$(ARCH)
.PHONY: docker-build
docker-build:
2020-02-28 00:08:35 +01:00
docker build -t yay-$(ARCH):${VERSION} .
docker run -e="ARCH=$(ARCH)" --name yay-$(ARCH) yay-$(ARCH):${VERSION} make build VERSION=${VERSION}
docker cp yay-$(ARCH):/app/${BIN} $(BIN)
docker container rm yay-$(ARCH)
.PHONY: test-vendor
test-vendor: vendor
@diff=$$(git diff vendor/); \
if [ -n "$$diff" ]; then \
echo "Please run 'make vendor' and commit the result:"; \
echo "$${diff}"; \
exit 1; \
fi;
.PHONY: lint
lint:
golangci-lint run
golint -set_exit_status . ./pkg/...
.PHONY: fmt
fmt:
2020-05-30 00:43:18 +02:00
go fmt ./...
.PHONY: install
install: build ${MOFILES}
install -Dm755 ${BIN} $(DESTDIR)$(PREFIX)/bin/${BIN}
install -Dm644 doc/${PKGNAME}.8 $(DESTDIR)$(PREFIX)/share/man/man8/${PKGNAME}.8
install -Dm644 completions/bash $(DESTDIR)$(PREFIX)/share/bash-completion/completions/${PKGNAME}
install -Dm644 completions/zsh $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_${PKGNAME}
install -Dm644 completions/fish $(DESTDIR)$(PREFIX)/share/fish/vendor_completions.d/${PKGNAME}.fish
2020-05-30 00:43:18 +02:00
for lang in ${LANGS}; do \
install -Dm644 ${LOCALEDIR}/$${lang}.mo $(DESTDIR)$(PREFIX)/share/locale/$$lang/LC_MESSAGES/${PKGNAME}.mo; \
done
.PHONY: uninstall
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/${BIN}
rm -f $(DESTDIR)$(PREFIX)/share/man/man8/${PKGNAME}.8
rm -f $(DESTDIR)$(PREFIX)/share/bash-completion/completions/${PKGNAME}
rm -f $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_${PKGNAME}
rm -f $(DESTDIR)$(PREFIX)/share/fish/vendor_completions.d/${PKGNAME}.fish
for lang in ${LANGS}; do \
rm -f $(DESTDIR)$(PREFIX)/share/locale/$$lang/LC_MESSAGES/${PKGNAME}.mo; \
done
2020-05-08 18:13:51 +02:00
$(BIN): $(SOURCES)
$(GO) build $(GOFLAGS) -ldflags '-s -w $(LDFLAGS)' $(EXTRA_GOFLAGS) -o $@
$(RELEASE_DIR):
mkdir $(RELEASE_DIR)
$(PACKAGE): $(BIN) $(RELEASE_DIR)
cp -t $(RELEASE_DIR) ${BIN} doc/${PKGNAME}.8 completions/* ${MOFILES}
tar -czvf $(PACKAGE) $(RELEASE_DIR)
locale:
2020-05-30 00:43:18 +02:00
xgotext -in . -out po
test -f $@ || msginit -l $* -i $< -o $@
msgmerge -U $@ $<
touch $@
${LOCALEDIR}/%.mo: ${LOCALEDIR}/%.po
msgfmt $< -o $@