# Step 04 -- Build the partial COFF section loader + test BOF
#
# Usage:
#   make                -- build COFFLoader.exe and hello_bof.o
#   make inspect        -- run the loader on hello_bof.o
#   make msvc           -- build COFFLoader.exe with MSVC
#   make clean          -- remove compiled files

CC_MINGW = x86_64-w64-mingw32-gcc
CC_HOST  = gcc
CFLAGS   = -c

all: COFFLoader.exe hello_bof.o

# Build the loader as a normal Windows program (linked with kernel32)
COFFLoader.exe: COFFLoader.c COFFLoader.h
	$(CC_HOST) COFFLoader.c -o COFFLoader.exe -lkernel32

# Build the BOF as a raw object file (compile only, no linking)
hello_bof.o: hello_bof.c beacon.h
	$(CC_MINGW) $(CFLAGS) hello_bof.c -o hello_bof.o

# Run the loader on the test BOF to see section loading output
inspect: COFFLoader.exe hello_bof.o
	./COFFLoader.exe hello_bof.o

# MSVC build (run from a VS Developer Command Prompt)
msvc: COFFLoader.c COFFLoader.h
	cl.exe COFFLoader.c /Fe:COFFLoader.exe

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