From 586733f2ebb0452e737f7faf54d81c7d6e6a679e Mon Sep 17 00:00:00 2001 From: anth64 Date: Mon, 20 Oct 2025 22:42:04 +0200 Subject: [PATCH] Makefile detect os (windows/posix) --- Makefile | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index d6a6ceb..1ffd073 100644 --- a/Makefile +++ b/Makefile @@ -11,11 +11,21 @@ OBJS_RELEASE := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/release/%.o,$(SRCS)) # Compiler and flags CC := gcc -CFLAGS_DEBUG := -g -O0 -Wall -Wpedantic -I$(INC_DIR) -std=c89 -fPIC -CFLAGS_RELEASE := -O2 -Wall -Wpedantic -I$(INC_DIR) -std=c89 -fPIC +CFLAGS_DEBUG := -g -O0 -Wall -Wpedantic -I$(INC_DIR) -std=c89 +CFLAGS_RELEASE := -O2 -Wall -Wpedantic -I$(INC_DIR) -std=c89 -# Library name -LIB_NAME := libstk.so +# Platform detection +ifeq ($(OS),Windows_NT) + LIB_NAME := stk.dll + LDFLAGS := + CFLAGS_DEBUG += -D_WIN32 + CFLAGS_RELEASE += -D_WIN32 +else + LIB_NAME := libstk.so + LDFLAGS := -ldl + CFLAGS_DEBUG += -fPIC + CFLAGS_RELEASE += -fPIC +endif # Default build all: debug @@ -27,11 +37,11 @@ release: $(BIN_DIR)/release/$(LIB_NAME) # Build shared library $(BIN_DIR)/debug/$(LIB_NAME): $(OBJS_DEBUG) @mkdir -p $(BIN_DIR)/debug - $(CC) -shared -o $@ $^ + $(CC) -shared -o $@ $^ $(LDFLAGS) $(BIN_DIR)/release/$(LIB_NAME): $(OBJS_RELEASE) @mkdir -p $(BIN_DIR)/release - $(CC) -shared -o $@ $^ + $(CC) -shared -o $@ $^ $(LDFLAGS) # Compile object files with header dependency tracking $(OBJ_DIR)/debug/%.o: $(SRC_DIR)/%.c