Skip to content

Commit

Permalink
perf: 优化 Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
wojiushixiaobai committed Jan 3, 2024
1 parent 64efe74 commit 4640246
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
env:
VERSION: ${{ steps.get_version.outputs.TAG }}
run: |
make && ls build
make all -s && ls build
- name: Release Upload Assets
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
Expand Down
93 changes: 36 additions & 57 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ BuildTime:=$(shell date -u '+%Y-%m-%d %I:%M:%S%p')
COMMIT:=$(shell git rev-parse HEAD)
GOVERSION:=$(shell go version)

GOOS:=$(shell go env GOOS)
GOARCH:=$(shell go env GOARCH)

LDFLAGS=-w -s

GOLDFLAGS=-X 'github.com/jumpserver/wisp/cmd.Version=$(VERSION)'
Expand All @@ -13,80 +16,56 @@ GOLDFLAGS+=-X 'github.com/jumpserver/wisp/cmd.GitCommit=$(COMMIT)'
GOLDFLAGS+=-X 'github.com/jumpserver/wisp/cmd.GoVersion=$(GOVERSION)'
WISPBUILD=CGO_ENABLED=0 go build -trimpath -ldflags "$(GOLDFLAGS) ${LDFLAGS}"

PLATFORM_LIST = \
darwin-amd64 \
darwin-arm64 \
linux-amd64 \
linux-arm64 \
linux-s390x \
linux-ppc64le

WINDOWS_ARCH_LIST = \
windows-amd64

all-arch: $(PLATFORM_LIST) $(WINDOWS_ARCH_LIST)
define make_artifact_full
GOOS=$(1) GOARCH=$(2) $(WISPBUILD) -o $(BUILDDIR)/$(NAME)-$(1)-$(2)
mkdir -p $(BUILDDIR)/$(NAME)-$(VERSION)-$(1)-$(2)
cp $(BUILDDIR)/$(NAME)-$(1)-$(2) $(BUILDDIR)/$(NAME)-$(VERSION)-$(1)-$(2)/$(NAME)
cd $(BUILDDIR) && tar -czvf $(NAME)-$(VERSION)-$(1)-$(2).tar.gz $(NAME)-$(VERSION)-$(1)-$(2)
rm -rf $(BUILDDIR)/$(NAME)-$(VERSION)-$(1)-$(2) $(BUILDDIR)/$(NAME)-$(1)-$(2)
endef

build:
GOARCH=$(GOARCH) GOOS=$(GOOS) $(WISPBUILD) -o $(BUILDDIR)/$(NAME) .

all:
$(call make_artifact_full,darwin,amd64)
$(call make_artifact_full,darwin,arm64)
$(call make_artifact_full,linux,amd64)
$(call make_artifact_full,linux,arm64)
$(call make_artifact_full,linux,ppc64le)
$(call make_artifact_full,linux,s390x)
$(call make_artifact_full,linux,riscv64)

local:
$(call make_artifact_full,$(shell go env GOOS),$(shell go env GOARCH))

darwin-amd64:
GOARCH=amd64 GOOS=darwin $(WISPBUILD) -o $(BUILDDIR)/$(NAME)-$@
mkdir -p $(BUILDDIR)/$(NAME)-$(VERSION)-$@
cp $(BUILDDIR)/$(NAME)-$@ $(BUILDDIR)/$(NAME)-$(VERSION)-$@/$(NAME)
cd $(BUILDDIR) && tar -czvf $(NAME)-$(VERSION)-$@.tar.gz $(NAME)-$(VERSION)-$@
rm -rf $(BUILDDIR)/$(NAME)-$(VERSION)-$@ $(BUILDDIR)/$(NAME)-$@
$(call make_artifact_full,darwin,amd64)

darwin-arm64:
GOARCH=arm64 GOOS=darwin $(WISPBUILD) -o $(BUILDDIR)/$(NAME)-$@
mkdir -p $(BUILDDIR)/$(NAME)-$(VERSION)-$@
cp $(BUILDDIR)/$(NAME)-$@ $(BUILDDIR)/$(NAME)-$(VERSION)-$@/$(NAME)
cd $(BUILDDIR) && tar -czvf $(NAME)-$(VERSION)-$@.tar.gz $(NAME)-$(VERSION)-$@
rm -rf $(BUILDDIR)/$(NAME)-$(VERSION)-$@ $(BUILDDIR)/$(NAME)-$@
$(call make_artifact_full,darwin,arm64)

