Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 2 | include ../scripts/Makefile.include |
| 3 | |
Jiri Benc | fde68c5 | 2018-03-08 23:00:37 +0100 | [diff] [blame] | 4 | prefix ?= /usr/local |
Daniel Borkmann | e306e2c | 2013-03-20 12:11:47 +0000 | [diff] [blame] | 5 | |
Daniel Borkmann | 3f35638 | 2013-12-11 23:43:44 +0100 | [diff] [blame] | 6 | LEX = flex |
| 7 | YACC = bison |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 8 | MAKE = make |
Jiri Benc | fde68c5 | 2018-03-08 23:00:37 +0100 | [diff] [blame] | 9 | INSTALL ?= install |
Daniel Borkmann | e306e2c | 2013-03-20 12:11:47 +0000 | [diff] [blame] | 10 | |
Kamal Mostafa | d7475de | 2015-11-11 14:24:27 -0800 | [diff] [blame] | 11 | CFLAGS += -Wall -O2 |
Will Deacon | f143c11 | 2019-11-21 12:41:40 +0000 | [diff] [blame] | 12 | CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi \ |
| 13 | -I$(srctree)/tools/include |
Kamal Mostafa | d7475de | 2015-11-11 14:24:27 -0800 | [diff] [blame] | 14 | |
Shuah Khan | 55d554f | 2019-09-26 19:13:44 -0600 | [diff] [blame] | 15 | # 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 Monnet | a89b2cb | 2019-11-19 10:56:26 +0000 | [diff] [blame] | 19 | ifeq ($(srctree),) |
| 20 | update_srctree := 1 |
| 21 | endif |
Shuah Khan | 55d554f | 2019-09-26 19:13:44 -0600 | [diff] [blame] | 22 | ifndef building_out_of_srctree |
Quentin Monnet | a89b2cb | 2019-11-19 10:56:26 +0000 | [diff] [blame] | 23 | update_srctree := 1 |
| 24 | endif |
| 25 | ifeq ($(update_srctree),1) |
Roman Gushchin | fb98266 | 2017-12-27 19:16:29 +0000 | [diff] [blame] | 26 | srctree := $(patsubst %/,%,$(dir $(CURDIR))) |
| 27 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 28 | endif |
| 29 | |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 30 | ifeq ($(V),1) |
| 31 | Q = |
| 32 | else |
| 33 | Q = @ |
| 34 | endif |
| 35 | |
Roman Gushchin | fb98266 | 2017-12-27 19:16:29 +0000 | [diff] [blame] | 36 | FEATURE_USER = .bpf |
| 37 | FEATURE_TESTS = libbfd disassembler-four-args |
| 38 | FEATURE_DISPLAY = libbfd disassembler-four-args |
| 39 | |
| 40 | check_feat := 1 |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 41 | NON_CHECK_FEAT_TARGETS := clean bpftool_clean runqslower_clean |
Roman Gushchin | fb98266 | 2017-12-27 19:16:29 +0000 | [diff] [blame] | 42 | ifdef MAKECMDGOALS |
| 43 | ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),) |
| 44 | check_feat := 0 |
| 45 | endif |
| 46 | endif |
| 47 | |
| 48 | ifeq ($(check_feat),1) |
| 49 | ifeq ($(FEATURES_DUMP),) |
| 50 | include $(srctree)/tools/build/Makefile.feature |
| 51 | else |
| 52 | include $(FEATURES_DUMP) |
| 53 | endif |
| 54 | endif |
| 55 | |
| 56 | ifeq ($(feature-disassembler-four-args), 1) |
| 57 | CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE |
| 58 | endif |
| 59 | |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 60 | $(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 61 | $(QUIET_BISON)$(YACC) -o $@ -d $< |
Daniel Borkmann | 3f35638 | 2013-12-11 23:43:44 +0100 | [diff] [blame] | 62 | |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 63 | $(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 64 | $(QUIET_FLEX)$(LEX) -o $@ $< |
Daniel Borkmann | 3f35638 | 2013-12-11 23:43:44 +0100 | [diff] [blame] | 65 | |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 66 | $(OUTPUT)%.o: $(srctree)/tools/bpf/%.c |
Ilya Leoshkevich | d70a6be | 2020-06-02 19:56:48 +0200 | [diff] [blame] | 67 | $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $< |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 68 | |
| 69 | $(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c |
Ilya Leoshkevich | d70a6be | 2020-06-02 19:56:48 +0200 | [diff] [blame] | 70 | $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $< |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 71 | $(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c |
Ilya Leoshkevich | d70a6be | 2020-06-02 19:56:48 +0200 | [diff] [blame] | 72 | $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $< |
Daniel Borkmann | e306e2c | 2013-03-20 12:11:47 +0000 | [diff] [blame] | 73 | |
Jiri Benc | 6c07100 | 2018-03-08 23:00:38 +0100 | [diff] [blame] | 74 | PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm |
| 75 | |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 76 | all: $(PROGS) bpftool runqslower |
Daniel Borkmann | e306e2c | 2013-03-20 12:11:47 +0000 | [diff] [blame] | 77 | |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 78 | $(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm' |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 79 | $(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 80 | $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl |
Daniel Borkmann | fd981e3 | 2013-12-11 23:43:43 +0100 | [diff] [blame] | 81 | |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 82 | $(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 83 | $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 84 | |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 85 | $(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 86 | $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ |
| 87 | |
Jiri Benc | ef8ba83b | 2018-03-08 23:00:41 +0100 | [diff] [blame] | 88 | $(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c |
John Fastabend | 9c299a3 | 2018-04-25 14:22:45 -0700 | [diff] [blame] | 89 | $(OUTPUT)bpf_exp.yacc.o: $(OUTPUT)bpf_exp.yacc.c |
| 90 | $(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c |
Daniel Borkmann | 3f35638 | 2013-12-11 23:43:44 +0100 | [diff] [blame] | 91 | |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 92 | clean: bpftool_clean runqslower_clean |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 93 | $(call QUIET_CLEAN, bpf-progs) |
Quentin Monnet | fbdb620 | 2019-08-30 12:00:39 +0100 | [diff] [blame] | 94 | $(Q)$(RM) -r -- $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \ |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 95 | $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.* |
Jakub Kicinski | cc5b340 | 2018-03-15 23:26:17 -0700 | [diff] [blame] | 96 | $(call QUIET_CLEAN, core-gen) |
Quentin Monnet | fbdb620 | 2019-08-30 12:00:39 +0100 | [diff] [blame] | 97 | $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpf |
| 98 | $(Q)$(RM) -r -- $(OUTPUT)feature |
Daniel Borkmann | e306e2c | 2013-03-20 12:11:47 +0000 | [diff] [blame] | 99 | |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 100 | install: $(PROGS) bpftool_install runqslower_install |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 101 | $(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 Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 108 | |
| 109 | bpftool: |
Jiri Benc | 58416c3 | 2018-03-08 23:00:39 +0100 | [diff] [blame] | 110 | $(call descend,bpftool) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 111 | |
| 112 | bpftool_install: |
Jiri Benc | 58416c3 | 2018-03-08 23:00:39 +0100 | [diff] [blame] | 113 | $(call descend,bpftool,install) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 114 | |
| 115 | bpftool_clean: |
Jiri Benc | 58416c3 | 2018-03-08 23:00:39 +0100 | [diff] [blame] | 116 | $(call descend,bpftool,clean) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 117 | |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 118 | runqslower: |
| 119 | $(call descend,runqslower) |
| 120 | |
| 121 | runqslower_install: |
| 122 | $(call descend,runqslower,install) |
| 123 | |
| 124 | runqslower_clean: |
| 125 | $(call descend,runqslower,clean) |
| 126 | |
Jiri Olsa | 33a57ce | 2020-07-11 23:53:22 +0200 | [diff] [blame] | 127 | resolve_btfids: |
| 128 | $(call descend,resolve_btfids) |
| 129 | |
| 130 | resolve_btfids_clean: |
| 131 | $(call descend,resolve_btfids,clean) |
| 132 | |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 133 | .PHONY: all install clean bpftool bpftool_install bpftool_clean \ |
Jiri Olsa | 33a57ce | 2020-07-11 23:53:22 +0200 | [diff] [blame] | 134 | runqslower runqslower_install runqslower_clean \ |
| 135 | resolve_btfids resolve_btfids_clean |