Skip to content

Commit

Permalink
tetragon: Simplify standard object/dependency build
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
olsajiri committed Nov 26, 2024
1 parent 56ef1e2 commit b9e03b6
Showing 1 changed file with 22 additions and 50 deletions.
72 changes: 22 additions & 50 deletions bpf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ CFLAGS_v53 = -D__LARGE_BPF_PROG
CFLAGS_v511 = -D__LARGE_BPF_PROG -D__LARGE_MAP_KEYS
CFLAGS_v61 = -D__LARGE_BPF_PROG -D__LARGE_MAP_KEYS -D__V61_BPF_PROG

CFLAGS_bpf_enforcer.o = -D__BPF_OVERRIDE_RETURN
CFLAGS_bpf_multi_enforcer.o = -D__BPF_OVERRIDE_RETURN -D__MULTI_KPROBE
CFLAGS_bpf_generic_lsm_core.o = -D__LARGE_BPF_PROG
CFLAGS_bpf_generic_lsm_output.o = -D__LARGE_BPF_PROG

rule_d_FLAGS = $(CFLAGS_$(notdir $(MTARGET)))
rule_o_FLAGS = $(CFLAGS_$(notdir $@))

rule_d = $(CLANG) $(CLANG_FLAGS) $(rule_d_FLAGS) $1 -MM -MP -MT $(MTARGET) $< > $@
rule_o = $(CLANG) $(CLANG_FLAGS) $(rule_o_FLAGS) $1 -c $< -o $@

VARIANT_FLAGS = $$(CFLAGS_$1)

define DEFINE_VARIANT
Expand All @@ -87,17 +98,17 @@ deps/bpf_generic_lsm_ima_bprm_$$(VAR).d: process/bpf_generic_lsm_ima_bprm.c
deps/bpf_generic_lsm_ima_file_$$(VAR).d: process/bpf_generic_lsm_ima_file.c

$(OBJSDIR)%_$$(VAR).o:
$(CLANG) $(CLANG_FLAGS) $(VARIANT_FLAGS) -c $$< -o $$@
$$(call rule_o,$(VARIANT_FLAGS))

$(DEPSDIR)%_$$(VAR).d:
$(CLANG) $(CLANG_FLAGS) $(VARIANT_FLAGS) -MM -MP -MT $$(MTARGET) $$< > $$@
$$(call rule_d,$(VARIANT_FLAGS))

$(OBJSDIR)bpf_multi_kprobe_$$(VAR).o $(OBJSDIR)bpf_multi_retkprobe_$$(VAR).o:
$(CLANG) $(CLANG_FLAGS) $(VARIANT_FLAGS) -D__MULTI_KPROBE -c $$< -o $$@
$$(call rule_o,$(VARIANT_FLAGS) -D__MULTI_KPROBE)

ifeq (v61,$$(VAR))
$(OBJSDIR)bpf_multi_uprobe_$$(VAR).o:
$(CLANG) $(CLANG_FLAGS) $(VARIANT_FLAGS) -D__MULTI_KPROBE -c $$< -o $$@
$$(call rule_o,$(VARIANT_FLAGS) -D__MULTI_KPROBE)
endif

endef
Expand All @@ -109,59 +120,20 @@ $(eval $(call DEFINE_VARIANT,v511))
$(eval $(call DEFINE_VARIANT,v61))

objs/%.o:
$(CLANG) $(CLANG_FLAGS) -c $< -o $@
$(rule_o)

$(DEPSDIR)%.d: $(ALIGNCHECKERDIR)%.c
$(CLANG) $(CLANG_FLAGS) -MM -MP -MT $(MTARGET) $< > $@


# Enforcer programs: bpf_enforcer, bpf_multi_enforcer, bpf_fmodret_enforcer

## bpf_enforcer: __BPF_OVERRIDE_RETURN, but no __MULTI_KPROBE
objs/bpf_enforcer.o:
$(CLANG) $(CLANG_FLAGS) -D__BPF_OVERRIDE_RETURN -c $< -o $@

$(DEPSDIR)bpf_enforcer.d: process/bpf_enforcer.c
$(CLANG) $(CLANG_FLAGS) -D__BPF_OVERRIDE_RETURN -MM -MP -MT $(MTARGET) $< > $@

## bpf_multi_enforcer: __BPF_OVERRIDE_RETURN and __MULTI_KPROBE
objs/bpf_multi_enforcer.o:
$(CLANG) $(CLANG_FLAGS) -D__BPF_OVERRIDE_RETURN -D__MULTI_KPROBE -c $< -o $@

$(rule_d)
$(DEPSDIR)bpf_multi_enforcer.d: process/bpf_enforcer.c
$(CLANG) $(CLANG_FLAGS) -D__BPF_OVERRIDE_RETURN -D__MULTI_KPROBE -MM -MP -MT $(MTARGET) $< > $@

## bpf_fmodret_enforcer no bpf_override_return: we need fmod_ret
objs/bpf_fmodret_enforcer.o:
$(CLANG) $(CLANG_FLAGS) -c $< -o $@

$(rule_d)
$(DEPSDIR)bpf_fmodret_enforcer.d: process/bpf_enforcer.c
$(CLANG) $(CLANG_FLAGS) -MM -MP -MT $(MTARGET) $< > $@

# PROCESSDIR
$(rule_d)
$(DEPSDIR)%.d: $(PROCESSDIR)%.c
$(CLANG) $(CLANG_FLAGS) -MM -MP -MT $(MTARGET) $< > $@

objs/bpf_generic_lsm_core.o:
$(CLANG) $(CLANG_FLAGS) -D__LARGE_BPF_PROG -c $< -o $@

$(DEPSDIR)/bpf_generic_lsm_core.d:
$(CLANG) $(CLANG_FLAGS) -D__LARGE_BPF_PROG -MM -MP -MT $(MTARGET) $< > $@

objs/bpf_generic_lsm_output.o:
$(CLANG) $(CLANG_FLAGS) -D__LARGE_BPF_PROG -c $< -o $@

$(DEPSDIR)/bpf_generic_lsm_output.d:
$(CLANG) $(CLANG_FLAGS) -D__LARGE_BPF_PROG -MM -MP -MT $(MTARGET) $< > $@


# BPFTESTDIR
$(rule_d)
$(DEPSDIR)%.d: $(BPFTESTDIR)%.c
$(CLANG) $(CLANG_FLAGS) -MM -MP -MT $(MTARGET) $< > $@

# CGROUPDIR
$(rule_d)
$(DEPSDIR)%.d: $(CGROUPDIR)%.c
$(CLANG) $(CLANG_FLAGS) -MM -MP -MT $(MTARGET) $< > $@
$(rule_d)

# include dependencies, see https://lists.gnu.org/archive/html/make-w32/2004-03/msg00062.html
ifeq (,$(filter $(MAKECMDGOALS),clean run-test))
Expand Down

0 comments on commit b9e03b6

Please sign in to comment.