xref: /openbmc/linux/tools/bpf/Makefile (revision 55fd7e02)
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)/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
18ifeq ($(srctree),)
19update_srctree := 1
20endif
21ifndef building_out_of_srctree
22update_srctree := 1
23endif
24ifeq ($(update_srctree),1)
25srctree := $(patsubst %/,%,$(dir $(CURDIR)))
26srctree := $(patsubst %/,%,$(dir $(srctree)))
27endif
28
29ifeq ($(V),1)
30  Q =
31else
32  Q = @
33endif
34
35FEATURE_USER = .bpf
36FEATURE_TESTS = libbfd disassembler-four-args
37FEATURE_DISPLAY = libbfd disassembler-four-args
38
39check_feat := 1
40NON_CHECK_FEAT_TARGETS := clean bpftool_clean runqslower_clean
41ifdef MAKECMDGOALS
42ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
43  check_feat := 0
44endif
45endif
46
47ifeq ($(check_feat),1)
48ifeq ($(FEATURES_DUMP),)
49include $(srctree)/tools/build/Makefile.feature
50else
51include $(FEATURES_DUMP)
52endif
53endif
54
55ifeq ($(feature-disassembler-four-args), 1)
56CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
57endif
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
73PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm
74
75all: $(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
91clean: 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
99install: $(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
108bpftool:
109	$(call descend,bpftool)
110
111bpftool_install:
112	$(call descend,bpftool,install)
113
114bpftool_clean:
115	$(call descend,bpftool,clean)
116
117runqslower:
118	$(call descend,runqslower)
119
120runqslower_install:
121	$(call descend,runqslower,install)
122
123runqslower_clean:
124	$(call descend,runqslower,clean)
125
126.PHONY: all install clean bpftool bpftool_install bpftool_clean \
127	runqslower runqslower_install runqslower_clean
128