Debian Codegraph @

tools/bpf/Makefile

raw
1 # SPDX-License-Identifier: GPL-2.0
2 include ../scripts/Makefile.include
3
4 prefix ?= /usr/local
5
6 LEX = flex
7 YACC = bison
8 MAKE = make
9 INSTALL ?= install
10
11 CFLAGS += -Wall -O2
12 CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi \
13 -I$(srctree)/tools/include
14
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
18 # builds
19 ifeq ($(srctree),)
20 update_srctree := 1
21 endif
22 ifndef building_out_of_srctree
23 update_srctree := 1
24 endif
25 ifeq ($(update_srctree),1)
26 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
27 srctree := $(patsubst %/,%,$(dir $(srctree)))
28 endif
29
30 FEATURE_USER = .bpf
31 FEATURE_TESTS = libbfd disassembler-four-args disassembler-init-styled
32 FEATURE_DISPLAY = libbfd
33
34 check_feat := 1
35 NON_CHECK_FEAT_TARGETS := clean bpftool_clean resolve_btfids_clean
36 ifdef MAKECMDGOALS
37 ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
38 check_feat := 0
39 endif
40 endif
41
42 ifeq ($(check_feat),1)
43 ifeq ($(FEATURES_DUMP),)
44 include $(srctree)/tools/build/Makefile.feature
45 else
46 include $(FEATURES_DUMP)
47 endif
48 endif
49
50 ifeq ($(feature-disassembler-four-args), 1)
51 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
52 endif
53 ifeq ($(feature-disassembler-init-styled), 1)
54 CFLAGS += -DDISASM_INIT_STYLED
55 endif
56
57 $(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y
58 $(QUIET_BISON)$(YACC) -o $@ -d $<
59
60 $(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l
61 $(QUIET_FLEX)$(LEX) -o $@ $<
62
63 $(OUTPUT)%.o: $(srctree)/tools/bpf/%.c
64 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
65
66 $(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c
67 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
68 $(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c
69 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
70
71 PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm
72
73 all: $(PROGS) bpftool
74
75 $(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm'
76 $(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o
77 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl
78
79 $(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o
80 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline
81
82 $(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o
83 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^
84
85 $(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c
86 $(OUTPUT)bpf_exp.yacc.o: $(OUTPUT)bpf_exp.yacc.c
87 $(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c
88
89 clean: bpftool_clean resolve_btfids_clean
90 $(call QUIET_CLEAN, bpf-progs)
91 $(Q)$(RM) -r -- $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \
92 $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.*
93 $(call QUIET_CLEAN, core-gen)
94 $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpf
95 $(Q)$(RM) -r -- $(OUTPUT)feature
96
97 install: $(PROGS) bpftool_install
98 $(call QUIET_INSTALL, bpf_jit_disasm)
99 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin
100 $(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm
101 $(call QUIET_INSTALL, bpf_dbg)
102 $(Q)$(INSTALL) $(OUTPUT)bpf_dbg $(DESTDIR)$(prefix)/bin/bpf_dbg
103 $(call QUIET_INSTALL, bpf_asm)
104 $(Q)$(INSTALL) $(OUTPUT)bpf_asm $(DESTDIR)$(prefix)/bin/bpf_asm
105
106 bpftool:
107 $(call descend,bpftool)
108
109 bpftool_install:
110 $(call descend,bpftool,install)
111
112 bpftool_clean:
113 $(call descend,bpftool,clean)
114
115 resolve_btfids:
116 $(call descend,resolve_btfids)
117
118 resolve_btfids_clean:
119 $(call descend,resolve_btfids,clean)
120
121 .PHONY: all install clean bpftool bpftool_install bpftool_clean \
122 resolve_btfids resolve_btfids_clean