xref: /linux-6.15/tools/bpf/Makefile (revision 6c071008)
1# SPDX-License-Identifier: GPL-2.0
2include ../scripts/Makefile.include
3
4prefix ?= /usr/local
5
6CC = gcc
7LEX = flex
8YACC = bison
9MAKE = make
10INSTALL ?= install
11
12CFLAGS += -Wall -O2
13CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/include/uapi -I$(srctree)/include
14
15ifeq ($(srctree),)
16srctree := $(patsubst %/,%,$(dir $(CURDIR)))
17srctree := $(patsubst %/,%,$(dir $(srctree)))
18endif
19
20FEATURE_USER = .bpf
21FEATURE_TESTS = libbfd disassembler-four-args
22FEATURE_DISPLAY = libbfd disassembler-four-args
23
24check_feat := 1
25NON_CHECK_FEAT_TARGETS := clean bpftool_clean
26ifdef MAKECMDGOALS
27ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
28  check_feat := 0
29endif
30endif
31
32ifeq ($(check_feat),1)
33ifeq ($(FEATURES_DUMP),)
34include $(srctree)/tools/build/Makefile.feature
35else
36include $(FEATURES_DUMP)
37endif
38endif
39
40ifeq ($(feature-disassembler-four-args), 1)
41CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
42endif
43
44$(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y
45	$(YACC) -o $@ -d $<
46
47$(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l
48	$(LEX) -o $@ $<
49
50$(OUTPUT)%.o: $(srctree)/tools/bpf/%.c
51	$(COMPILE.c) -o $@ $<
52
53PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm
54
55all: $(PROGS) bpftool
56
57$(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm'
58$(OUTPUT)bpf_jit_disasm: LDLIBS = -lopcodes -lbfd -ldl
59$(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o
60
61$(OUTPUT)bpf_dbg: LDLIBS = -lreadline
62$(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o
63
64$(OUTPUT)bpf_asm: LDLIBS =
65$(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o
66$(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.yacc.c
67
68clean: bpftool_clean
69	rm -rf $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \
70	       $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.*
71
72install: $(PROGS) bpftool_install
73	$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin
74	$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm
75	$(INSTALL) $(OUTPUT)bpf_dbg $(DESTDIR)$(prefix)/bin/bpf_dbg
76	$(INSTALL) $(OUTPUT)bpf_asm $(DESTDIR)$(prefix)/bin/bpf_asm
77
78bpftool:
79	$(MAKE) -C bpftool
80
81bpftool_install:
82	$(MAKE) -C bpftool install
83
84bpftool_clean:
85	$(MAKE) -C bpftool clean
86
87.PHONY: bpftool FORCE
88