mirror of
https://github.com/RubyMetric/chsrc
synced 2025-10-19 17:17:25 +08:00
feat(build): 支持编译资源文件
修复just 修复makefile
This commit is contained in:
73
Makefile
73
Makefile
@@ -6,9 +6,10 @@
|
||||
# File Authors : Aoran Zeng <ccmywish@qq.com>
|
||||
# Contributors : Yangmoooo <yangmoooo@outlook.com>
|
||||
# | sanchuanhehe <wyihe5520@gmail.com>
|
||||
# | Mikachu2333 <mikachu.23333@zohomail.com>
|
||||
# |
|
||||
# Created On : <2023-08-28>
|
||||
# Last Modified : <2025-07-22>
|
||||
# Last Modified : <2025-10-11>
|
||||
#
|
||||
# 请阅读 ./doc/01-开发与构建.md 来使用
|
||||
# --------------------------------------------------------------
|
||||
@@ -18,17 +19,24 @@ On-Linux = 0
|
||||
On-Windows = 0
|
||||
On-macOS = 0
|
||||
|
||||
ifeq ($(shell uname), Linux)
|
||||
On-Linux = 1
|
||||
endif
|
||||
|
||||
ifeq ($(shell uname), Darwin)
|
||||
On-macOS = 1
|
||||
endif
|
||||
|
||||
# 只有Windows会定义$(OS)变量
|
||||
ifeq ($(OS), Windows_NT)
|
||||
# Windows 会定义 OS 或 ComSpec 环境变量
|
||||
ifdef ComSpec
|
||||
On-Windows = 1
|
||||
else ifdef OS
|
||||
ifeq ($(OS), Windows_NT)
|
||||
On-Windows = 1
|
||||
endif
|
||||
endif
|
||||
|
||||
# 只在非 Windows 环境下调用 uname
|
||||
ifneq ($(On-Windows), 1)
|
||||
UNAME_S := $(shell uname 2>/dev/null || echo unknown)
|
||||
ifeq ($(UNAME_S), Linux)
|
||||
On-Linux = 1
|
||||
endif
|
||||
ifeq ($(UNAME_S), Darwin)
|
||||
On-macOS = 1
|
||||
endif
|
||||
endif
|
||||
#=====================================
|
||||
|
||||
@@ -36,8 +44,8 @@ endif
|
||||
|
||||
#======== Default Tooling ============
|
||||
ifeq ($(On-Windows), 1)
|
||||
# MSYS2 环境
|
||||
CC = cc
|
||||
# Windows 环境 - 使用 gcc
|
||||
CC = gcc
|
||||
else ifeq ($(On-macOS), 1)
|
||||
CC = clang
|
||||
else
|
||||
@@ -142,13 +150,25 @@ build-in-debug-mode:
|
||||
build-in-release-mode: CFLAGS += $(CFLAGS_optimization)
|
||||
build-in-release-mode:
|
||||
@echo Starting: Build in RELEASE mode: \'$(CC)\' $(CFLAGS) -o $(ReleaseMode-Target-Name)
|
||||
ifeq ($(On-Windows), 1)
|
||||
@if exist lib\chsrc.res del /Q lib\chsrc.res 2>nul
|
||||
@windres lib\win_res.rc -O coff -o lib\chsrc.res -Iinclude -Ilib
|
||||
@$(CC) src/chsrc-main.c lib/chsrc.res $(CFLAGS) $(_C_Warning_Flags) -o $(ReleaseMode-Target-Name)
|
||||
@del /Q lib\chsrc.res 2>nul
|
||||
else
|
||||
@$(CC) src/chsrc-main.c $(CFLAGS) $(_C_Warning_Flags) -o $(ReleaseMode-Target-Name)
|
||||
endif
|
||||
@echo Finished: Build in RELEASE mode
|
||||
|
||||
# CI release mode 的配置在该文件上方
|
||||
build-in-ci-release-mode:
|
||||
@echo Starting: Build in CI-RELEASE mode: \'$(CC)\' $(CFLAGS) -o $(CIReleaseMode-Target-Name)
|
||||
ifeq ($(On-Windows), 1)
|
||||
@windres lib\win_res.rc -O coff -o lib\chsrc.res -Iinclude -Ilib
|
||||
@$(CC) src/chsrc-main.c lib/chsrc.res $(CFLAGS) $(_C_Warning_Flags) -o $(CIReleaseMode-Target-Name)
|
||||
else
|
||||
@$(CC) src/chsrc-main.c $(CFLAGS) $(_C_Warning_Flags) -o $(CIReleaseMode-Target-Name)
|
||||
endif
|
||||
@echo Finished: Build in CI-RELEASE mode
|
||||
|
||||
# 永远重新编译
|
||||
@@ -163,6 +183,10 @@ test-make-env:
|
||||
@echo "On-macOS: $(On-macOS)"
|
||||
@echo "CC: $(CC)"
|
||||
@echo "CFLAGS: $(CFLAGS)"
|
||||
ifeq ($(On-Windows), 1)
|
||||
@echo "USER: $(USERNAME)"
|
||||
@echo "PWD: $(CURDIR)"
|
||||
else
|
||||
@echo "USER: $$(whoami)"
|
||||
@echo "PWD: $(shell pwd)"
|
||||
@echo "UID: $$(id -u)"
|
||||
@@ -173,17 +197,28 @@ test-make-env:
|
||||
else \
|
||||
echo "HOME: $(HOME)"; \
|
||||
fi
|
||||
endif
|
||||
|
||||
# 这两个测试文件都用 DEBUG mode
|
||||
test-xy: CFLAGS += $(CFLAGS_debug)
|
||||
test-xy:
|
||||
ifeq ($(On-Windows), 1)
|
||||
@$(CC) test/xy.c $(CFLAGS) -o xy.exe
|
||||
@xy.exe
|
||||
else
|
||||
@$(CC) test/xy.c $(CFLAGS) -o xy
|
||||
@./xy
|
||||
endif
|
||||
|
||||
test-fw: CFLAGS += $(CFLAGS_debug)
|
||||
test-fw:
|
||||
ifeq ($(On-Windows), 1)
|
||||
@$(CC) test/fw.c $(CFLAGS) -o fw.exe
|
||||
@fw.exe
|
||||
else
|
||||
@$(CC) test/fw.c $(CFLAGS) -o fw
|
||||
@./fw
|
||||
endif
|
||||
|
||||
check: test
|
||||
|
||||
@@ -195,15 +230,25 @@ test-cli: $(DevMode-Target-Name)
|
||||
@perl ./test/cli.pl
|
||||
|
||||
clean:
|
||||
ifeq ($(On-Windows), 1)
|
||||
-@if exist *.exe del /Q *.exe 2>nul
|
||||
-@if exist xy.exe del /Q xy.exe 2>nul
|
||||
-@if exist fw.exe del /Q fw.exe 2>nul
|
||||
-@if exist README.md.bak* del /Q README.md.bak* 2>nul
|
||||
-@if exist chsrc.exe del /Q chsrc.exe 2>nul
|
||||
-@if exist chsrc-debug.exe del /Q chsrc-debug.exe 2>nul
|
||||
-@if exist chsrc-release.exe del /Q chsrc-release.exe 2>nul
|
||||
-@if exist chsrc-ci-release.exe del /Q chsrc-ci-release.exe 2>nul
|
||||
else
|
||||
-@rm *.exe 2>/dev/null
|
||||
-@rm xy 2>/dev/null
|
||||
-@rm fw 2>/dev/null
|
||||
-@rm README.md.bak* 2>/dev/null
|
||||
|
||||
-@rm chsrc 2>/dev/null
|
||||
-@rm chsrc-debug 2>/dev/null
|
||||
-@rm chsrc-release 2>/dev/null
|
||||
-@rm chsrc-ci-release 2>/dev/null
|
||||
endif
|
||||
|
||||
# -include pkg/deb/Makefile # 不这么做,因为 pkg/deb/Makefile 需要在 pkg/deb 目录下执行
|
||||
# 保持动词在前的任务名风格
|
||||
|
24
include/chsrc_version.h
Normal file
24
include/chsrc_version.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/** ------------------------------------------------------------
|
||||
* Copyright © 2023-2025 曾奥然, 郭恒
|
||||
* SPDX-License-Identifier: MIT
|
||||
* -------------------------------------------------------------
|
||||
* Lib Authors : 曾奥然 <ccmywish@qq.com>
|
||||
* Contributors : Mikachu2333 <mikachu.23333@zohomail.com>
|
||||
* |
|
||||
* Created On : <2025-10-10>
|
||||
* Last Modified : <2025-10-10>
|
||||
|
||||
* !!!警告!!!
|
||||
* 发布前请修改此处的内容
|
||||
* ------------------------------------------------------------*/
|
||||
|
||||
#define Chsrc_Version "0.2.3"
|
||||
#define Chsrc_Release_Date "2025/10/06"
|
||||
|
||||
// 以下宏仅用于 Windows
|
||||
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
|
||||
#define CHSRC_VERSION_MAJOR 0
|
||||
#define CHSRC_VERSION_MINOR 2
|
||||
#define CHSRC_VERSION_PATCH 3
|
||||
#define CHSRC_VERSION_STRING "0.2.3"
|
||||
#endif
|
9
justfile
9
justfile
@@ -4,10 +4,10 @@
|
||||
# --------------------------------------------------------------
|
||||
# Build File : justfile
|
||||
# File Authors : Aoran Zeng <ccmywish@qq.com>
|
||||
# Contributors : Nul None <nul@none.org>
|
||||
# Contributors : Mikachu2333 <mikachu.23333@zohomail.com>
|
||||
# |
|
||||
# Created On : <2025-06-18>
|
||||
# Last Modified : <2025-07-21>
|
||||
# Last Modified : <2025-10-11>
|
||||
#
|
||||
# 该文件主要用于在原生Windows上执行项目的基本任务,而不借助于
|
||||
# GNU make 以及相应的 MSYS2、Cygwin 环境
|
||||
@@ -115,7 +115,10 @@ build-in-debug-mode:
|
||||
|
||||
build-in-release-mode:
|
||||
@echo Starting: Build in RELEASE mode: '{{CC}}' {{CFLAGS_release_mode_prompt}} -o {{ReleaseMode-Target-Name}}
|
||||
@{{CC}} src/chsrc-main.c {{CFLAGS_release_mode}} -o {{ReleaseMode-Target-Name}}
|
||||
{{ if os() == 'windows' { '@if exist lib\\chsrc.res del lib\\chsrc.res' } else { '' } }}
|
||||
{{ if os() == 'windows' { '@windres lib\\win_res.rc -O coff -o lib\\chsrc.res -Iinclude -Ilib' } else { '' } }}
|
||||
{{ if os() == 'windows' { '@{{CC}} src/chsrc-main.c lib/chsrc.res {{CFLAGS_release_mode}} -o {{ReleaseMode-Target-Name}}' } else { '@{{CC}} src/chsrc-main.c {{CFLAGS_release_mode}} -o {{ReleaseMode-Target-Name}}' } }}
|
||||
{{ if os() == 'windows' { '@del lib\\chsrc.res' } else { '' } }}
|
||||
@echo Finished: Build in RELEASE mode
|
||||
|
||||
debug: build-in-debug-mode
|
||||
|
44
lib/win_res.rc
Normal file
44
lib/win_res.rc
Normal file
@@ -0,0 +1,44 @@
|
||||
// chsrc.rc - Windows Resource Script
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include <windows.h>
|
||||
#include "chsrc_version.h"
|
||||
|
||||
// 图标资源
|
||||
IDI_ICON1 ICON DISCARDABLE "logo.ico"
|
||||
|
||||
// 版本信息
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION CHSRC_VERSION_MAJOR,CHSRC_VERSION_MINOR,CHSRC_VERSION_PATCH,0
|
||||
PRODUCTVERSION CHSRC_VERSION_MAJOR,CHSRC_VERSION_MINOR,CHSRC_VERSION_PATCH,0
|
||||
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS VS_FF_DEBUG
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS VOS_NT_WINDOWS32
|
||||
FILETYPE VFT_APP
|
||||
FILESUBTYPE VFT2_UNKNOWN
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Github RubyMetric"
|
||||
VALUE "FileDescription", "Change Source everywhere for every software"
|
||||
VALUE "FileVersion", Chsrc_Version
|
||||
VALUE "InternalName", "chsrc"
|
||||
VALUE "LegalCopyright", "Copyright (c) 2023-2025 RubyMetric"
|
||||
VALUE "OriginalFilename", "chsrc.exe"
|
||||
VALUE "ProductName", "chsrc"
|
||||
VALUE "ProductVersion", Chsrc_Release_Date
|
||||
VALUE "Comments", "MIT License"
|
||||
VALUE "LegalTrademarks", ""
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x0804, 1200, 0x0409, 1200 // 简体中文和英语
|
||||
END
|
||||
END
|
@@ -30,8 +30,8 @@
|
||||
* 然的加入,逐渐成长为互相支持的伙伴。
|
||||
* ------------------------------------------------------------*/
|
||||
|
||||
#define Chsrc_Version "0.2.3"
|
||||
#define Chsrc_Release_Date "2025/10/06"
|
||||
#include "chsrc_version.h"
|
||||
|
||||
#define Chsrc_Maintain_URL "https://github.com/RubyMetric/chsrc"
|
||||
#define Chsrc_Maintain_URL2 "https://gitee.com/RubyMetric/chsrc"
|
||||
|
||||
|
Reference in New Issue
Block a user