2021-09-30 04:05:52 +08:00
|
|
|
GOCMD=go
|
|
|
|
XGOCMD=xgo -go go-1.17.x
|
|
|
|
GOBUILD=CGO_ENABLED=1 $(GOCMD) build -a -trimpath
|
|
|
|
GOCLEAN=$(GOCMD) clean
|
2018-06-17 08:18:39 +08:00
|
|
|
NAME=clash
|
2021-09-30 04:05:52 +08:00
|
|
|
BINDIR=$(shell pwd)/bin
|
2021-07-01 22:49:29 +08:00
|
|
|
VERSION=$(shell git describe --tags --always 2>/dev/null || date +%F)
|
2019-03-23 19:24:26 +08:00
|
|
|
BUILDTIME=$(shell date -u)
|
2021-09-30 04:05:52 +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 = \
|
2021-09-30 04:05:52 +08:00
|
|
|
darwin-10.12-amd64 \
|
|
|
|
darwin-10.15-arm64 \
|
2019-01-03 10:49:09 +08:00
|
|
|
linux-386 \
|
|
|
|
linux-amd64 \
|
2021-09-30 04:05:52 +08:00
|
|
|
linux-arm64
|
2018-06-17 08:18:39 +08:00
|
|
|
|
2019-01-03 10:49:09 +08:00
|
|
|
WINDOWS_ARCH_LIST = \
|
2021-09-30 04:05:52 +08:00
|
|
|
windows-4.0-amd64 \
|
|
|
|
windows-4.0-386
|
|
|
|
# windows-arm64
|
2019-01-03 10:49:09 +08:00
|
|
|
|
2021-09-30 04:05:52 +08:00
|
|
|
all: linux-amd64 darwin-10.12-amd64 windows-4.0-amd64 # Most used
|
2018-06-17 08:18:39 +08:00
|
|
|
|
2021-09-30 04:05:52 +08:00
|
|
|
build:
|
|
|
|
$(GOBUILD) -ldflags $(RELEASE_LDFLAGS) -o $(BINDIR)/$(NAME)-$@
|
2020-06-21 12:38:14 +08:00
|
|
|
|
2021-09-30 04:05:52 +08:00
|
|
|
darwin-10.12-amd64:
|
|
|
|
$(XGOCMD) -dest=$(BINDIR) -out=$(NAME) -trimpath=true -ldflags=$(RELEASE_LDFLAGS) -targets=darwin-10.12/amd64 $(BUILD_PACKAGE)
|
2018-06-17 08:18:39 +08:00
|
|
|
|
2021-09-30 04:05:52 +08:00
|
|
|
darwin-10.15-arm64:
|
|
|
|
$(XGOCMD) -dest=$(BINDIR) -out=$(NAME) -trimpath=true -ldflags=$(RELEASE_LDFLAGS) -targets=darwin-10.15/arm64 $(BUILD_PACKAGE)
|
2021-02-18 18:15:09 +08:00
|
|
|
|
2019-01-03 10:49:09 +08:00
|
|
|
linux-386:
|
2021-09-30 04:05:52 +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-09-30 04:05:52 +08:00
|
|
|
GOARCH=amd64 GOOS=linux $(GOBUILD) -ldflags $(STATIC_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-09-30 04:05:52 +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
|
|
|
|
2021-09-30 04:05:52 +08:00
|
|
|
windows-4.0-386:
|
|
|
|
$(XGOCMD) -dest=$(BINDIR) -out=$(NAME) -trimpath=true -ldflags=$(RELEASE_LDFLAGS) -targets=windows-4.0/386 $(BUILD_PACKAGE)
|
2019-01-03 10:49:09 +08:00
|
|
|
|
2021-09-30 04:05:52 +08:00
|
|
|
windows-4.0-amd64:
|
|
|
|
$(XGOCMD) -dest=$(BINDIR) -out=$(NAME) -trimpath=true -ldflags=$(RELEASE_LDFLAGS) -targets=windows-4.0/amd64 $(BUILD_PACKAGE)
|
2019-01-03 10:49:09 +08:00
|
|
|
|
2021-09-30 04:05:52 +08:00
|
|
|
#windows-arm64:
|
|
|
|
# $(XGOCMD) -dest=$(BINDIR) -out=$(NAME) -trimpath=true -ldflags=$(RELEASE_LDFLAGS) -targets=windows/arm64 $(BUILD_PACKAGE)
|
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-09-30 04:05:52 +08:00
|
|
|
|
2018-06-17 08:18:39 +08:00
|
|
|
clean:
|
2021-09-30 04:05:52 +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)
|