-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
113 lines (91 loc) · 3.11 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
export GO111MODULE=on
ARCH ?= $(shell uname -m)
BIN := yay
DESTDIR :=
GO ?= go
PKGNAME := yay
PREFIX := /usr/local
MAJORVERSION := 9
MINORVERSION := 4
PATCHVERSION := 2
VERSION ?= ${MAJORVERSION}.${MINORVERSION}.${PATCHVERSION}
GOFLAGS := -v -mod=vendor
EXTRA_GOFLAGS ?=
LDFLAGS := $(LDFLAGS) -X "main.version=${VERSION}"
RELEASE_DIR := ${PKGNAME}_${VERSION}_${ARCH}
PACKAGE := $(RELEASE_DIR).tar.gz
SOURCES ?= $(shell find . -name "*.go" -type f ! -path "./vendor/*")
.PHONY: default
default: build
.PHONY: all
all: | clean release
.PHONY: clean
clean:
$(GO) clean $(GOFLAGS) -i ./...
rm -rf $(BIN) $(PKGNAME)_$(VERSION)_*
.PHONY: test
test:
$(GO) vet $(GOFLAGS) ./...
@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)
$(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/*
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
.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 VERSION=${VERSION}
docker cp yay-$(ARCH):/app/${PACKAGE} $(PACKAGE)
docker container rm yay-$(ARCH)
.PHONY: docker-build
docker-build:
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
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;
.PHONY: lint
lint:
golangci-lint run
golint -set_exit_status . ./pkg/...
.PHONY: fmt
fmt:
#go fmt -mod=vendor $(GOFILES) ./... Doesn't work yet but will be supported soon
gofmt -s -w $(SOURCES)
.PHONY: vendor
vendor:
$(GO) mod tidy && $(GO) mod vendor
.PHONY: install
install:
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
.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