# Copyright Epic Games, Inc. All Rights Reserved.
# SPDX-License-Identifier: GPL-2.0-only

CLANG?=clang
BPFTOOL?=bpftool

BPF_SOURCE=ProcessProtection.bpf.c
BPF_OBJECT=ProcessProtection.bpf.o
BPF_SKELETON=ProcessProtection.lskel.h
BPF_VMLINUX=vmlinux.h
BPF_HEADERS=ProcessProtectionEvents.h ProcessProtectionHelpers.bpf.h

BPF_CFLAGS=-target bpf -D__TARGET_ARCH_x86 -O2 -g -Wall -Wno-missing-declarations -I.

.PHONY: all clean

all: $(BPF_SKELETON)

$(BPF_VMLINUX):
	$(BPFTOOL) btf dump file /sys/kernel/btf/vmlinux format c > $@

$(BPF_OBJECT): $(BPF_SOURCE) $(BPF_VMLINUX) $(BPF_HEADERS)
	$(CLANG) $(BPF_CFLAGS) -c $(BPF_SOURCE) -o $@

$(BPF_SKELETON): $(BPF_OBJECT)
	$(BPFTOOL) gen skeleton -L $(BPF_OBJECT) > $@

clean:
	rm -f $(BPF_OBJECT) $(BPF_SKELETON) $(BPF_VMLINUX)
