1 # SPDX-License-Identifier: GPL-2.0
2 include ../scripts/Makefile.include
13 CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/include/uapi -I$(srctree)/include
15 # This will work when bpf is built in tools env. where srctree
16 # isn't set and when invoked from selftests build, where srctree
17 # is set to ".". building_out_of_srctree is undefined for in srctree
19 ifndef building_out_of_srctree
20 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
21 srctree := $(patsubst %/,%,$(dir $(srctree)))
31 FEATURE_TESTS = libbfd disassembler-four-args
32 FEATURE_DISPLAY = libbfd disassembler-four-args
35 NON_CHECK_FEAT_TARGETS := clean bpftool_clean
37 ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
42 ifeq ($(check_feat),1)
43 ifeq ($(FEATURES_DUMP),)
44 include $(srctree)/tools/build/Makefile.feature
46 include $(FEATURES_DUMP)
50 ifeq ($(feature-disassembler-four-args), 1)
51 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
54 $(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y
55 $(QUIET_BISON)$(YACC) -o $@ -d $<
57 $(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l
58 $(QUIET_FLEX)$(LEX) -o $@ $<
60 $(OUTPUT)%.o: $(srctree)/tools/bpf/%.c
61 $(QUIET_CC)$(COMPILE.c) -o $@ $<
63 $(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c
64 $(QUIET_CC)$(COMPILE.c) -o $@ $<
65 $(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c
66 $(QUIET_CC)$(COMPILE.c) -o $@ $<
68 PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm
72 $(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm'
73 $(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o
74 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl
76 $(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o
77 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline
79 $(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o
80 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^
82 $(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c
83 $(OUTPUT)bpf_exp.yacc.o: $(OUTPUT)bpf_exp.yacc.c
84 $(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c
87 $(call QUIET_CLEAN, bpf-progs)
88 $(Q)$(RM) -r -- $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \
89 $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.*
90 $(call QUIET_CLEAN, core-gen)
91 $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpf
92 $(Q)$(RM) -r -- $(OUTPUT)feature
94 install: $(PROGS) bpftool_install
95 $(call QUIET_INSTALL, bpf_jit_disasm)
96 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin
97 $(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm
98 $(call QUIET_INSTALL, bpf_dbg)
99 $(Q)$(INSTALL) $(OUTPUT)bpf_dbg $(DESTDIR)$(prefix)/bin/bpf_dbg
100 $(call QUIET_INSTALL, bpf_asm)
101 $(Q)$(INSTALL) $(OUTPUT)bpf_asm $(DESTDIR)$(prefix)/bin/bpf_asm
104 $(call descend,bpftool)
107 $(call descend,bpftool,install)
110 $(call descend,bpftool,clean)
112 .PHONY: all install clean bpftool bpftool_install bpftool_clean