1 # SPDX-License-Identifier: GPL-2.0
2 include ../scripts/Makefile.include
12 CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi \
13 -I$(srctree)/tools/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
22 ifndef building_out_of_srctree
25 ifeq ($(update_srctree),1)
26 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
27 srctree := $(patsubst %/,%,$(dir $(srctree)))
37 FEATURE_TESTS = libbfd disassembler-four-args disassembler-init-styled
38 FEATURE_DISPLAY = libbfd
41 NON_CHECK_FEAT_TARGETS := clean bpftool_clean runqslower_clean resolve_btfids_clean
43 ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
48 ifeq ($(check_feat),1)
49 ifeq ($(FEATURES_DUMP),)
50 include $(srctree)/tools/build/Makefile.feature
52 include $(FEATURES_DUMP)
56 ifeq ($(feature-disassembler-four-args), 1)
57 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
59 ifeq ($(feature-disassembler-init-styled), 1)
60 CFLAGS += -DDISASM_INIT_STYLED
63 $(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y
64 $(QUIET_BISON)$(YACC) -o $@ -d $<
66 $(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l
67 $(QUIET_FLEX)$(LEX) -o $@ $<
69 $(OUTPUT)%.o: $(srctree)/tools/bpf/%.c
70 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
72 $(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c
73 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
74 $(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c
75 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
77 PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm
79 all: $(PROGS) bpftool runqslower
81 $(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm'
82 $(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o
83 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl
85 $(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o
86 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline
88 $(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o
89 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^
91 $(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c
92 $(OUTPUT)bpf_exp.yacc.o: $(OUTPUT)bpf_exp.yacc.c
93 $(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c
95 clean: bpftool_clean runqslower_clean resolve_btfids_clean
96 $(call QUIET_CLEAN, bpf-progs)
97 $(Q)$(RM) -r -- $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \
98 $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.*
99 $(call QUIET_CLEAN, core-gen)
100 $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpf
101 $(Q)$(RM) -r -- $(OUTPUT)feature
103 install: $(PROGS) bpftool_install
104 $(call QUIET_INSTALL, bpf_jit_disasm)
105 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin
106 $(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm
107 $(call QUIET_INSTALL, bpf_dbg)
108 $(Q)$(INSTALL) $(OUTPUT)bpf_dbg $(DESTDIR)$(prefix)/bin/bpf_dbg
109 $(call QUIET_INSTALL, bpf_asm)
110 $(Q)$(INSTALL) $(OUTPUT)bpf_asm $(DESTDIR)$(prefix)/bin/bpf_asm
113 $(call descend,bpftool)
116 $(call descend,bpftool,install)
119 $(call descend,bpftool,clean)
122 $(call descend,runqslower)
125 $(call descend,runqslower,clean)
128 $(call descend,resolve_btfids)
130 resolve_btfids_clean:
131 $(call descend,resolve_btfids,clean)
133 .PHONY: all install clean bpftool bpftool_install bpftool_clean \
134 runqslower runqslower_clean \
135 resolve_btfids resolve_btfids_clean