1 # SPDX-License-Identifier: GPL-2.0
2 include ../scripts/Makefile.include
12 CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/include/uapi -I$(srctree)/include
14 # This will work when bpf is built in tools env. where srctree
15 # isn't set and when invoked from selftests build, where srctree
16 # is set to ".". building_out_of_srctree is undefined for in srctree
21 ifndef building_out_of_srctree
24 ifeq ($(update_srctree),1)
25 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
26 srctree := $(patsubst %/,%,$(dir $(srctree)))
36 FEATURE_TESTS = libbfd disassembler-four-args
37 FEATURE_DISPLAY = libbfd disassembler-four-args
40 NON_CHECK_FEAT_TARGETS := clean bpftool_clean runqslower_clean
42 ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
47 ifeq ($(check_feat),1)
48 ifeq ($(FEATURES_DUMP),)
49 include $(srctree)/tools/build/Makefile.feature
51 include $(FEATURES_DUMP)
55 ifeq ($(feature-disassembler-four-args), 1)
56 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
59 $(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y
60 $(QUIET_BISON)$(YACC) -o $@ -d $<
62 $(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l
63 $(QUIET_FLEX)$(LEX) -o $@ $<
65 $(OUTPUT)%.o: $(srctree)/tools/bpf/%.c
66 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
68 $(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c
69 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
70 $(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c
71 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
73 PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm
75 all: $(PROGS) bpftool runqslower
77 $(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm'
78 $(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o
79 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl
81 $(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o
82 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline
84 $(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o
85 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^
87 $(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c
88 $(OUTPUT)bpf_exp.yacc.o: $(OUTPUT)bpf_exp.yacc.c
89 $(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c
91 clean: bpftool_clean runqslower_clean
92 $(call QUIET_CLEAN, bpf-progs)
93 $(Q)$(RM) -r -- $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \
94 $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.*
95 $(call QUIET_CLEAN, core-gen)
96 $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpf
97 $(Q)$(RM) -r -- $(OUTPUT)feature
99 install: $(PROGS) bpftool_install runqslower_install
100 $(call QUIET_INSTALL, bpf_jit_disasm)
101 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin
102 $(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm
103 $(call QUIET_INSTALL, bpf_dbg)
104 $(Q)$(INSTALL) $(OUTPUT)bpf_dbg $(DESTDIR)$(prefix)/bin/bpf_dbg
105 $(call QUIET_INSTALL, bpf_asm)
106 $(Q)$(INSTALL) $(OUTPUT)bpf_asm $(DESTDIR)$(prefix)/bin/bpf_asm
109 $(call descend,bpftool)
112 $(call descend,bpftool,install)
115 $(call descend,bpftool,clean)
118 $(call descend,runqslower)
121 $(call descend,runqslower,install)
124 $(call descend,runqslower,clean)
126 .PHONY: all install clean bpftool bpftool_install bpftool_clean \
127 runqslower runqslower_install runqslower_clean