-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
91 lines (70 loc) · 2.88 KB
/
Makefile
File metadata and controls
91 lines (70 loc) · 2.88 KB
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
APP := $(shell basename -s .git $(shell git remote get-url origin))
VERSION := $(shell git describe --tags --abbrev=0)-$(shell git rev-parse --short HEAD)
REGISTRY := ghcr.io/piavik
#defaults
TARGETOS ?= linux
TARGETARCH ?= amd64
BIN_DIR := .
.DELETE_ON_ERROR:
format:
@gofmt -s -w .
vet:
@go vet ./...
lint: vet
@which golangci-lint > /dev/null || (curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.1.6)
@golangci-lint run ./...
test:
@go test -v
# install dependencies
deps:
@#which go > /dev/null || wget https://go.dev/dl/go1.24.3.linux-amd64.tar.gz && tar -C /usr/local -xzf go1.24.3.linux-amd64.tar.gz && set PATH=${PATH}:/usr/local/go/bin; export PATH
@go mod tidy
@go mod download
# build binary for TARGETOS:TARGETARCH platform
build: format deps vet test
@echo "Compiling binary executable for TARGETOS=${TARGETOS} TARGETARCH=${TARGETARCH}"
@CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -v -o ${BIN_DIR}/kbot \
-ldflags "-X="github.com/piavik/kbot/cmd.appVersion=${VERSION}
# build docker image for TARGETOS:TARGETARCH platform
image:
@echo "Creating docker image for TARGETOS=${TARGETOS} TARGETARCH=${TARGETARCH}"
@docker build . -t ${REGISTRY}/${APP}:${VERSION}-${TARGETARCH} \
--build-arg TARGETARCH=${TARGETARCH} \
--build-arg TARGETOS=${TARGETOS} \
--build-arg VERSION=${VERSION}
# build preset TARGETOS:TARGETARCH
linux_amd64:
@$(eval TARGETOS=linux)
@$(eval TARGETARCH=amd64)
@$(MAKE) build TARGETOS=${TARGETOS} TARGETARCH=${TARGETARCH} BIN_DIR=./${TARGETOS}/${TARGETARCH} --no-print-directory
linux_arm64:
@$(eval TARGETOS=linux)
@$(eval TARGETARCH=arm64)
@$(MAKE) build TARGETOS=${TARGETOS} TARGETARCH=${TARGETARCH} BIN_DIR=./${TARGETOS}/${TARGETARCH} --no-print-directory
darwin_amd64:
@$(eval TARGETOS=darwin)
@$(eval TARGETARCH=amd64)
@$(MAKE) build TARGETOS=${TARGETOS} TARGETARCH=${TARGETARCH} BIN_DIR=./${TARGETOS}/${TARGETARCH} --no-print-directory
darwin_arm64:
@$(eval TARGETOS=darwin)
@$(eval TARGETARCH=arm64)
@$(MAKE) build TARGETOS=${TARGETOS} TARGETARCH=${TARGETARCH} BIN_DIR=./${TARGETOS}/${TARGETARCH} --no-print-directory
windows_amd64:
@$(eval TARGETOS=windows)
@$(eval TARGETARCH=amd64)
@$(MAKE) build TARGETOS=${TARGETOS} TARGETARCH=${TARGETARCH} BIN_DIR=./${TARGETOS}/${TARGETARCH} --no-print-directory
windows_arm64:
@$(eval TARGETOS=windows)
@$(eval TARGETARCH=arm64)
@$(MAKE) build TARGETOS=${TARGETOS} TARGETARCH=${TARGETARCH} BIN_DIR=./${TARGETOS}/${TARGETARCH} --no-print-directory
linux: linux_amd64 linux_arm64 ;
darwin: darwin_amd64 darwin_arm64 ;
windows: windows_amd64 windows_arm64 ;
build_all: linux darwin windows ;
push:
@docker push ${REGISTRY}/${APP}:${VERSION}-${TARGETARCH}
clean:
@rm -rf kbot*
@for dir in linux darwin windows; do rm -rf $$dir; done
@docker rmi -f ${REGISTRY}/${APP}:${VERSION}-${TARGETARCH} 2>/dev/null || true