mihomo/Makefile

87 lines
3.1 KiB
Makefile
Raw Normal View History

GOCMD=go
2021-10-15 14:11:14 +08:00
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
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)
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-10-21 20:22:23 +08:00
darwin-amd64 \
darwin-arm64 \
2019-01-03 10:49:09 +08:00
linux-amd64 \
linux-arm64
2021-10-21 20:22:23 +08:00
# linux-386
2018-06-17 08:18:39 +08:00
2019-01-03 10:49:09 +08:00
WINDOWS_ARCH_LIST = \
2021-10-21 20:22:23 +08:00
windows-amd64 \
windows-386
# windows-arm64
2019-01-03 10:49:09 +08:00
2021-10-21 20:22:23 +08:00
all: linux-amd64 darwin-amd64 windows-amd64 # Most used
2018-06-17 08:18:39 +08:00
build:
2021-10-21 20:22:23 +08:00
$(GOBUILD) -ldflags $(RELEASE_LDFLAGS) -tags build_local -o $(BINDIR)/$(NAME)-$@
2020-06-21 12:38:14 +08:00
2021-10-21 20:22:23 +08:00
darwin-amd64:
$(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
2021-10-21 20:22:23 +08:00
darwin-arm64:
$(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:
$(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:
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
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-10-21 20:22:23 +08:00
windows-386:
$(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
2019-01-03 10:49:09 +08:00
2021-10-21 20:22:23 +08:00
windows-amd64:
$(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
2019-01-03 10:49:09 +08:00
#windows-arm64:
# $(XGOCMD) -dest=$(BINDIR) -out=$(NAME) -trimpath=true -ldflags=$(RELEASE_LDFLAGS) -targets=windows/arm64 $(BUILD_PACKAGE)
2021-10-21 20:22:23 +08:00
# 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)
2018-06-17 08:18:39 +08:00
clean:
2021-10-15 14:11:14 +08:00
rm -rf $(BINDIR)/
mkdir -p $(BINDIR)
cleancache:
# go build cache may need to cleanup if changing C source code
$(GOCLEAN) -cache
2021-10-15 14:11:14 +08:00
rm -rf $(BINDIR)/
mkdir -p $(BINDIR)