From cfd267a56a2bfc34afc49f4b3be86965a5b56112 Mon Sep 17 00:00:00 2001 From: Ariel Otilibili Date: Mon, 9 Sep 2024 17:47:44 +0200 Subject: [PATCH] ebpf_prog/Makefile: temp files are now handled by a pattern rule * `%.bc` are autoremoved: these LLVM IR files are intermediate [1] * `%.o` are now produced by a wildcard search * introduced `.SUFFIXES:` for cleaning up the implicit rules [2] * else Makefile would have generated `%.o` from its own database. [1] https://www.gnu.org/software/make/manual/html_node/Chained-Rules.html [2] https://www.gnu.org/software/make/manual/html_node/Suffix-Rules.html Signed-off-by: Ariel Otilibili --- ebpf_prog/Makefile | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/ebpf_prog/Makefile b/ebpf_prog/Makefile index 25239506ab..180db955df 100644 --- a/ebpf_prog/Makefile +++ b/ebpf_prog/Makefile @@ -5,7 +5,7 @@ # KERNEL_DIR ?= /lib/modules/$(shell uname -r)/source KERNEL_HEADERS ?= /usr/src/linux-headers-$(shell uname -r)/ -CLANG ?= clang +CC = clang LLC ?= llc LLVM_STRIP ?= llvm-strip -g ARCH ?= $(shell uname -m) @@ -27,8 +27,9 @@ ifeq ($(ARCH),arm) EXTRA_FLAGS = "-D__LINUX_ARM_ARCH__=7" endif -BIN := opensnitch.o opensnitch-procs.o opensnitch-dns.o -CLANG_FLAGS = -I. \ +SRC := $(wildcard *.c) +BIN := $(SRC:.c=.o) +CFLAGS = -I. \ -I$(KERNEL_HEADERS)/arch/$(ARCH)/include/generated/ \ -I$(KERNEL_HEADERS)/include \ -include $(KERNEL_DIR)/include/linux/kconfig.h \ @@ -54,10 +55,13 @@ CLANG_FLAGS = -I. \ all: $(BIN) -%.o: %.c - $(CLANG) $(CLANG_FLAGS) -c $< -o $@.partial - $(LLC) -march=bpf -mcpu=generic -filetype=obj -o $@ $@.partial - rm -f $@.partial +%.bc: %.c + $(CC) $(CFLAGS) -c $< + +%.o: %.bc + $(LLC) -march=bpf -mcpu=generic -filetype=obj -o $@ $< clean: - rm -f *.o *.partial + rm -f $(BIN) + +.SUFFIXES: