# Step 07 -- Build COFFLoader with full Beacon compatibility layer
#
# Usage:
#   make          -- build COFFLoader.exe and hello_bof.o
#   make run      -- build and run the loader on hello_bof.o
#   make clean    -- remove build artifacts
#
# The loader is built with MinGW (gcc).  The BOF is cross-compiled
# with MinGW as a relocatable object (-c).

# --- Toolchain ---
CC       = gcc
CC_MINGW = x86_64-w64-mingw32-gcc
CFLAGS   = -Wall -Wextra
LDFLAGS  = -lkernel32 -luser32 -ladvapi32

# --- Targets ---
all: COFFLoader.exe hello_bof.o

# Build the COFF loader executable from both source files
COFFLoader.exe: COFFLoader.c beacon_compatibility.c COFFLoader.h beacon_compatibility.h
	$(CC) $(CFLAGS) -o COFFLoader.exe COFFLoader.c beacon_compatibility.c $(LDFLAGS)

# Cross-compile the BOF as a relocatable object (no linking)
hello_bof.o: hello_bof.c beacon.h
	$(CC_MINGW) -c hello_bof.c -o hello_bof.o

# Build and run the loader on hello_bof.o
run: COFFLoader.exe hello_bof.o
	./COFFLoader.exe go hello_bof.o

clean:
	rm -f COFFLoader.exe hello_bof.o *.obj

.PHONY: all run clean
