Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1# SPDX-License-Identifier: GPL-2.0
2include ../scripts/Makefile.include
3
4prefix ?= /usr/local
5
6LEX = flex
7YACC = bison
8MAKE = make
9INSTALL ?= install
10
11CFLAGS += -Wall -O2
12CFLAGS += -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
19ifeq ($(srctree),)
20update_srctree := 1
21endif
22ifndef building_out_of_srctree
23update_srctree := 1
24endif
25ifeq ($(update_srctree),1)
26srctree := $(patsubst %/,%,$(dir $(CURDIR)))
27srctree := $(patsubst %/,%,$(dir $(srctree)))
28endif
29
30FEATURE_USER = .bpf
31FEATURE_TESTS = libbfd disassembler-four-args disassembler-init-styled
32FEATURE_DISPLAY = libbfd
33
34check_feat := 1
35NON_CHECK_FEAT_TARGETS := clean bpftool_clean resolve_btfids_clean
36ifdef MAKECMDGOALS
37ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
38 check_feat := 0
39endif
40endif
41
42ifeq ($(check_feat),1)
43ifeq ($(FEATURES_DUMP),)
44include $(srctree)/tools/build/Makefile.feature
45else
46include $(FEATURES_DUMP)
47endif
48endif
49
50ifeq ($(feature-disassembler-four-args), 1)
51CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
52endif
53ifeq ($(feature-disassembler-init-styled), 1)
54CFLAGS += -DDISASM_INIT_STYLED
55endif
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
71PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm
72
73all: $(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
89clean: 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
97install: $(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
106bpftool:
107 $(call descend,bpftool)
108
109bpftool_install:
110 $(call descend,bpftool,install)
111
112bpftool_clean:
113 $(call descend,bpftool,clean)
114
115resolve_btfids:
116 $(call descend,resolve_btfids)
117
118resolve_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