Makefile supports multiple plantform

This commit is contained in:
Kinneyzhang 2026-01-26 11:51:19 +08:00
parent 136e53fe8e
commit 262b5eefdc
4 changed files with 60 additions and 4 deletions

View File

@ -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).

View File

@ -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).

View File

@ -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`

View File

@ -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