# Compiler
CC = x86_64-w64-mingw32-gcc

# Base flags
CFLAGS = -Wall -w -IInclude
LFLAGS = -liphlpapi -lnetapi32 -lwininet -lws2_32 -lwinhttp -mwindows
# Console flags (no -mwindows) for debug console output
LFLAGS_CONSOLE = -liphlpapi -lnetapi32 -lwininet -lws2_32 -lwinhttp
DFLAGS = -D_DEBUG -DDEBUG_SOCKS -g

# Directories
SRC_FILES := *.c
BUILD_DIR = build

# Ensure build directory exists
$(shell mkdir -p $(BUILD_DIR))

# Build Targets
all: exe dll
debug: debug_exe debug_dll

exe: $(BUILD_DIR)/cazalla.exe
dll: $(BUILD_DIR)/cazalla.dll
debug_exe: $(BUILD_DIR)/cazalla-debug.exe
debug_dll: $(BUILD_DIR)/cazalla-debug.dll

# Executable Target
$(BUILD_DIR)/cazalla.exe: $(SRC_FILES)
	$(CC) $^ -o $@ $(CFLAGS) -s -D_EXE $(LFLAGS)

$(BUILD_DIR)/cazalla-debug.exe: $(SRC_FILES)
	$(CC) $^ -o $@ $(CFLAGS) -D_EXE $(LFLAGS_CONSOLE) $(DFLAGS)

# DLL Target
$(BUILD_DIR)/cazalla.dll: $(SRC_FILES)
	$(CC) $^ -o $@ -shared -D_DLL $(CFLAGS) -s $(LFLAGS)

$(BUILD_DIR)/cazalla-debug.dll: $(SRC_FILES)
	$(CC) $^ -o $@ -shared -D_DLL $(CFLAGS) $(LFLAGS) $(DFLAGS)

# Optional: file-logging debug build (writes to C:\\Temp\\Ra.log)
debug_log: $(BUILD_DIR)/cazalla-debug-log.exe
$(BUILD_DIR)/cazalla-debug-log.exe: $(SRC_FILES)
	$(CC) $^ -o $@ $(CFLAGS) -D_EXE -D_DEBUG_RELEASE $(LFLAGS_CONSOLE) $(DFLAGS)

# Clean up
clean:
	rm -rf $(BUILD_DIR)
