blob: 5d1995fd369c696d919240f66b9dad92ff4612ab [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
Shuah Khan55d554f2019-09-26 19:13:44 -060015# 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
19ifndef building_out_of_srctree
Roman Gushchinfb982662017-12-27 19:16:29 +000020srctree := $(patsubst %/,%,$(dir $(CURDIR)))
21srctree := $(patsubst %/,%,$(dir $(srctree)))
22endif
23
Jiri Benca50b7f82018-03-08 23:00:40 +010024ifeq ($(V),1)
25 Q =
26else
27 Q = @
28endif
29
Roman Gushchinfb982662017-12-27 19:16:29 +000030FEATURE_USER = .bpf
31FEATURE_TESTS = libbfd disassembler-four-args
32FEATURE_DISPLAY = libbfd disassembler-four-args
33
34check_feat := 1
35NON_CHECK_FEAT_TARGETS := clean bpftool_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
53
Jiri Benc5a8997f2018-03-08 23:00:36 +010054$(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y
Jiri Benca50b7f82018-03-08 23:00:40 +010055 $(QUIET_BISON)$(YACC) -o $@ -d $<
Daniel Borkmann3f356382013-12-11 23:43:44 +010056
Jiri Benc5a8997f2018-03-08 23:00:36 +010057$(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l
Jiri Benca50b7f82018-03-08 23:00:40 +010058 $(QUIET_FLEX)$(LEX) -o $@ $<
Daniel Borkmann3f356382013-12-11 23:43:44 +010059
Jiri Benc5a8997f2018-03-08 23:00:36 +010060$(OUTPUT)%.o: $(srctree)/tools/bpf/%.c
Jiri Benca50b7f82018-03-08 23:00:40 +010061 $(QUIET_CC)$(COMPILE.c) -o $@ $<
62
63$(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c
64 $(QUIET_CC)$(COMPILE.c) -o $@ $<
65$(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c
66 $(QUIET_CC)$(COMPILE.c) -o $@ $<
Daniel Borkmanne306e2c2013-03-20 12:11:47 +000067
Jiri Benc6c071002018-03-08 23:00:38 +010068PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm
69
70all: $(PROGS) bpftool
Daniel Borkmanne306e2c2013-03-20 12:11:47 +000071
Jiri Benc5a8997f2018-03-08 23:00:36 +010072$(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm'
Jiri Benc5a8997f2018-03-08 23:00:36 +010073$(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o
Jiri Benca50b7f82018-03-08 23:00:40 +010074 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl
Daniel Borkmannfd981e32013-12-11 23:43:43 +010075
Jiri Benc5a8997f2018-03-08 23:00:36 +010076$(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o
Jiri Benca50b7f82018-03-08 23:00:40 +010077 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline
Jiri Benc5a8997f2018-03-08 23:00:36 +010078
Jiri Benc5a8997f2018-03-08 23:00:36 +010079$(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o
Jiri Benca50b7f82018-03-08 23:00:40 +010080 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^
81
Jiri Bencef8ba83b2018-03-08 23:00:41 +010082$(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c
John Fastabend9c299a32018-04-25 14:22:45 -070083$(OUTPUT)bpf_exp.yacc.o: $(OUTPUT)bpf_exp.yacc.c
84$(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c
Daniel Borkmann3f356382013-12-11 23:43:44 +010085
Jakub Kicinski71bb4282017-10-04 20:10:04 -070086clean: bpftool_clean
Jiri Benca50b7f82018-03-08 23:00:40 +010087 $(call QUIET_CLEAN, bpf-progs)
Quentin Monnetfbdb6202019-08-30 12:00:39 +010088 $(Q)$(RM) -r -- $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \
Jiri Benc5a8997f2018-03-08 23:00:36 +010089 $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.*
Jakub Kicinskicc5b3402018-03-15 23:26:17 -070090 $(call QUIET_CLEAN, core-gen)
Quentin Monnetfbdb6202019-08-30 12:00:39 +010091 $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpf
92 $(Q)$(RM) -r -- $(OUTPUT)feature
Daniel Borkmanne306e2c2013-03-20 12:11:47 +000093
Jiri Benc6c071002018-03-08 23:00:38 +010094install: $(PROGS) bpftool_install
Jiri Benca50b7f82018-03-08 23:00:40 +010095 $(call QUIET_INSTALL, bpf_jit_disasm)
96 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin
97 $(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm
98 $(call QUIET_INSTALL, bpf_dbg)
99 $(Q)$(INSTALL) $(OUTPUT)bpf_dbg $(DESTDIR)$(prefix)/bin/bpf_dbg
100 $(call QUIET_INSTALL, bpf_asm)
101 $(Q)$(INSTALL) $(OUTPUT)bpf_asm $(DESTDIR)$(prefix)/bin/bpf_asm
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700102
103bpftool:
Jiri Benc58416c32018-03-08 23:00:39 +0100104 $(call descend,bpftool)
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700105
106bpftool_install:
Jiri Benc58416c32018-03-08 23:00:39 +0100107 $(call descend,bpftool,install)
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700108
109bpftool_clean:
Jiri Benc58416c32018-03-08 23:00:39 +0100110 $(call descend,bpftool,clean)
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700111
Jakub Kicinski8050ea42018-03-15 23:26:16 -0700112.PHONY: all install clean bpftool bpftool_install bpftool_clean