2019-09-26 12:45:48 +02:00
|
|
|
export GO111MODULE=on
|
2018-03-23 05:23:16 +01:00
|
|
|
|
2019-10-04 21:43:42 +02:00
|
|
|
ARCH ?= $(shell uname -m)
|
2019-09-26 12:45:48 +02:00
|
|
|
BIN := yay
|
2018-03-23 05:23:16 +01:00
|
|
|
DESTDIR :=
|
2019-09-26 12:45:48 +02:00
|
|
|
GO ?= go
|
2019-10-04 21:43:42 +02:00
|
|
|
PKGNAME := yay
|
|
|
|
PREFIX := /usr/local
|
2018-03-23 05:23:16 +01:00
|
|
|
|
2018-12-03 15:51:17 +01:00
|
|
|
MAJORVERSION := 9
|
2019-09-26 12:45:48 +02:00
|
|
|
MINORVERSION := 3
|
2019-10-05 12:16:58 +02:00
|
|
|
PATCHVERSION := 3
|
2018-10-08 19:46:51 +02:00
|
|
|
VERSION ?= ${MAJORVERSION}.${MINORVERSION}.${PATCHVERSION}
|
2018-03-23 05:23:16 +01:00
|
|
|
|
2019-10-05 12:16:58 +02:00
|
|
|
GOFLAGS := -v -mod=vendor
|
2019-10-04 21:43:42 +02:00
|
|
|
EXTRA_GOFLAGS ?=
|
|
|
|
LDFLAGS := $(LDFLAGS) -X "main.version=${VERSION}"
|
|
|
|
|
2019-09-26 12:45:48 +02:00
|
|
|
RELEASE_DIR := ${PKGNAME}_${VERSION}_${ARCH}
|
|
|
|
PACKAGE := $(RELEASE_DIR).tar.gz
|
2019-10-05 12:16:58 +02:00
|
|
|
SOURCES ?= $(shell find . -name "*.go" -type f ! -path "./vendor/*")
|
2016-12-02 19:22:21 +01:00
|
|
|
|
2019-09-26 12:45:48 +02:00
|
|
|
.PHONY: default
|
2016-09-05 04:32:57 +02:00
|
|
|
default: build
|
|
|
|
|
2019-10-10 17:37:37 +02:00
|
|
|
.PHONY: all
|
|
|
|
all: | clean release
|
|
|
|
|
2019-09-26 12:45:48 +02:00
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
2019-10-05 12:16:58 +02:00
|
|
|
$(GO) clean $(GOFLAGS) -i ./...
|
2019-09-26 12:45:48 +02:00
|
|
|
rm -rf $(BIN) $(PKGNAME)_$(VERSION)_*
|
|
|
|
|
|
|
|
.PHONY: test
|
2019-10-05 12:16:58 +02:00
|
|
|
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)
|
2019-10-05 12:16:58 +02:00
|
|
|
$(GO) test $(GOFLAGS) --race -covermode=atomic . ./pkg/...
|
2019-09-26 12:45:48 +02:00
|
|
|
|
|
|
|
.PHONY: build
|
|
|
|
build: $(BIN)
|
|
|
|
|
|
|
|
.PHONY: release
|
|
|
|
release: $(PACKAGE)
|
|
|
|
|
|
|
|
$(BIN): $(SOURCES)
|
2019-10-05 12:16:58 +02:00
|
|
|
$(GO) build $(GOFLAGS) -ldflags '-s -w $(LDFLAGS)' $(EXTRA_GOFLAGS) -o $@
|
2019-09-26 12:45:48 +02:00
|
|
|
|
|
|
|
$(RELEASE_DIR):
|
|
|
|
mkdir $(RELEASE_DIR)
|
|
|
|
|
|
|
|
$(PACKAGE): $(BIN) $(RELEASE_DIR)
|
|
|
|
cp -t $(RELEASE_DIR) ${BIN} doc/${PKGNAME}.8 completions/*
|
|
|
|
tar -czvf $(PACKAGE) $(RELEASE_DIR)
|
|
|
|
|
|
|
|
.PHONY: docker-release-all
|
|
|
|
docker-release-all:
|
|
|
|
make docker-release ARCH=x86_64
|
|
|
|
make docker-release ARCH=armv7h
|
|
|
|
make docker-release ARCH=aarch64
|
2018-02-17 19:25:43 +01:00
|
|
|
|
2019-09-26 12:45:48 +02:00
|
|
|
.PHONY: docker-release
|
|
|
|
docker-release:
|
|
|
|
docker build --target builder_env --build-arg BUILD_ARCH="$(ARCH)" -t yay-$(ARCH):${VERSION} .
|
|
|
|
docker run -e="ARCH=$(ARCH)" --name yay-$(ARCH) yay-$(ARCH):${VERSION} make release
|
|
|
|
docker cp yay-$(ARCH):/app/${PACKAGE} $(PACKAGE)
|
|
|
|
docker container rm yay-$(ARCH)
|
|
|
|
|
|
|
|
.PHONY: docker-build
|
|
|
|
docker-build:
|
2019-10-05 02:04:01 +02:00
|
|
|
docker build --target builder --build-arg BUILD_ARCH="$(ARCH)" -t yay-build-$(ARCH):${VERSION} .
|
|
|
|
docker run -e="ARCH=$(ARCH)" --name yay-build-${ARCH} yay-build-${ARCH}:${VERSION} /bin/sh
|
2019-09-26 12:45:48 +02:00
|
|
|
docker cp yay-build-${ARCH}:/app/${BIN} ${BIN}
|
|
|
|
docker container rm yay-build-${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;
|
|
|
|
|
2019-10-05 12:16:58 +02:00
|
|
|
.PHONY: fmt
|
|
|
|
fmt:
|
|
|
|
#go fmt -mod=vendor $(GOFILES) ./... Doesn't work yet but will be supported soon
|
|
|
|
gofmt -s -w $(SOURCES)
|
|
|
|
|
2019-09-26 12:45:48 +02:00
|
|
|
.PHONY: vendor
|
|
|
|
vendor:
|
|
|
|
$(GO) mod tidy && $(GO) mod vendor
|
|
|
|
|
|
|
|
.PHONY: install
|
2016-10-05 18:04:16 +02:00
|
|
|
install:
|
2019-09-26 12:45:48 +02:00
|
|
|
install -Dm755 ${BIN} $(DESTDIR)$(PREFIX)/bin/${BIN}
|
2018-03-23 05:23:16 +01:00
|
|
|
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
|
|
|
|
|
2019-09-26 12:45:48 +02:00
|
|
|
.PHONY: uninstall
|
2018-03-23 05:23:16 +01:00
|
|
|
uninstall:
|
2019-09-26 12:45:48 +02:00
|
|
|
rm -f $(DESTDIR)$(PREFIX)/bin/${BIN}
|
2018-03-23 05:23:16 +01:00
|
|
|
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
|