Makefile detect os (windows/posix)

This commit is contained in:
2025-10-20 22:42:04 +02:00
parent 9d51be7a18
commit 586733f2eb
+16 -6
View File
@@ -11,11 +11,21 @@ OBJS_RELEASE := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/release/%.o,$(SRCS))
# Compiler and flags # Compiler and flags
CC := gcc CC := gcc
CFLAGS_DEBUG := -g -O0 -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 -fPIC CFLAGS_RELEASE := -O2 -Wall -Wpedantic -I$(INC_DIR) -std=c89
# Library name # Platform detection
LIB_NAME := libstk.so 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 # Default build
all: debug all: debug
@@ -27,11 +37,11 @@ release: $(BIN_DIR)/release/$(LIB_NAME)
# Build shared library # Build shared library
$(BIN_DIR)/debug/$(LIB_NAME): $(OBJS_DEBUG) $(BIN_DIR)/debug/$(LIB_NAME): $(OBJS_DEBUG)
@mkdir -p $(BIN_DIR)/debug @mkdir -p $(BIN_DIR)/debug
$(CC) -shared -o $@ $^ $(CC) -shared -o $@ $^ $(LDFLAGS)
$(BIN_DIR)/release/$(LIB_NAME): $(OBJS_RELEASE) $(BIN_DIR)/release/$(LIB_NAME): $(OBJS_RELEASE)
@mkdir -p $(BIN_DIR)/release @mkdir -p $(BIN_DIR)/release
$(CC) -shared -o $@ $^ $(CC) -shared -o $@ $^ $(LDFLAGS)
# Compile object files with header dependency tracking # Compile object files with header dependency tracking
$(OBJ_DIR)/debug/%.o: $(SRC_DIR)/%.c $(OBJ_DIR)/debug/%.o: $(SRC_DIR)/%.c