linux-amd64:
GOARCH=amd64 GOOS=linux $(WISPBUILD) -o $(BUILDDIR)/$(NAME)-$@
mkdir -p $(BUILDDIR)/$(NAME)-$(VERSION)-$@
cp $(BUILDDIR)/$(NAME)-$@ $(BUILDDIR)/$(NAME)-$(VERSION)-$@/$(NAME)
cd $(BUILDDIR) && tar -czvf $(NAME)-$(VERSION)-$@.tar.gz $(NAME)-$(VERSION)-$@
rm -rf $(BUILDDIR)/$(NAME)-$(VERSION)-$@ $(BUILDDIR)/$(NAME)-$@
$(call make_artifact_full,linux,amd64)

linux-arm64:
GOARCH=arm64 GOOS=linux $(WISPBUILD) -o $(BUILDDIR)/$(NAME)-$@
mkdir -p $(BUILDDIR)/$(NAME)-$(VERSION)-$@
cp $(BUILDDIR)/$(NAME)-$@ $(BUILDDIR)/$(NAME)-$(VERSION)-$@/$(NAME)
cd $(BUILDDIR) && tar -czvf $(NAME)-$(VERSION)-$@.tar.gz $(NAME)-$(VERSION)-$@
rm -rf $(BUILDDIR)/$(NAME)-$(VERSION)-$@ $(BUILDDIR)/$(NAME)-$@
$(call make_artifact_full,linux,arm64)

linux-s390x:
GOARCH=s390x GOOS=linux $(WISPBUILD) -o $(BUILDDIR)/$(NAME)-$@
mkdir -p $(BUILDDIR)/$(NAME)-$(VERSION)-$@/
cp $(BUILDDIR)/$(NAME)-$@ $(BUILDDIR)/$(NAME)-$(VERSION)-$@/$(NAME)
cd $(BUILDDIR) && tar -czvf $(NAME)-$(VERSION)-$@.tar.gz $(NAME)-$(VERSION)-$@
rm -rf $(BUILDDIR)/$(NAME)-$(VERSION)-$@ $(BUILDDIR)/$(NAME)-$@
linux-loong64:
$(call make_artifact_full,linux,loong64)

linux-ppc64le:
GOARCH=ppc64le GOOS=linux $(WISPBUILD) -o $(BUILDDIR)/$(NAME)-$@
mkdir -p $(BUILDDIR)/$(NAME)-$(VERSION)-$@/
cp $(BUILDDIR)/$(NAME)-$@ $(BUILDDIR)/$(NAME)-$(VERSION)-$@/$(NAME)
cd $(BUILDDIR) && tar -czvf $(NAME)-$(VERSION)-$@.tar.gz $(NAME)-$(VERSION)-$@
rm -rf $(BUILDDIR)/$(NAME)-$(VERSION)-$@ $(BUILDDIR)/$(NAME)-$@
$(call make_artifact_full,linux,ppc64le)

linux-loong64:
GOARCH=loong64 GOOS=linux $(WISPBUILD) -o $(BUILDDIR)/$(NAME)-$@
mkdir -p $(BUILDDIR)/$(NAME)-$(VERSION)-$@
cp $(BUILDDIR)/$(NAME)-$@ $(BUILDDIR)/$(NAME)-$(VERSION)-$@/$(NAME)
cd $(BUILDDIR) && tar -czvf $(NAME)-$(VERSION)-$@.tar.gz $(NAME)-$(VERSION)-$@
rm -rf $(BUILDDIR)/$(NAME)-$(VERSION)-$@ $(BUILDDIR)/$(NAME)-$@

windows-amd64:
GOARCH=amd64 GOOS=windows $(WISPBUILD) -o $(BUILDDIR)/$(NAME)-$@.exe
mkdir -p $(BUILDDIR)/$(NAME)-$(VERSION)-$@
cp $(BUILDDIR)/$(NAME)-$@.exe $(BUILDDIR)/$(NAME)-$(VERSION)-$@/$(NAME).exe
cd $(BUILDDIR) && tar -czvf $(NAME)-$(VERSION)-$@.tar.gz $(NAME)-$(VERSION)-$@
rm -rf $(BUILDDIR)/$(NAME)-$(VERSION)-$@ $(BUILDDIR)/$(NAME)-$@.exe
linux-s390x:
$(call make_artifact_full,linux,s390x)

linux-riscv64:
$(call make_artifact_full,linux,riscv64)

clean:
rm -rf $(BUILDDIR)


proto_path=./protos/
proto_files=./protos/*.proto

Expand Down

0 comments on commit 4640246

Please sign in to comment.