# Build the Linux BOF loader as the shared object shipped with this module.
#
# Both agents map it as the coffloader_linux dependency: the C agent through
# dynload, the Go agent through memmod (core/lib/coffloader). Keep this the
# single source of the loader.
#
# Hosted artifact: glibc is linked dynamically and pinned to ABI 2.17.
# The C2 runs this on every module invocation; the build is idempotent.
CC = zig cc
ZIG_TARGET ?= x86_64-linux-gnu.2.17
CFLAGS = -O2 -fPIC -std=c99 -Wall -Wextra -Werror -fvisibility=hidden \
         -fno-builtin -fno-stack-protector -fno-sanitize=all -fno-ident \
         -ffunction-sections -fdata-sections
LDFLAGS = -shared -Wl,--gc-sections -Wl,--build-id=none -Wl,-z,noexecstack \
          -Wl,--hash-style=both
TARGET = coffloader_linux.so
SOURCES = loader_linux.c beacon_compat.c

all: $(TARGET)

$(TARGET): $(SOURCES)
	$(CC) -target $(ZIG_TARGET) $(CFLAGS) $(LDFLAGS) -o $@ $(SOURCES)
	@command -v strip >/dev/null 2>&1 && \
	  strip --remove-section=.comment $@ || true

clean:
	rm -f $(TARGET)
