bpf: Compile resolve_btfids tool at kernel compilation start
[linux-2.6-microblaze.git] / tools / bpf / Makefile
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)/include/uapi -I$(srctree)/include
13
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
17 # builds
18 ifeq ($(srctree),)
19 update_srctree := 1
20 endif
21 ifndef building_out_of_srctree
22 update_srctree := 1
23 endif
24 ifeq ($(update_srctree),1)
25 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
26 srctree := $(patsubst %/,%,$(dir $(srctree)))
27 endif
28
29 ifeq ($(V),1)
30   Q =
31 else
32   Q = @
33 endif
34
35 FEATURE_USER = .bpf
36 FEATURE_TESTS = libbfd disassembler-four-args
37 FEATURE_DISPLAY = libbfd disassembler-four-args
38
39 check_feat := 1
40 NON_CHECK_FEAT_TARGETS := clean bpftool_clean runqslower_clean
41 ifdef MAKECMDGOALS
42 ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
43   check_feat := 0
44 endif
45 endif
46
47 ifeq ($(check_feat),1)
48 ifeq ($(FEATURES_DUMP),)
49 include $(srctree)/tools/build/Makefile.feature
50 else
51 include $(FEATURES_DUMP)
52 endif
53 endif
54
55 ifeq ($(feature-disassembler-four-args), 1)
56 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
57 endif
58
59 $(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y
60         $(QUIET_BISON)$(YACC) -o $@ -d $<
61
62 $(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l
63         $(QUIET_FLEX)$(LEX) -o $@ $<
64
65 $(OUTPUT)%.o: $(srctree)/tools/bpf/%.c
66         $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
67
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 $@ $<
72
73 PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm
74
75 all: $(PROGS) bpftool runqslower
76
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
80
81 $(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o
82         $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline
83
84 $(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o
85         $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^
86
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
90
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
98
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
107
108 bpftool:
109         $(call descend,bpftool)
110
111 bpftool_install:
112         $(call descend,bpftool,install)
113
114 bpftool_clean:
115         $(call descend,bpftool,clean)
116
117 runqslower:
118         $(call descend,runqslower)
119
120 runqslower_install:
121         $(call descend,runqslower,install)
122
123 runqslower_clean:
124         $(call descend,runqslower,clean)
125
126 resolve_btfids:
127         $(call descend,resolve_btfids)
128
129 resolve_btfids_clean:
130         $(call descend,resolve_btfids,clean)
131
132 .PHONY: all install clean bpftool bpftool_install bpftool_clean \
133         runqslower runqslower_install runqslower_clean \
134         resolve_btfids resolve_btfids_clean