Clash.Meta/Makefile

94 lines
3.3 KiB
Makefile
Raw Normal View History

2021-11-17 16:03:47 +08:00
GOCMD=go
XGOCMD=xgo -go=go-1.17.x
GOBUILD=CGO_ENABLED=1 $(GOCMD) build -trimpath
GOCLEAN=$(GOCMD) clean
2018-06-17 08:18:39 +08:00
NAME=clash
2021-11-17 16:03:47 +08:00
BINDIR=$(shell pwd)/bin
VERSION=$(shell git describe --tags --always 2>/dev/null || date +%F)
2019-03-23 19:24:26 +08:00
BUILDTIME=$(shell date -u)
2021-11-17 16:03:47 +08:00
BUILD_PACKAGE=.
RELEASE_LDFLAGS='-X "github.com/Dreamacro/clash/constant.Version=$(VERSION)" \
-X "github.com/Dreamacro/clash/constant.BuildTime=$(BUILDTIME)" \
-w -s -buildid='
STATIC_LDFLAGS='-X "github.com/Dreamacro/clash/constant.Version=$(VERSION)" \
-X "github.com/Dreamacro/clash/constant.BuildTime=$(BUILDTIME)" \
-extldflags "-static" \
-w -s -buildid='
2018-06-17 08:18:39 +08:00
2019-01-03 10:49:09 +08:00
PLATFORM_LIST = \
darwin-amd64 \
darwin-arm64 \
2021-11-17 16:03:47 +08:00
linux-amd64
# linux-arm64
# linux-386
2018-06-17 08:18:39 +08:00
2019-01-03 10:49:09 +08:00
WINDOWS_ARCH_LIST = \
windows-amd64 \
2021-11-17 16:03:47 +08:00
windows-386
# windows-arm64
2019-01-03 10:49:09 +08:00
all: linux-amd64 darwin-amd64 windows-amd64 # Most used
2018-06-17 08:18:39 +08:00
2021-11-17 16:03:47 +08:00
build:
$(GOBUILD) -ldflags $(RELEASE_LDFLAGS) -tags build_local -o $(BINDIR)/$(NAME)-$@
2020-06-21 12:38:14 +08:00
2019-01-03 10:49:09 +08:00
darwin-amd64:
2021-11-17 16:03:47 +08:00
$(XGOCMD) -dest=$(BINDIR) -out=$(NAME) -trimpath=true -ldflags=$(RELEASE_LDFLAGS) -targets=darwin-10.12/amd64 $(BUILD_PACKAGE) && \
mv $(BINDIR)/$(NAME)-darwin-10.12-amd64 $(BINDIR)/$(NAME)-darwin-amd64
2018-06-17 08:18:39 +08:00
darwin-arm64:
2021-11-17 16:03:47 +08:00
$(XGOCMD) -dest=$(BINDIR) -out=$(NAME) -trimpath=true -ldflags=$(RELEASE_LDFLAGS) -targets=darwin-11.1/arm64 $(BUILD_PACKAGE) && \
mv $(BINDIR)/$(NAME)-darwin-11.1-arm64 $(BINDIR)/$(NAME)-darwin-arm64
2019-01-03 10:49:09 +08:00
linux-386:
2021-11-17 16:03:47 +08:00
$(XGOCMD) -dest=$(BINDIR) -out=$(NAME) -trimpath=true -ldflags=$(STATIC_LDFLAGS) -targets=linux/386 $(BUILD_PACKAGE)
2019-01-03 10:49:09 +08:00
linux-amd64:
2021-11-17 16:03:47 +08:00
$(GOBUILD) -ldflags $(RELEASE_LDFLAGS) -o $(BINDIR)/$(NAME)-$@
#GOARCH=amd64 GOOS=linux $(GOBUILD) -ldflags $(RELEASE_LDFLAGS) -o $(BINDIR)/$(NAME)-$@
#$(XGOCMD) -dest=$(BINDIR) -out=$(NAME) -trimpath=true -ldflags=$(STATIC_LDFLAGS) -targets=linux/amd64 $(BUILD_PACKAGE)
2019-01-03 10:49:09 +08:00
2021-11-17 16:03:47 +08:00
linux-arm64:
$(XGOCMD) -dest=$(BINDIR) -out=$(NAME) -trimpath=true -ldflags=$(STATIC_LDFLAGS) -targets=linux/arm64 $(BUILD_PACKAGE)
2019-01-03 10:49:09 +08:00
windows-386:
2021-11-17 16:03:47 +08:00
$(XGOCMD) -dest=$(BINDIR) -out=$(NAME) -trimpath=true -ldflags=$(RELEASE_LDFLAGS) -targets=windows-4.0/386 $(BUILD_PACKAGE) && \
mv $(BINDIR)/$(NAME)-windows-4.0-386.exe $(BINDIR)/$(NAME)-windows-386.exe
2018-06-20 23:00:16 +08:00
2019-01-03 10:49:09 +08:00
windows-amd64:
2021-11-17 16:03:47 +08:00
$(XGOCMD) -dest=$(BINDIR) -out=$(NAME) -trimpath=true -ldflags=$(RELEASE_LDFLAGS) -targets=windows-4.0/amd64 $(BUILD_PACKAGE) && \
mv $(BINDIR)/$(NAME)-windows-4.0-amd64.exe $(BINDIR)/$(NAME)-windows-amd64.exe
2021-08-18 13:26:23 +08:00
2021-11-17 16:03:47 +08:00
#windows-arm64:
# $(XGOCMD) -dest=$(BINDIR) -out=$(NAME) -trimpath=true -ldflags=$(RELEASE_LDFLAGS) -targets=windows/arm64 $(BUILD_PACKAGE)
# mv $(NAME)-windows-4.0-arm64.exe $(NAME)-windows-arm64.exe
2019-01-03 10:49:09 +08:00
gz_releases=$(addsuffix .gz, $(PLATFORM_LIST))
zip_releases=$(addsuffix .zip, $(WINDOWS_ARCH_LIST))
$(gz_releases): %.gz : %
chmod +x $(BINDIR)/$(NAME)-$(basename $@)
2019-03-30 15:34:24 +08:00
gzip -f -S -$(VERSION).gz $(BINDIR)/$(NAME)-$(basename $@)
2019-01-03 10:49:09 +08:00
$(zip_releases): %.zip : %
2019-03-23 19:24:26 +08:00
zip -m -j $(BINDIR)/$(NAME)-$(basename $@)-$(VERSION).zip $(BINDIR)/$(NAME)-$(basename $@).exe
2019-01-03 10:49:09 +08:00
all-arch: $(PLATFORM_LIST) $(WINDOWS_ARCH_LIST)
2018-06-17 08:18:39 +08:00
2019-01-03 10:49:09 +08:00
releases: $(gz_releases) $(zip_releases)
2021-10-10 23:44:09 +08:00
2021-11-17 16:03:47 +08:00
vet:
$(GOCMD) vet -tags build_local ./...
2021-10-10 23:44:09 +08:00
lint:
2021-11-17 16:03:47 +08:00
golangci-lint run --build-tags=build_local --disable-all -E govet -E gofumpt -E megacheck ./...
2021-10-10 23:44:09 +08:00
2018-06-17 08:18:39 +08:00
clean:
2021-11-17 16:03:47 +08:00
rm -rf $(BINDIR)/
mkdir -p $(BINDIR)
cleancache:
# go build cache may need to cleanup if changing C source code
$(GOCLEAN) -cache
rm -rf $(BINDIR)/
mkdir -p $(BINDIR)