LLC ?= llc
CLANG ?= clang
CC ?= gcc

ARCH := arm64
INCLUDES := -I/usr/include/bpf -I/usr/include/ -I/usr/include/x86_64-linux-gnu
LIBS := -lbpf -lelf -lz
CFLAGS := -g -O2

all: bridge_xdp.o loader

bridge_xdp.o: bridge_xdp.c
	$(CLANG) -S \
	    -target bpf \
	    -D __BPF_TRACING__ \
	    $(INCLUDES) \
	    -Wall \
	    $(CFLAGS) \
	    -g \
	    -emit-llvm -c -o bridge_xdp.ll bridge_xdp.c
	$(LLC) -march=bpf -mcpu=v3 -mattr=+alu32 -filetype=obj \
	    -debugger-tune=gdb \
	    -o bridge_xdp.o bridge_xdp.ll

loader: loader.c
	$(CC) -Wall $(INCLUDES) $(CFLAGS) -o loader loader.c $(LIBS)

clean:
	rm -f bridge_xdp.o bridge_xdp.ll loader
