f331970ae2
Refactor memory allocation patterns: - Replace realloc-in-loop with count-then-allocate pattern across all platforms - Eliminate arbitrary buffer sizes (e.g., malloc(8 * ...)) in favor of exact counts - Reduce allocation overhead by pre-counting items before malloc Fix Windows file watching: - Replace unreliable FindFirstChangeNotification with directory handle approach - Add is_file_ready() to prevent events while compiler is still writing files - Preserve timestamps when file is locked to retry on next poll - Fix do-while loop in platform_directory_init_scan (was skipping first file) Fix Linux inotify event handling: - Consolidate DELETE+CREATE pairs into single RELOAD event - Prevents duplicate events when compiler uses temp-file-and-rename pattern Fix BSD/macOS kqueue implementation: - Remove realloc loops from update_watches() and watch initialization - Pre-count files before allocating file descriptor arrays All platforms now correctly handle: - Compiler overwrites (temp file operations) - Manual copy/move operations - Explicit file deletions Tested on Linux, Windows 10, and FreeBSD.
51 lines
1.2 KiB
Makefile
51 lines
1.2 KiB
Makefile
include config.mk
|
|
|
|
ifeq ($(OS),Windows_NT)
|
|
SHELL := cmd.exe
|
|
FULL_LIB := $(LIB_NAME).dll
|
|
LDFLAGS_PLAT :=
|
|
CFLAGS_PLAT :=
|
|
MKDIR = if not exist $(subst /,\,$(1)) mkdir $(subst /,\,$(1))
|
|
RMDIR = if exist $(subst /,\,$(1)) rd /s /q $(subst /,\,$(1))
|
|
else
|
|
FULL_LIB := lib$(LIB_NAME).so
|
|
LDFLAGS_PLAT := -ldl
|
|
CFLAGS_PLAT := -fPIC
|
|
MKDIR = mkdir -p $(1)
|
|
RMDIR = rm -rf $(1)
|
|
endif
|
|
|
|
CFLAGS_BASE := -Wall -Wpedantic -I$(INC_DIR) -std=c89 $(CFLAGS_PLAT)
|
|
|
|
.PHONY: all debug release clean
|
|
|
|
all: debug
|
|
|
|
debug: $(BIN_DIR)/debug/$(FULL_LIB)
|
|
release: $(BIN_DIR)/release/$(FULL_LIB)
|
|
|
|
# Debug Rules
|
|
$(BIN_DIR)/debug/$(FULL_LIB): $(SRCS:src/%.c=obj/debug/%.o)
|
|
@$(call MKDIR,$(@D))
|
|
$(CC) -shared -o $@ $^ $(LDFLAGS_PLAT)
|
|
|
|
obj/debug/%.o: src/%.c
|
|
@$(call MKDIR,$(@D))
|
|
$(CC) $(CFLAGS_BASE) -g -O0 -MMD -MP -c $< -o $@
|
|
|
|
# Release Rules
|
|
$(BIN_DIR)/release/$(FULL_LIB): $(SRCS:src/%.c=obj/release/%.o)
|
|
@$(call MKDIR,$(@D))
|
|
$(CC) -shared -o $@ $^ $(LDFLAGS_PLAT)
|
|
|
|
obj/release/%.o: src/%.c
|
|
@$(call MKDIR,$(@D))
|
|
$(CC) $(CFLAGS_BASE) -O2 -MMD -MP -c $< -o $@
|
|
|
|
-include $(wildcard obj/debug/*.d)
|
|
-include $(wildcard obj/release/*.d)
|
|
|
|
clean:
|
|
@$(call RMDIR,$(OBJ_DIR))
|
|
@$(call RMDIR,$(BIN_DIR))
|