From 262b5eefdc722cd93338f08ec67d2cec14a2992c Mon Sep 17 00:00:00 2001 From: Kinneyzhang Date: Mon, 26 Jan 2026 11:51:19 +0800 Subject: [PATCH] Makefile supports multiple plantform --- .../DONE-PLAN.md | 7 +++++ .../DONE-TASK-001.md | 20 +++++++++++++ .../change_maintenance_20260126.md | 9 ++++++ ekp_c/Makefile | 28 ++++++++++++++++--- 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 .phrase/phases/DONE-phase-maintenance-20260126/DONE-PLAN.md create mode 100644 .phrase/phases/DONE-phase-maintenance-20260126/DONE-TASK-001.md create mode 100644 .phrase/phases/DONE-phase-maintenance-20260126/change_maintenance_20260126.md diff --git a/.phrase/phases/DONE-phase-maintenance-20260126/DONE-PLAN.md b/.phrase/phases/DONE-phase-maintenance-20260126/DONE-PLAN.md new file mode 100644 index 0000000..54d6d4c --- /dev/null +++ b/.phrase/phases/DONE-phase-maintenance-20260126/DONE-PLAN.md @@ -0,0 +1,7 @@ +# Phase: Maintenance (2026-01-26) + +## Purpose +Fix build issues and maintain codebase stability. + +## Tasks +- [x] task001: Fix Windows build failure in `ekp_c` (Make `cc` not found). diff --git a/.phrase/phases/DONE-phase-maintenance-20260126/DONE-TASK-001.md b/.phrase/phases/DONE-phase-maintenance-20260126/DONE-TASK-001.md new file mode 100644 index 0000000..9a8a647 --- /dev/null +++ b/.phrase/phases/DONE-phase-maintenance-20260126/DONE-TASK-001.md @@ -0,0 +1,20 @@ +# Task 001: Fix Windows build failure + +## Issue +User reports `make` fails on Windows because `cc` is not found. +Current Makefile relies on `uname` and assumes `cc` exists. + +## Plan +1. Detect Windows via `OS` environment variable (standard on Windows). +2. On Windows, default CC to `gcc` if not set. +3. Remove reliance on `uname` for Windows detection. +4. Verify `pthread` linking. + +## Status +- [x] Completed (2026-01-26) + +## Validation +- Run `make` in `ekp_c/`. +- Verify `ekp.dll` is created. +- [x] Confirmed `make` builds `ekp.dll`. +- [x] Confirmed `make test` passes (loads module in Emacs). diff --git a/.phrase/phases/DONE-phase-maintenance-20260126/change_maintenance_20260126.md b/.phrase/phases/DONE-phase-maintenance-20260126/change_maintenance_20260126.md new file mode 100644 index 0000000..4bf38b5 --- /dev/null +++ b/.phrase/phases/DONE-phase-maintenance-20260126/change_maintenance_20260126.md @@ -0,0 +1,9 @@ +# Changes Log - Phase Maintenance 2026-01-26 + +## 2026-01-26 +- **Fix**: Update `ekp_c/Makefile` to support Windows build. + - Detect `Windows_NT` and use `gcc` instead of `cc`. + - Set default `EMACS_ROOT` and `EMACS` path for the current environment. + - Add `EMACS_ROOT` include path to `CFLAGS`. + - Fix `test` target to use configured `$(EMACS)` executable. + - Task: `task001` diff --git a/ekp_c/Makefile b/ekp_c/Makefile index d13a1a3..e79fd3c 100644 --- a/ekp_c/Makefile +++ b/ekp_c/Makefile @@ -4,10 +4,24 @@ # Uses pthread for multi-threading, optimizes for native CPU. # Detect OS -UNAME := $(shell uname) +ifeq ($(OS),Windows_NT) + UNAME := Windows +else + UNAME := $(shell uname 2>/dev/null || echo Unknown) +endif # Compiler settings -CC := cc +# Default to gcc on Windows if cc is not found +ifeq ($(UNAME), Windows) + CC = gcc + # Default Emacs root for this environment (can be overridden) + EMACS_ROOT ?= C:/Users/26289/Apps/emacs-30.2/emacs-30.2 + EMACS ?= $(EMACS_ROOT)/bin/emacs.exe +else + CC ?= cc + EMACS ?= emacs +endif + CFLAGS := -std=c11 -Wall -Wextra -Wpedantic -O3 -fPIC CFLAGS += -march=native -flto CFLAGS += -D_POSIX_C_SOURCE=200809L @@ -32,10 +46,15 @@ else ifeq ($(UNAME), Linux) # Linux MODULE_EXT := so LDFLAGS := -shared -lpthread -lm -else +else ifeq ($(UNAME), Windows) # Windows (MinGW) MODULE_EXT := dll LDFLAGS := -shared -lpthread + CFLAGS += -I$(EMACS_ROOT)/include +else + # Fallback / Unknown + MODULE_EXT := so + LDFLAGS := -shared -lpthread endif # Source files @@ -70,7 +89,7 @@ install: $(MODULE) # Test with Emacs test: $(MODULE) - emacs -Q --batch \ + $(EMACS) -Q --batch \ -L . \ --eval '(module-load (expand-file-name "./$(MODULE)"))' \ --eval '(message "ekp-c version: %s" (ekp-c-version))' \ @@ -86,6 +105,7 @@ info: @echo "LDFLAGS: $(LDFLAGS)" @echo "MODULE: $(MODULE)" @echo "UNAME: $(UNAME)" + @echo "EMACS: $(EMACS)" ifdef EMACS_INCLUDE @echo "EMACS_INCLUDE: $(EMACS_INCLUDE)" endif