33# SPDX-License-Identifier: GPL-3.0-or-later
44# --------------------------------------------------------------
55# Build File : Makefile
6- # File Authors : Aoran Zeng <[email protected] >7- # Contributors : Yangmoooo <[email protected] >8- # | sanchuanhehe <[email protected] >9- # | Mikachu2333 <[email protected] >10- # |
6+ # File Authors : Aoran Zeng <[email protected] >7+ # Contributors : Yangmoooo <[email protected] >8+ # | sanchuanhehe <[email protected] >9+ # |
1110# Created On : <2023-08-28>
12- # Last Modified : <2025-10-11 >
11+ # Last Modified : <2025-07-22 >
1312#
1413# 请阅读 ./doc/01-开发与构建.md 来使用
1514# --------------------------------------------------------------
@@ -19,33 +18,26 @@ On-Linux = 0
1918On-Windows = 0
2019On-macOS = 0
2120
22- # Windows 会定义 OS 或 ComSpec 环境变量
23- ifdef ComSpec
24- On-Windows = 1
25- else ifdef OS
26- ifeq ($(OS), Windows_NT)
27- On-Windows = 1
28- endif
21+ ifeq ($(shell uname) , Linux)
22+ On-Linux = 1
2923endif
3024
31- # 只在非 Windows 环境下调用 uname
32- ifneq ($(On-Windows ) , 1)
33- UNAME_S := $(shell uname 2>/dev/null || echo unknown)
34- ifeq ($(UNAME_S), Linux)
35- On-Linux = 1
36- endif
37- ifeq ($(UNAME_S), Darwin)
38- On-macOS = 1
39- endif
25+ ifeq ($(shell uname) , Darwin)
26+ On-macOS = 1
27+ endif
28+
29+ # 只有Windows会定义$(OS)变量
30+ ifeq ($(OS ) , Windows_NT)
31+ On-Windows = 1
4032endif
4133# =====================================
4234
4335
4436
4537# ======== Default Tooling ============
4638ifeq ($(On-Windows ) , 1)
47- # Windows 环境 - 使用 gcc
48- CC = gcc
39+ # MSYS2 环境
40+ CC = cc
4941else ifeq ($(On-macOS), 1)
5042 CC = clang
5143else
@@ -62,20 +54,10 @@ endif
6254
6355
6456# ======== Compilation Config ==========
65- CFLAGS += -Iinclude -Ilib -Isrc/framework -Isrc/res
66-
67- Target-Is-Windows = 0
68- Use-Windows-Resource = 0
57+ CFLAGS += -Iinclude -Ilib
6958
7059ifeq ($(On-Windows ) , 1)
7160 CLANG_FLAGS = -target x86_64-pc-windows-gnu
72- Target-Machine := $(shell $(CC) -dumpmachine 2>nul || echo unknown)
73- ifneq ($(findstring mingw,$(Target-Machine)),)
74- Target-Is-Windows = 1
75- else ifneq ($(findstring windows,$(Target-Machine)),)
76- Target-Is-Windows = 1
77- endif
78- Use-Windows-Resource := $(Target-Is-Windows)
7961endif
8062
8163ifeq ($(CC ) , clang)
@@ -160,25 +142,13 @@ build-in-debug-mode:
160142build-in-release-mode : CFLAGS += $(CFLAGS_optimization )
161143build-in-release-mode :
162144 @echo Starting: Build in RELEASE mode: \' $(CC ) \' $(CFLAGS ) -o $(ReleaseMode-Target-Name )
163- ifeq ($(Use-Windows-Resource ) , 1)
164- @if exist src\\res\\chsrc.res del src\\res\\chsrc.res
165- @windres src\\res\\win_res.rc -O coff -o src\\res\\chsrc.res -Iinclude -Ilib -Isrc\\framework -Isrc\\res
166- @$(CC) src\\chsrc-main.c src\\res\\chsrc.res $(CFLAGS) $(_C_Warning_Flags) -o $(ReleaseMode-Target-Name)
167- @del src\\res\\chsrc.res
168- else
169145 @$(CC ) src/chsrc-main.c $(CFLAGS ) $(_C_Warning_Flags ) -o $(ReleaseMode-Target-Name )
170- endif
171146 @echo Finished: Build in RELEASE mode
172147
173148# CI release mode 的配置在该文件上方
174149build-in-ci-release-mode :
175150 @echo Starting: Build in CI-RELEASE mode: \' $(CC ) \' $(CFLAGS ) -o $(CIReleaseMode-Target-Name )
176- ifeq ($(Use-Windows-Resource ) , 1)
177- @windres src\\res\\win_res.rc -O coff -o src\\res\\chsrc.res -Iinclude -Ilib -Isrc\\framework -Isrc\\res
178- @$(CC) src\\chsrc-main.c src\\res\\chsrc.res $(CFLAGS) $(_C_Warning_Flags) -o $(CIReleaseMode-Target-Name)
179- else
180151 @$(CC ) src/chsrc-main.c $(CFLAGS ) $(_C_Warning_Flags ) -o $(CIReleaseMode-Target-Name )
181- endif
182152 @echo Finished: Build in CI-RELEASE mode
183153
184154# 永远重新编译
@@ -193,10 +163,6 @@ test-make-env:
193163 @echo " On-macOS: $( On-macOS) "
194164 @echo " CC: $( CC) "
195165 @echo " CFLAGS: $( CFLAGS) "
196- ifeq ($(On-Windows ) , 1)
197- @echo "USER: $(USERNAME)"
198- @echo "PWD: $(CURDIR)"
199- else
200166 @echo " USER: $$ (whoami)"
201167 @echo " PWD: $( shell pwd) "
202168 @echo " UID: $$ (id -u)"
@@ -207,28 +173,17 @@ else
207173 else \
208174 echo "HOME: $(HOME)"; \
209175 fi
210- endif
211176
212177# 这两个测试文件都用 DEBUG mode
213178test-xy : CFLAGS += $(CFLAGS_debug )
214179test-xy :
215- ifeq ($(On-Windows ) , 1)
216- @$(CC) test/xy.c $(CFLAGS) -o xy.exe
217- @xy.exe
218- else
219180 @$(CC ) test/xy.c $(CFLAGS ) -o xy
220181 @./xy
221- endif
222182
223183test-fw : CFLAGS += $(CFLAGS_debug )
224184test-fw :
225- ifeq ($(On-Windows ) , 1)
226- @$(CC) test/fw.c $(CFLAGS) -o fw.exe
227- @fw.exe
228- else
229185 @$(CC ) test/fw.c $(CFLAGS ) -o fw
230186 @./fw
231- endif
232187
233188check : test
234189
@@ -240,25 +195,15 @@ test-cli: $(DevMode-Target-Name)
240195 @perl ./test/cli.pl
241196
242197clean :
243- ifeq ($(On-Windows ) , 1)
244- -@if exist *.exe del /Q *.exe 2>nul
245- -@if exist xy.exe del /Q xy.exe 2>nul
246- -@if exist fw.exe del /Q fw.exe 2>nul
247- -@if exist README.md.bak* del /Q README.md.bak* 2>nul
248- -@if exist chsrc.exe del /Q chsrc.exe 2>nul
249- -@if exist chsrc-debug.exe del /Q chsrc-debug.exe 2>nul
250- -@if exist chsrc-release.exe del /Q chsrc-release.exe 2>nul
251- -@if exist chsrc-ci-release.exe del /Q chsrc-ci-release.exe 2>nul
252- else
253198 -@rm * .exe 2> /dev/null
254199 -@rm xy 2> /dev/null
255200 -@rm fw 2> /dev/null
256201 -@rm README.md.bak* 2> /dev/null
202+
257203 -@rm chsrc 2>/dev/null
258204 -@rm chsrc-debug 2>/dev/null
259205 -@rm chsrc-release 2>/dev/null
260206 -@rm chsrc-ci-release 2>/dev/null
261- endif
262207
263208# -include pkg/deb/Makefile # 不这么做,因为 pkg/deb/Makefile 需要在 pkg/deb 目录下执行
264209# 保持动词在前的任务名风格
0 commit comments