blob: 1ea545965ee36c3a8dca16fd0e34f19aa4894e60 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Jiri Benc5a8997f2018-03-08 23:00:36 +01002include ../scripts/Makefile.include
3
Jiri Bencfde68c52018-03-08 23:00:37 +01004prefix ?= /usr/local
Daniel Borkmanne306e2c2013-03-20 12:11:47 +00005
6CC = gcc
Daniel Borkmann3f356382013-12-11 23:43:44 +01007LEX = flex
8YACC = bison
Jakub Kicinski71bb4282017-10-04 20:10:04 -07009MAKE = make
Jiri Bencfde68c52018-03-08 23:00:37 +010010INSTALL ?= install
Daniel Borkmanne306e2c2013-03-20 12:11:47 +000011
Kamal Mostafad7475de2015-11-11 14:24:27 -080012CFLAGS += -Wall -O2
Jiri Benc5a8997f2018-03-08 23:00:36 +010013CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/include/uapi -I$(srctree)/include
Kamal Mostafad7475de2015-11-11 14:24:27 -080014
Roman Gushchinfb982662017-12-27 19:16:29 +000015ifeq ($(srctree),)
16srctree := $(patsubst %/,%,$(dir $(CURDIR)))
17srctree := $(patsubst %/,%,$(dir $(srctree)))
18endif
19
Jiri Benca50b7f82018-03-08 23:00:40 +010020ifeq ($(V),1)
21 Q =
22else
23 Q = @
24endif
25
Roman Gushchinfb982662017-12-27 19:16:29 +000026FEATURE_USER = .bpf
27FEATURE_TESTS = libbfd disassembler-four-args
28FEATURE_DISPLAY = libbfd disassembler-four-args
29
30check_feat := 1
31NON_CHECK_FEAT_TARGETS := clean bpftool_clean
32ifdef MAKECMDGOALS
33ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
34 check_feat := 0
35endif
36endif
37
38ifeq ($(check_feat),1)
39ifeq ($(FEATURES_DUMP),)
40include $(srctree)/tools/build/Makefile.feature
41else
42include $(FEATURES_DUMP)
43endif
44endif
45
46ifeq ($(feature-disassembler-four-args), 1)
47CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
48endif
49
Jiri Benc5a8997f2018-03-08 23:00:36 +010050$(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y
Jiri Benca50b7f82018-03-08 23:00:40 +010051 $(QUIET_BISON)$(YACC) -o $@ -d $<
Daniel Borkmann3f356382013-12-11 23:43:44 +010052
Jiri Benc5a8997f2018-03-08 23:00:36 +010053$(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l
Jiri Benca50b7f82018-03-08 23:00:40 +010054 $(QUIET_FLEX)$(LEX) -o $@ $<
Daniel Borkmann3f356382013-12-11 23:43:44 +010055
Jiri Benc5a8997f2018-03-08 23:00:36 +010056$(OUTPUT)%.o: $(srctree)/tools/bpf/%.c
Jiri Benca50b7f82018-03-08 23:00:40 +010057 $(QUIET_CC)$(COMPILE.c) -o $@ $<
58
59$(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c
60 $(QUIET_CC)$(COMPILE.c) -o $@ $<
61$(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c
62 $(QUIET_CC)$(COMPILE.c) -o $@ $<
Daniel Borkmanne306e2c2013-03-20 12:11:47 +000063
Jiri Benc6c071002018-03-08 23:00:38 +010064PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm
65
66all: $(PROGS) bpftool
Daniel Borkmanne306e2c2013-03-20 12:11:47 +000067
Jiri Benc5a8997f2018-03-08 23:00:36 +010068$(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm'
Jiri Benc5a8997f2018-03-08 23:00:36 +010069$(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o
Jiri Benca50b7f82018-03-08 23:00:40 +010070 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl
Daniel Borkmannfd981e32013-12-11 23:43:43 +010071
Jiri Benc5a8997f2018-03-08 23:00:36 +010072$(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o
Jiri Benca50b7f82018-03-08 23:00:40 +010073 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline
Jiri Benc5a8997f2018-03-08 23:00:36 +010074
Jiri Benc5a8997f2018-03-08 23:00:36 +010075$(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o
Jiri Benca50b7f82018-03-08 23:00:40 +010076 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^
77
Jiri Bencef8ba83b2018-03-08 23:00:41 +010078$(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c
Daniel Borkmann3f356382013-12-11 23:43:44 +010079
Jakub Kicinski71bb4282017-10-04 20:10:04 -070080clean: bpftool_clean
Jiri Benca50b7f82018-03-08 23:00:40 +010081 $(call QUIET_CLEAN, bpf-progs)
82 $(Q)rm -rf $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \
Jiri Benc5a8997f2018-03-08 23:00:36 +010083 $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.*
Jakub Kicinskicc5b3402018-03-15 23:26:17 -070084 $(call QUIET_CLEAN, core-gen)
85 $(Q)rm -f $(OUTPUT)FEATURE-DUMP.bpf
Daniel Borkmanne306e2c2013-03-20 12:11:47 +000086
Jiri Benc6c071002018-03-08 23:00:38 +010087install: $(PROGS) bpftool_install
Jiri Benca50b7f82018-03-08 23:00:40 +010088 $(call QUIET_INSTALL, bpf_jit_disasm)
89 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin
90 $(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm
91 $(call QUIET_INSTALL, bpf_dbg)
92 $(Q)$(INSTALL) $(OUTPUT)bpf_dbg $(DESTDIR)$(prefix)/bin/bpf_dbg
93 $(call QUIET_INSTALL, bpf_asm)
94 $(Q)$(INSTALL) $(OUTPUT)bpf_asm $(DESTDIR)$(prefix)/bin/bpf_asm
Jakub Kicinski71bb4282017-10-04 20:10:04 -070095
96bpftool:
Jiri Benc58416c32018-03-08 23:00:39 +010097 $(call descend,bpftool)
Jakub Kicinski71bb4282017-10-04 20:10:04 -070098
99bpftool_install:
Jiri Benc58416c32018-03-08 23:00:39 +0100100 $(call descend,bpftool,install)
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700101
102bpftool_clean:
Jiri Benc58416c32018-03-08 23:00:39 +0100103 $(call descend,bpftool,clean)
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700104
Jakub Kicinski8050ea42018-03-15 23:26:16 -0700105.PHONY: all install clean bpftool bpftool_install bpftool_clean