Skip to content

Commit a033510

Browse files
committed
Only compile static when CI
[GitHub #173]
1 parent 47bc5bc commit a033510

File tree

1 file changed

+42
-14
lines changed

1 file changed

+42
-14
lines changed

Makefile

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,68 @@
99
# Last Modified : <2025-03-06>
1010
# --------------------------------------------------------------
1111

12-
CFLAGS += -Iinclude -Ilib
12+
On-Linux = 0
13+
On-Windows = 0
14+
On-macOS = 0
15+
16+
ifeq ($(shell uname), Linux)
17+
On-Linux = 1
18+
endif
1319

14-
# 只有Windows会定义该变量
20+
# 只有Windows会定义$(OS)变量
1521
ifeq ($(OS), Windows_NT)
22+
On-Windows = 1
23+
endif
24+
#=======================
25+
26+
CFLAGS += -Iinclude -Ilib
27+
28+
ifeq ($(On-Windows), 1)
1629
CLANG_FLAGS = -target x86_64-pc-windows-gnu
1730
endif
31+
1832
ifeq ($(CC), clang)
1933
CFLAGS += $(CLANG_FLAGS)
2034
endif
21-
ifeq ($(shell uname), Linux)
22-
CFLAGS += -static
23-
endif
24-
ifdef DEBUG
25-
CFLAGS += -g
26-
endif
2735

2836
override WARN += -Wall -Wextra -Wno-unused-variable -Wno-unused-function -Wno-missing-braces -Wno-misleading-indentation \
2937
-Wno-missing-field-initializers -Wno-unused-parameter -Wno-sign-compare
3038
_C_Warning_Flags := $(WARN)
3139

32-
Target_Name = chsrc
40+
ifdef DEBUG
41+
CFLAGS += -g
42+
endif
43+
44+
DEBUGGER = gdb
45+
46+
STATIC = 0
47+
#=======================
48+
49+
Target-Name = chsrc
3350

3451
# 由 GitHub Actions 在调用时修改
3552
CI_ARTIFACT_NAME = chsrc
3653

37-
DEBUGGER = gdb
54+
ifeq ($(MAKECMDGOALS), CI)
55+
ifeq ($(On-Linux), 1)
56+
STATIC = 1
57+
endif
58+
endif
3859
#=======================
3960

61+
4062
all:
41-
@$(CC) src/chsrc-main.c $(CFLAGS) $(_C_Warning_Flags) -o $(Target_Name)
63+
ifeq ($(STATIC), 1)
64+
CFLAGS += -static
65+
endif
66+
67+
all:
68+
@$(CC) src/chsrc-main.c $(CFLAGS) $(_C_Warning_Flags) -o $(Target-Name)
4269
@echo; echo Compile done using \'$(CC)\' $(CFLAGS)
4370

4471
CI: all
45-
@mv $(Target_Name) $(CI_ARTIFACT_NAME)
72+
@mv $(Target-Name) $(CI_ARTIFACT_NAME)
73+
4674

4775
debug: CFLAGS += -g
4876
debug: all
@@ -59,10 +87,10 @@ test-fw:
5987
@./fw
6088

6189
# AUR package 安装时将执行此 target
62-
fastcheck: $(Target_Name)
90+
fastcheck: $(Target-Name)
6391
@perl ./test/cli.pl fastcheck
6492

65-
test-cli: $(Target_Name)
93+
test-cli: $(Target-Name)
6694
@perl ./test/cli.pl
6795

6896
clean:

0 commit comments

Comments
 (0)