33# SPDX-License-Identifier: GPL-3.0-or-later
44# --------------------------------------------------------------
55# Build File : Makefile
6- # File Authors : Aoran Zeng <ccmywish@qq.com>
7- # Contributors : Yangmoooo <yangmoooo@outlook.com>
8- # | sanchuanhehe <wyihe5520@gmail.com>
9- # |
6+ # File Authors : Aoran Zeng <ccmywish@qq.com>
7+ # Contributors : Yangmoooo <yangmoooo@outlook.com>
8+ # | sanchuanhehe <wyihe5520@gmail.com>
9+ # | Mikachu2333 <mikachu.23333@zohomail.com>
10+ # |
1011# Created On : <2023-08-28>
11- # Last Modified : <2025-07-22 >
12+ # Last Modified : <2025-10-11 >
1213#
1314# 请阅读 ./doc/01-开发与构建.md 来使用
1415# --------------------------------------------------------------
@@ -18,26 +19,33 @@ On-Linux = 0
1819On-Windows = 0
1920On-macOS = 0
2021
21- ifeq ($(shell uname) , Linux)
22- On-Linux = 1
23- endif
24-
25- ifeq ($(shell uname) , Darwin)
26- On-macOS = 1
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
2729endif
2830
29- # 只有Windows会定义$(OS)变量
30- ifeq ($(OS ) , Windows_NT)
31- On-Windows = 1
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
3240endif
3341# =====================================
3442
3543
3644
3745# ======== Default Tooling ============
3846ifeq ($(On-Windows ) , 1)
39- # MSYS2 环境
40- CC = cc
47+ # Windows 环境 - 使用 gcc
48+ CC = gcc
4149else ifeq ($(On-macOS), 1)
4250 CC = clang
4351else
@@ -142,7 +150,14 @@ build-in-debug-mode:
142150build-in-release-mode : CFLAGS += $(CFLAGS_optimization )
143151build-in-release-mode :
144152 @echo Starting: Build in RELEASE mode: \' $(CC ) \' $(CFLAGS ) -o $(ReleaseMode-Target-Name )
153+ ifeq ($(On-Windows ) , 1)
154+ @if exist lib\chsrc.res del /Q lib\chsrc.res 2>nul
155+ @windres lib\win_res.rc -O coff -o lib\chsrc.res -Iinclude -Ilib
156+ @$(CC) src/chsrc-main.c lib/chsrc.res $(CFLAGS) $(_C_Warning_Flags) -o $(ReleaseMode-Target-Name)
157+ @del /Q lib\chsrc.res 2>nul
158+ else
145159 @$(CC) src/chsrc-main.c $(CFLAGS) $(_C_Warning_Flags) -o $(ReleaseMode-Target-Name)
160+ endif
146161 @echo Finished: Build in RELEASE mode
147162
148163# CI release mode 的配置在该文件上方
@@ -163,6 +178,10 @@ test-make-env:
163178 @echo " On-macOS: $( On-macOS) "
164179 @echo " CC: $( CC) "
165180 @echo " CFLAGS: $( CFLAGS) "
181+ ifeq ($(On-Windows ) , 1)
182+ @echo "USER: $(USERNAME)"
183+ @echo "PWD: $(CURDIR)"
184+ else
166185 @echo "USER: $$(whoami)"
167186 @echo "PWD: $(shell pwd)"
168187 @echo "UID: $$(id -u)"
@@ -173,17 +192,28 @@ test-make-env:
173192 else \
174193 echo "HOME: $(HOME)"; \
175194 fi
195+ endif
176196
177197# 这两个测试文件都用 DEBUG mode
178198test-xy : CFLAGS += $(CFLAGS_debug )
179199test-xy :
200+ ifeq ($(On-Windows ) , 1)
201+ @$(CC) test/xy.c $(CFLAGS) -o xy.exe
202+ @xy.exe
203+ else
180204 @$(CC) test/xy.c $(CFLAGS) -o xy
181205 @./xy
206+ endif
182207
183208test-fw : CFLAGS += $(CFLAGS_debug )
184209test-fw :
210+ ifeq ($(On-Windows ) , 1)
211+ @$(CC) test/fw.c $(CFLAGS) -o fw.exe
212+ @fw.exe
213+ else
185214 @$(CC) test/fw.c $(CFLAGS) -o fw
186215 @./fw
216+ endif
187217
188218check : test
189219
@@ -195,15 +225,25 @@ test-cli: $(DevMode-Target-Name)
195225 @perl ./test/cli.pl
196226
197227clean :
228+ ifeq ($(On-Windows ) , 1)
229+ -@if exist *.exe del /Q *.exe 2>nul
230+ -@if exist xy.exe del /Q xy.exe 2>nul
231+ -@if exist fw.exe del /Q fw.exe 2>nul
232+ -@if exist README.md.bak* del /Q README.md.bak* 2>nul
233+ -@if exist chsrc.exe del /Q chsrc.exe 2>nul
234+ -@if exist chsrc-debug.exe del /Q chsrc-debug.exe 2>nul
235+ -@if exist chsrc-release.exe del /Q chsrc-release.exe 2>nul
236+ -@if exist chsrc-ci-release.exe del /Q chsrc-ci-release.exe 2>nul
237+ else
198238 -@rm *.exe 2>/dev/null
199239 -@rm xy 2>/dev/null
200240 -@rm fw 2>/dev/null
201241 -@rm README.md.bak* 2>/dev/null
202-
203242 -@rm chsrc 2>/dev/null
204243 -@rm chsrc-debug 2>/dev/null
205244 -@rm chsrc-release 2>/dev/null
206245 -@rm chsrc-ci-release 2>/dev/null
246+ endif
207247
208248# -include pkg/deb/Makefile # 不这么做,因为 pkg/deb/Makefile 需要在 pkg/deb 目录下执行
209249# 保持动词在前的任务名风格
0 commit comments