fix: Makefile Windows 检测兼容 Msys2/MINGW 环境

uname -s 在 Msys2 上返回 MINGW64_NT-* 而非 Windows,
添加 findstring 匹配确保静态链接选项生效
This commit is contained in:
2026-06-21 05:58:37 +08:00
parent 7fb2b730e9
commit 369b840cf2
6 changed files with 36 additions and 16 deletions
+12 -1
View File
@@ -9,6 +9,16 @@ LIB_SRC = dynamics_lib.c
# 自动检测系统
UNAME_S := $(shell uname -s 2>/dev/null || echo Windows)
# Windows 检测:Msys2/MINGW 也视为 Windows
IS_WINDOWS := $(findstring MINGW,$(UNAME_S))
ifneq ($(IS_WINDOWS),)
UNAME_S := Windows
endif
IS_WINDOWS := $(findstring MSYS,$(UNAME_S))
ifneq ($(IS_WINDOWS),)
UNAME_S := Windows
endif
# DLL 输出到 engines/release/
DLL_DIR = ../../release
@@ -19,8 +29,9 @@ else ifeq ($(UNAME_S),Darwin)
DLL_TARGET = $(DLL_DIR)/dynamics_c.dylib
DLL_FLAGS = -dynamiclib
else
# Windows: 静态链接运行时,避免依赖 libgcc_s_seh-1.dll
DLL_TARGET = $(DLL_DIR)/dynamics_c.dll
DLL_FLAGS = -shared
DLL_FLAGS = -shared -static
endif
.PHONY: all dll clean
+13 -9
View File
@@ -6,14 +6,17 @@ LIB_SRC = dynamics_lib.cpp
UNAME_S := $(shell uname -s 2>/dev/null || echo Windows)
CXXFLAGS = -O3 -march=native -std=c++17 -Wall -Wextra -D_USE_MATH_DEFINES
# Windows 下静态链接运行时
ifeq ($(UNAME_S),Windows)
STATIC_FLAGS = -static-libgcc -static-libstdc++
else
STATIC_FLAGS =
# Windows 检测:Msys2/MINGW 也视为 Windows
IS_WINDOWS := $(findstring MINGW,$(UNAME_S))
ifneq ($(IS_WINDOWS),)
UNAME_S := Windows
endif
IS_WINDOWS := $(findstring MSYS,$(UNAME_S))
ifneq ($(IS_WINDOWS),)
UNAME_S := Windows
endif
CXXFLAGS = -O3 -march=native -std=c++17 -Wall -Wextra -D_USE_MATH_DEFINES
# DLL 输出到 engines/release/
DLL_DIR = ../../release
@@ -25,8 +28,9 @@ else ifeq ($(UNAME_S),Darwin)
DLL_TARGET = $(DLL_DIR)/dynamics_cpp.dylib
DLL_FLAGS = -dynamiclib
else
# Windows: 完全静态链接,避免依赖运行时 DLL
DLL_TARGET = $(DLL_DIR)/dynamics_cpp.dll
DLL_FLAGS = -shared
DLL_FLAGS = -shared -static
endif
.PHONY: all dll clean
@@ -36,7 +40,7 @@ all: dll
dll: $(DLL_TARGET)
$(DLL_TARGET): $(LIB_SRC) | $(DLL_DIR)
$(CXX) $(CXXFLAGS) $(STATIC_FLAGS) $(DLL_FLAGS) -o $@ $(LIB_SRC)
$(CXX) $(CXXFLAGS) $(DLL_FLAGS) -o $@ $(LIB_SRC)
@echo " === C++ DLL built: $@ ==="
$(DLL_DIR):
+11 -6
View File
@@ -7,10 +7,14 @@ LIB_SRC = dynamics_lib.f90
UNAME_S := $(shell uname -s 2>/dev/null || echo Windows)
ifeq ($(UNAME_S),Windows)
STATIC_FLAGS = -static
else
STATIC_FLAGS =
# Windows 检测:Msys2/MINGW 也视为 Windows
IS_WINDOWS := $(findstring MINGW,$(UNAME_S))
ifneq ($(IS_WINDOWS),)
UNAME_S := Windows
endif
IS_WINDOWS := $(findstring MSYS,$(UNAME_S))
ifneq ($(IS_WINDOWS),)
UNAME_S := Windows
endif
# DLL 输出到 engines/release/
@@ -23,8 +27,9 @@ else ifeq ($(UNAME_S),Darwin)
DLL_TARGET = $(DLL_DIR)/dynamics_f90.dylib
DLL_FLAGS = -dynamiclib
else
# Windows: 完全静态链接,避免依赖 libgfortran-5.dll
DLL_TARGET = $(DLL_DIR)/dynamics_f90.dll
DLL_FLAGS = -shared -fPIC
DLL_FLAGS = -shared -fPIC -static
endif
.PHONY: all dll clean
@@ -34,7 +39,7 @@ all: dll
dll: $(DLL_TARGET)
$(DLL_TARGET): $(LIB_SRC) | $(DLL_DIR)
$(FC) $(FFLAGS) $(STATIC_FLAGS) $(DLL_FLAGS) -o $@ $(LIB_SRC)
$(FC) $(FFLAGS) $(DLL_FLAGS) -o $@ $(LIB_SRC)
@echo " === Fortran DLL built: $@ ==="
$(DLL_DIR):