-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
47 lines (41 loc) · 997 Bytes
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
.PHONY: build
.PHONY: before
# 设置变量
TARGETS := \
darwin/amd64 \
darwin/arm64 \
freebsd/386 \
freebsd/amd64 \
freebsd/arm \
freebsd/arm64 \
linux/386 \
linux/amd64 \
linux/arm \
linux/arm64 \
linux/mips \
linux/mips64 \
windows/386 \
windows/amd64 \
windows/arm \
windows/arm64
CC := go
FLAGS := -v
APP_NAME := jim
BIN := ./bin
build: all
# 默认目标,编译所有平台
all: $(TARGETS)
# 编译指定平台的目标
$(TARGETS):
@echo "编译 $@"
GOOS=$(word 1, $(subst /, ,$@)) GOARCH=$(word 2, $(subst /, ,$@)) $(CC) build -o $(BIN)/$(APP_NAME)-$(word 1, $(subst /, ,$@))-$(word 2, $(subst /, ,$@))$(if $(filter windows%,$@),.exe,)
# 清理生成的文件
clean:
rm -f ./bin/$(APP_NAME)-*
# 帮助信息
help:
@echo "Usage:"
@echo " make 编译项目到所有平台"
@echo " make <平台> 编译指定平台的项目"
@echo " make clean 清理生成的文件"
@echo " make help 显示帮助信息"