@@ -3,11 +3,25 @@ if BUILD_EBPF
# Maintaining a local copy of UAPI linux/bpf.h
BPF_CFLAGS = -Iinclude
-all: lb.bpf filter.bpf bypass_filter.bpf xdp_filter.bpf vlan_filter.bpf
+CLANG = ${CC}
-%.bpf: %.c
- ${CC} -Wall $(BPF_CFLAGS) -O2 -D__KERNEL__ -D__ASM_SYSREG_H -target bpf -emit-llvm -c $< -o - | ${LLC} -march=bpf -filetype=obj -o $@
+BPF_TARGETS = lb.bpf
+BPF_TARGETS += filter.bpf
+BPF_TARGETS += bypass_filter.bpf
+BPF_TARGETS += xdp_filter.bpf
+BPF_TARGETS += vlan_filter.bpf
-CLEANFILES = *.bpf
+all: $(BPF_TARGETS)
+
+$(BPF_TARGETS): %.bpf: %.c
+# From C-code to LLVM-IR format suffix .ll (clang -S -emit-llvm)
+ ${CLANG} -Wall $(BPF_CFLAGS) -O2 \
+ -D__KERNEL__ -D__ASM_SYSREG_H \
+ -target bpf -S -emit-llvm $< -o ${@:.bpf=.ll}
+# From LLVM-IR to BPF-bytecode in ELF-obj file
+ ${LLC} -march=bpf -filetype=obj ${@:.bpf=.ll} -o $@
+ ${RM} ${@:.bpf=.ll}
+
+CLEANFILES = *.bpf *.ll
endif