-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
96 lines (71 loc) · 2.19 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
BINDIR := $(CURDIR)/bin
INSTALL_PATH ?= /usr/local/bin
DIST_DIRS := find * -type d -exec
PLATFORMS := darwin/arm64 darwin/amd64 linux/arm64 linux/amd64
BINNAME ?= mangathr
# go
PKG := ./...
LDFLAGS := -w -s
# Rebuild the binary if any of these files change
SRC := $(shell find . -type f -name '*.go' -print) go.mod go.sum
SHELL = /usr/bin/env sh
# git
GIT_COMMIT = $(shell git rev-parse HEAD)
GIT_SHA = $(shell git rev-parse --short HEAD)
GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
LDFLAGS += -X github.com/browningluke/mangathr/v2/internal/version.sha=${GIT_SHA}
ifdef VERSION
BINARY_VERSION = $(VERSION)
endif
BINARY_VERSION ?= ${GIT_TAG}
# Only set Version if building a tag or VERSION is set
ifneq ($(BINARY_VERSION),)
LDFLAGS += -X github.com/browningluke/mangathr/v2/internal/version.version=${BINARY_VERSION}
endif
# Default target
.PHONY: all
all: build
# install dependencies (for docker caching)
deps:
go mod download
go mod verify
# build
.PHONY: build
build: $(BINDIR)/$(BINNAME)
$(BINDIR)/$(BINNAME): $(SRC)
go build -trimpath -ldflags '$(LDFLAGS)' -o '$(BINDIR)'/$(BINNAME) ./cmd/mangathr
# install
.PHONY: install
install: build
@install "$(BINDIR)/$(BINNAME)" "$(INSTALL_PATH)/$(BINNAME)"
# Release
# Build for all platforms
cross-build: LDFLAGS += -extldflags "-static"
cross-build: $(PLATFORMS)
@echo "Build complete for all platforms."
# Define the build rule for each platform
$(PLATFORMS):
@platform=$@; \
GOARCH=$$(echo $$platform | cut -d'/' -f2) ; \
GOOS=$$(echo $$platform | cut -d'/' -f1) ; \
echo "Building for $$GOOS/$$GOARCH"; \
mkdir -p dist/$$GOOS-$$GOARCH; \
GOARCH=$$GOARCH GOOS=$$GOOS go build -o dist/$$GOOS-$$GOARCH/ -trimpath -ldflags '$(LDFLAGS)' $(PKG)
.PHONY: dist
dist:
( \
cd dist && \
$(DIST_DIRS) cp ../LICENSE {} \; && \
$(DIST_DIRS) cp ../README.md {} \; && \
$(DIST_DIRS) tar -czf mangathr-${VERSION}-{}.tar.gz {} \; && \
$(DIST_DIRS) zip -r mangathr-${VERSION}-{}.zip {} \; \
)
# Misc
.PHONY: clean
clean:
@rm -rf '$(BINDIR)' ./dist
.PHONY: info
info:
@echo "Version: ${VERSION}"
@echo "Git Tag: ${GIT_TAG}"
@echo "Git Commit: ${GIT_COMMIT}"