Skip to content

Commit 738b1c6

Browse files
committed
chore: 优化编译脚本
1 parent 4c10f56 commit 738b1c6

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

Makefile

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,54 @@
11
BIN_NAME=github-backup
2+
BUILD_DIR=./build
23
BUILD=$(shell git rev-parse --short HEAD)@$(shell date +%s)
34
CURRENT_OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
45
CURRENT_ARCH := $(shell uname -m | tr '[:upper:]' '[:lower:]')
5-
GO_BUILD=CGO_ENABLED=0 go build -ldflags "-X main.BuildVersion=$(BUILD)"
6+
LD_FLAGS=-ldflags "-X main.BuildVersion=$(BUILD)"
7+
GO_BUILD=CGO_ENABLED=0 go build $(LD_FLAGS)
68

79
.PHONY: build
810
build:
9-
$(GO_BUILD) -o ./build/$(CURRENT_OS)_$(CURRENT_ARCH)/ ./...
11+
$(GO_BUILD) -o ./build/$(BIN_NAME)_$(CURRENT_OS)_$(CURRENT_ARCH)/ ./...
1012

1113
.PHONY: run
1214
run:
13-
go run -ldflags "-X main.BuildVersion=$(BUILD)" .
15+
go run $(LD_FLAGS) .
1416

1517
.PHONY: install
1618
install:
17-
go install -ldflags "-X main.BuildVersion=$(BUILD)" .
19+
go install $(LD_FLAGS) .
1820

1921
.PHONY: buildLinuxX86
2022
buildLinuxX86:
21-
GOOS=linux GOARCH=amd64 $(GO_BUILD) -o ./build/linux_x86/ ./...
23+
GOOS=linux GOARCH=amd64 $(GO_BUILD) -o $(BUILD_DIR)/$(BIN_NAME)_linux_x86/ ./...
24+
25+
.PHONY: buildLinuxARM64
26+
buildLinuxARM64:
27+
GOOS=linux GOARCH=arm64 $(GO_BUILD) -o $(BUILD_DIR)/$(BIN_NAME)_linux_arm64/ ./...
2228

2329
.PHONY: buildWindowsX86
2430
buildWindowsX86:
25-
GOOS=windows GOARCH=amd64 $(GO_BUILD) -o ./build/windows_x86/ ./...
31+
GOOS=windows GOARCH=amd64 $(GO_BUILD) -o $(BUILD_DIR)/$(BIN_NAME)_windows_x86/ ./...
32+
33+
.PHONY: buildWindowsARM64
34+
buildWindowsARM64:
35+
GOOS=windows GOARCH=arm64 $(GO_BUILD) -o $(BUILD_DIR)/$(BIN_NAME)_windows_arm64/ ./...
36+
37+
.PHONY: buildDarwinX86
38+
buildDarwinX86:
39+
GOOS=darwin GOARCH=amd64 $(GO_BUILD) -o $(BUILD_DIR)/$(BIN_NAME)_darwin_x86/ ./...
40+
41+
.PHONY: buildDarwinARM64
42+
buildDarwinARM64:
43+
GOOS=darwin GOARCH=arm64 $(GO_BUILD) -o $(BUILD_DIR)/$(BIN_NAME)_darwin_arm64/ ./...
2644

2745
.PHONY: buildAll
28-
buildAll: buildLinuxX86 buildWindowsX86 build
46+
buildAll: buildLinuxX86 buildLinuxARM64 buildWindowsX86 buildWindowsARM64 buildDarwinX86 buildDarwinARM64
47+
48+
.PHONY: compressAll
49+
compressAll: buildAll
50+
@cd $(BUILD_DIR) && \
51+
for dir in */; do \
52+
base=$${dir%/}; \
53+
tar -czvf $${base}.tar.gz $${base}; \
54+
done

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ A simple tool to backup github repository to gitea or other provider.
44

55
### Installation
66

7+
#### Build from source
78
```bash
89
go install github.com/TBXark/github-backup@latest
910
````
1011

12+
#### Download from release
13+
Download the latest release from [release page](https://github.com/TBXark/github-backup/releases)
14+
1115
### Usage
1216
```
1317
Usage of github-backup:

0 commit comments

Comments
 (0)