-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
77 lines (62 loc) · 2.2 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
SRC := $(shell find . -type f -name '*.go'; echo go.mod)
TAGS := $(shell pkg-config mpv || echo nolibmpv)
VERSION := $(shell git describe)
BUILD_FLAGS := -ldflags "-X main.version=$(VERSION)" -tags '$(TAGS)'
BINS := ym ym-cache ym-files
OS := linux darwin windows
CROSS := $(foreach bin,$(BINS),$(foreach os,$(OS),$(if $(findstring windows,$(os)),dist/$(bin).$(os).exe,dist/$(bin).$(os))))
NATIVE := $(foreach bin,$(BINS),dist/$(bin).native)
RELEASE := $(foreach bin,$(BINS),$(foreach os,$(OS),$(if $(findstring windows,$(os)),dist/release/$(os)/$(bin)-nolibmpv.exe,dist/release/$(os)/$(bin)-nolibmpv)))
.PHONY: all
all: $(NATIVE)
dist/ym.native: $(SRC) | dist
go build $(BUILD_FLAGS) -o $@ ./cmd/ym/*.go
dist/ym-%.native: $(SRC) | dist
go build $(BUILD_FLAGS) -o $@ ./cmd/$(shell basename "$@" | cut -d'.' -f1)/*.go
dist/ym%: $(SRC) | dist
gox $(BUILD_FLAGS) \
-tags 'nolibmpv' \
-osarch="$(shell echo "$@" | cut -d'.' -f2 | rev | cut -d'-' -f1 | rev)/amd64" \
-output="$(shell echo "$@" | cut -d'.' -f-2)" ./cmd/$(shell basename "$@" | cut -d'.' -f1)
dist:
@mkdir dist 2>/dev/null || true
dist/release/%: cross
@mkdir dist/release 2>/dev/null || true
@os="$$(dirname "$*")"; \
mkdir "$$(dirname "$@")" 2>/dev/null; \
src="$$(basename "$*" | sed "s/-nolibmpv/.$$os/")"; \
cp "dist/$$src" "$@";
.PHONY: run
run: dist/ym.native
./dist/ym.native
.PHONY: install
install:
@for i in $(BINS); do \
go install $(BUILD_FLAGS) github.com/frizinak/ym/cmd/$$i; \
done
.PHONY: complete
complete:
go build -i -buildmode=default -tags '$(TAGS)' -o /dev/null ./cmd/ym/*.go
.PHONY: cross
cross: $(CROSS)
.PHONY: release
release: reset-release $(RELEASE)
@if ! echo "$(TAGS)" | grep nolibmpv > /dev/null; then \
$(MAKE) all; \
for i in dist/ym*.native; do cp "$$i" "dist/release/linux/$$(basename $$i | cut -d '.' -f1)" ; done; \
fi
@cd dist/release && for i in ./*; do \
if [ ! -d "$$i" ]; then continue; fi; \
if echo "$$i" | grep 'windows' >/dev/null; then \
zip -r "$$i" "$$i"; \
continue; \
fi; \
tar -zcf "$$i.tar.gz" "$$(basename $$i)"; \
done
@echo -e "\033[1;30;42m Release: $(VERSION) \033[0m"
.PHONY: reset
reset:
-rm -rf dist
.PHONY: reset-release
reset-release:
-rm -rf dist/release