1- SRC: =config.go ipc.go options.go $(wildcard cmd/open-in-mpv/* )
2- EXT_SRC: =$(wildcard extension/Chrome/* ) extension/Firefox/manifest.json
3- SCRIPTS_DIR: =scripts
4- BUILD_DIR: =build
5-
6- all : $(BUILD_DIR ) /open-in-mpv.tar.gz $(BUILD_DIR ) /linux.tar $(BUILD_DIR ) /mac.tar $(BUILD_DIR ) /windows.tar $(BUILD_DIR ) /firefox.zip
7-
8- builddir :
1+ SRC := config.go ipc.go options.go $(wildcard cmd/open-in-mpv/* )
2+ EXT_SRC := $(wildcard extension/Chrome/* ) extension/Firefox/manifest.json
3+ SCRIPTS_DIR := scripts
4+
5+ TAG_COMMIT := $(shell git rev-list --abbrev-commit --tags --max-count=1)
6+ TAG := $(shell git describe --abbrev=0 --tags ${TAG_COMMIT} 2>/dev/null || true)
7+ COMMIT := $(shell git rev-parse --short HEAD)
8+ DATE_PRETTY := $(shell env TZ=UTC0 git log -1 --format=% cd --date=format:"% Y-% m-% d")
9+ DATE := $(shell env TZ=UTC0 git log -1 --format=% cd --date=format:"% Y% m% d")
10+ VERSION := $(TAG:v%=% )
11+ ifneq ($(COMMIT ) , $(TAG_COMMIT ) )
12+ VERSION := $(VERSION ) -next-$(COMMIT ) -$(DATE )
13+ endif
14+ ifeq ($(VERSION ) ,)
15+ VERSION := $(COMMIT ) -$(DATA )
16+ endif
17+ ifneq ($(shell git status --porcelain) ,)
18+ VERSION := $(VERSION ) -dirty
19+ endif
20+ BUILD_DIR := build/$(VERSION )
21+
22+ LDFLAGS := -s -w -X main.Version=$(TAG ) -X main.BuildDate=$(DATE_PRETTY ) -X main.Commit=$(COMMIT )
23+
24+
25+ all : $(BUILD_DIR ) /open-in-mpv_$(VERSION ) .tar.gz $(BUILD_DIR ) /linux.tar $(BUILD_DIR ) /mac.tar $(BUILD_DIR ) /windows.tar $(BUILD_DIR ) /firefox.zip
26+
27+ $(BUILD_DIR ) :
928 @mkdir -p $(BUILD_DIR ) /linux $(BUILD_DIR ) /windows $(BUILD_DIR ) /mac
1029
11- $(BUILD_DIR ) /open-in-mpv .tar.gz : $(SRC )
30+ $(BUILD_DIR ) /open-in-mpv_ $( VERSION ) .tar.gz : $(SRC )
1231 @echo -e " \n# Creating tarball"
1332 go mod vendor
14- tar czf $(BUILD_DIR ) /open-in-mpv .tar.gz --transform " s,^,open-in-mpv /," --exclude $(BUILD_DIR ) *
33+ tar czf $(BUILD_DIR ) /open-in-mpv_ $( VERSION ) .tar.gz --transform " s,^,open-in-mpv_ $( VERSION ) /," --exclude $(BUILD_DIR ) *
1534 rm -rf vendor
1635
17- $(BUILD_DIR ) /linux/open-in-mpv : $(SRC ) builddir
36+ $(BUILD_DIR ) /linux/open-in-mpv : $(SRC ) $( BUILD_DIR )
1837 @echo -e " \n# Building for Linux"
19- env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags=" -s -w " -o $@ ./cmd/open-in-mpv
38+ env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags=" $( LDFLAGS ) " -o $@ ./cmd/open-in-mpv
2039 cp $(SCRIPTS_DIR ) /install-protocol.sh $(dir $@ )
2140 cp $(SCRIPTS_DIR ) /open-in-mpv.desktop $(dir $@ )
2241
2342$(BUILD_DIR ) /linux.tar : $(BUILD_DIR ) /linux/open-in-mpv
2443 tar cf $@ -C $(dir $@ ) linux $(notdir $(wildcard $(BUILD_DIR ) /linux/* ) )
2544
26- $(BUILD_DIR ) /mac/open-in-mpv.app : $(SRC ) scripts/Info.plist builddir
45+ $(BUILD_DIR ) /mac/open-in-mpv.app : $(SRC ) scripts/Info.plist $( BUILD_DIR )
2746 @# See https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html
2847 @# and https://apple.stackexchange.com/questions/253184/associating-protocol-handler-in-mac-os-x
2948 @echo -e " \n# Building MacOS app bundle"
3049 @mkdir -p $@ /Contents/MacOS
3150 go install github.com/randall77/makefat@latest
32- env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags=" -s -w " -o $(dir $@ ) open-in-mpv.amd64 ./cmd/open-in-mpv
33- env CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags=" -s -w " -o $(dir $@ ) open-in-mpv.arm64 ./cmd/open-in-mpv
51+ env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags=" $( LDFLAGS ) " -o $(dir $@ ) open-in-mpv.amd64 ./cmd/open-in-mpv
52+ env CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags=" $( LDFLAGS ) " -o $(dir $@ ) open-in-mpv.arm64 ./cmd/open-in-mpv
3453 $(GOBIN ) /makefat $@ /Contents/MacOS/open-in-mpv $(dir $@ ) open-in-mpv.amd64 $(dir $@ ) open-in-mpv.arm64
3554 cp config.yml $@ /Contents/MacOS/
3655 cp $(SCRIPTS_DIR ) /Info.plist $@ /Contents
3756
3857$(BUILD_DIR ) /mac.tar : $(BUILD_DIR ) /mac/open-in-mpv.app
3958 tar cf $@ -C $(dir $@ ) /mac open-in-mpv.app
4059
41- $(BUILD_DIR ) /windows/open-in-mpv.exe : $(SRC ) builddir
60+ $(BUILD_DIR ) /windows/open-in-mpv.exe : $(SRC ) $( BUILD_DIR )
4261 @echo -e " \n# Building for Windows"
43- env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags=" -s -w -H windowsgui" -o $@ ./cmd/open-in-mpv
62+ env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags=" $( LDFLAGS ) -H windowsgui" -o $@ ./cmd/open-in-mpv
4463 cp $(SCRIPTS_DIR ) /install-protocol.reg $(dir $@ )
4564
4665$(BUILD_DIR ) /windows.tar : $(BUILD_DIR ) /windows/open-in-mpv.exe
@@ -62,9 +81,9 @@ uninstall:
6281 rm /usr/bin/open-in-mpv
6382
6483clean :
65- rm -rf $(BUILD_DIR ) / *
84+ rm -rf $(dir $( BUILD_DIR )) *
6685
6786test :
6887 go test ./...
6988
70- .PHONY : all builddir install install-protocol uninstall clean test
89+ .PHONY : all install install-protocol uninstall clean test
0 commit comments