blob: 0a6d09a3e91ff5e923081ff04f3d1f4e6b84567e [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
Daniel Borkmann3f356382013-12-11 23:43:44 +01006LEX = flex
7YACC = bison
Jakub Kicinski71bb4282017-10-04 20:10:04 -07008MAKE = make
Jiri Bencfde68c52018-03-08 23:00:37 +01009INSTALL ?= install
Daniel Borkmanne306e2c2013-03-20 12:11:47 +000010
Kamal Mostafad7475de2015-11-11 14:24:27 -080011CFLAGS += -Wall -O2
Will Deaconf143c112019-11-21 12:41:40 +000012CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi \
13 -I$(srctree)/tools/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
Quentin Monneta89b2cb2019-11-19 10:56:26 +000019ifeq ($(srctree),)
20update_srctree := 1
21endif
Shuah Khan55d554f2019-09-26 19:13:44 -060022ifndef building_out_of_srctree
Quentin Monneta89b2cb2019-11-19 10:56:26 +000023update_srctree := 1
24endif
25ifeq ($(update_srctree),1)
Roman Gushchinfb982662017-12-27 19:16:29 +000026srctree := $(patsubst %/,%,$(dir $(CURDIR)))
27srctree := $(patsubst %/,%,$(dir $(srctree)))
28endif
29
Jiri Benca50b7f82018-03-08 23:00:40 +010030ifeq ($(V),1)
31 Q =
32else
33 Q = @
34endif
35
Roman Gushchinfb982662017-12-27 19:16:29 +000036FEATURE_USER = .bpf
37FEATURE_TESTS = libbfd disassembler-four-args
38FEATURE_DISPLAY = libbfd disassembler-four-args
39
40check_feat := 1
Andrii Nakryiko9c015462020-01-12 23:31:42 -080041NON_CHECK_FEAT_TARGETS := clean bpftool_clean runqslower_clean
Roman Gushchinfb982662017-12-27 19:16:29 +000042ifdef MAKECMDGOALS
43ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
44 check_feat := 0
45endif
46endif
47
48ifeq ($(check_feat),1)
49ifeq ($(FEATURES_DUMP),)
50include $(srctree)/tools/build/Makefile.feature
51else
52include $(FEATURES_DUMP)
53endif
54endif
55
56ifeq ($(feature-disassembler-four-args), 1)
57CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
58endif
59
Jiri Benc5a8997f2018-03-08 23:00:36 +010060$(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y
Jiri Benca50b7f82018-03-08 23:00:40 +010061 $(QUIET_BISON)$(YACC) -o $@ -d $<
Daniel Borkmann3f356382013-12-11 23:43:44 +010062
Jiri Benc5a8997f2018-03-08 23:00:36 +010063$(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l
Jiri Benca50b7f82018-03-08 23:00:40 +010064 $(QUIET_FLEX)$(LEX) -o $@ $<
Daniel Borkmann3f356382013-12-11 23:43:44 +010065
Jiri Benc5a8997f2018-03-08 23:00:36 +010066$(OUTPUT)%.o: $(srctree)/tools/bpf/%.c
Ilya Leoshkevichd70a6be2020-06-02 19:56:48 +020067 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
Jiri Benca50b7f82018-03-08 23:00:40 +010068
69$(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c
Ilya Leoshkevichd70a6be2020-06-02 19:56:48 +020070 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
Jiri Benca50b7f82018-03-08 23:00:40 +010071$(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c
Ilya Leoshkevichd70a6be2020-06-02 19:56:48 +020072 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
Daniel Borkmanne306e2c2013-03-20 12:11:47 +000073
Jiri Benc6c071002018-03-08 23:00:38 +010074PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm
75
Andrii Nakryiko9c015462020-01-12 23:31:42 -080076all: $(PROGS) bpftool runqslower
Daniel Borkmanne306e2c2013-03-20 12:11:47 +000077
Jiri Benc5a8997f2018-03-08 23:00:36 +010078$(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm'
Jiri Benc5a8997f2018-03-08 23:00:36 +010079$(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o
Jiri Benca50b7f82018-03-08 23:00:40 +010080 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl
Daniel Borkmannfd981e32013-12-11 23:43:43 +010081
Jiri Benc5a8997f2018-03-08 23:00:36 +010082$(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o
Jiri Benca50b7f82018-03-08 23:00:40 +010083 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline
Jiri Benc5a8997f2018-03-08 23:00:36 +010084
Jiri Benc5a8997f2018-03-08 23:00:36 +010085$(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o
Jiri Benca50b7f82018-03-08 23:00:40 +010086 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^
87
Jiri Bencef8ba83b2018-03-08 23:00:41 +010088$(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c
John Fastabend9c299a32018-04-25 14:22:45 -070089$(OUTPUT)bpf_exp.yacc.o: $(OUTPUT)bpf_exp.yacc.c
90$(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c
Daniel Borkmann3f356382013-12-11 23:43:44 +010091
Andrii Nakryiko9c015462020-01-12 23:31:42 -080092clean: bpftool_clean runqslower_clean
Jiri Benca50b7f82018-03-08 23:00:40 +010093 $(call QUIET_CLEAN, bpf-progs)
Quentin Monnetfbdb6202019-08-30 12:00:39 +010094 $(Q)$(RM) -r -- $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \
Jiri Benc5a8997f2018-03-08 23:00:36 +010095 $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.*
Jakub Kicinskicc5b3402018-03-15 23:26:17 -070096 $(call QUIET_CLEAN, core-gen)
Quentin Monnetfbdb6202019-08-30 12:00:39 +010097 $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpf
98 $(Q)$(RM) -r -- $(OUTPUT)feature
Daniel Borkmanne306e2c2013-03-20 12:11:47 +000099
Andrii Nakryiko9c015462020-01-12 23:31:42 -0800100install: $(PROGS) bpftool_install runqslower_install
Jiri Benca50b7f82018-03-08 23:00:40 +0100101 $(call QUIET_INSTALL, bpf_jit_disasm)
102 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin
103 $(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm
104 $(call QUIET_INSTALL, bpf_dbg)
105 $(Q)$(INSTALL) $(OUTPUT)bpf_dbg $(DESTDIR)$(prefix)/bin/bpf_dbg
106 $(call QUIET_INSTALL, bpf_asm)
107 $(Q)$(INSTALL) $(OUTPUT)bpf_asm $(DESTDIR)$(prefix)/bin/bpf_asm
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700108
109bpftool:
Jiri Benc58416c32018-03-08 23:00:39 +0100110 $(call descend,bpftool)
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700111
112bpftool_install:
Jiri Benc58416c32018-03-08 23:00:39 +0100113 $(call descend,bpftool,install)
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700114
115bpftool_clean:
Jiri Benc58416c32018-03-08 23:00:39 +0100116 $(call descend,bpftool,clean)
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700117
Andrii Nakryiko9c015462020-01-12 23:31:42 -0800118runqslower:
119 $(call descend,runqslower)
120
121runqslower_install:
122 $(call descend,runqslower,install)
123
124runqslower_clean:
125 $(call descend,runqslower,clean)
126
Jiri Olsa33a57ce2020-07-11 23:53:22 +0200127resolve_btfids:
128 $(call descend,resolve_btfids)
129
130resolve_btfids_clean:
131 $(call descend,resolve_btfids,clean)
132
Andrii Nakryiko9c015462020-01-12 23:31:42 -0800133.PHONY: all install clean bpftool bpftool_install bpftool_clean \
Jiri Olsa33a57ce2020-07-11 23:53:22 +0200134 runqslower runqslower_install runqslower_clean \
135 resolve_btfids resolve_btfids_clean