-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
73 lines (57 loc) · 2.04 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
VERSION = 0.2.0
RELEASE = 5
DIST_DIR = $(shell pwd)/dist
#OS :=$(shell awk -F= '/^ID/{print $$2}' /etc/os-release)
#BUILDROOT ?=
# Docker command to use, can be podman
DOCKER ?= docker
##@ Build
build: fmt lint vet
go build -mod=vendor -o bin/flotta main.go
LINT_IMAGE=golangci/golangci-lint:v1.45.0
lint: ## Check if the go code is properly written, rules are in .golangci.yml
$(DOCKER) run --rm -v $(CURDIR):$(CURDIR):z -w="$(CURDIR)" $(LINT_IMAGE) sh -c 'golangci-lint run'
fmt: ## Run go fmt against code.
go fmt ./...
vet: ## Run go vet against code.
go vet ./...
##@ Development
cobra: ## Download cobra locally if necessary.
ifeq (, $(shell which cobra))
@(cd /tmp && go get github.com/mitchellh/[email protected])
@(cd /tmp/ && go get github.com/spf13/[email protected])
$(call go-install-tool,$(COBRA),github.com/spf13/[email protected])
endif
vendor:
go mod tidy -go=1.17
go mod vendor
rpm-tarball:
(git archive --prefix flotta-dev-cli-$(VERSION)/ HEAD ) \
| gzip > flotta-dev-cli-$(VERSION).tar.gz
rpm-src: rpm-tarball
install -D -m644 flotta-dev-cli-$(VERSION).tar.gz --target-directory `rpmbuild -E %_sourcedir`
rpmbuild -bs \
-D "VERSION $(VERSION)" \
-D "RELEASE $(RELEASE)" \
--buildroot $(DIST_DIR) ./flotta-dev-cli.spec
rpm-copr-testing: rpm-src
copr build project-flotta/flotta-testing $(HOME)/rpmbuild/SRPMS/flotta-dev-cli-$(VERSION)-$(RELEASE).*.src.rpm
rpm-copr: rpm-src
copr build project-flotta/flotta $(HOME)/rpmbuild/SRPMS/flotta-dev-cli-$(VERSION)-$(RELEASE).*.src.rpm
rpm-build: rpm-src
rpmbuild $(RPMBUILD_OPTS) --rebuild $(HOME)/rpmbuild/SRPMS/flotta-dev-cli-$(VERSION)-$(RELEASE).*.src.rpm
rpm: ## Create rpm build
RPMBUILD_OPTS=--target=x86_64 $(MAKE) rpm-build
# go-install-tool will 'go install' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-install-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef