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 | |
| 6 | CC = gcc |
Daniel Borkmann | 3f35638 | 2013-12-11 23:43:44 +0100 | [diff] [blame] | 7 | LEX = flex |
| 8 | YACC = bison |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 9 | MAKE = make |
Jiri Benc | fde68c5 | 2018-03-08 23:00:37 +0100 | [diff] [blame] | 10 | INSTALL ?= install |
Daniel Borkmann | e306e2c | 2013-03-20 12:11:47 +0000 | [diff] [blame] | 11 | |
Kamal Mostafa | d7475de | 2015-11-11 14:24:27 -0800 | [diff] [blame] | 12 | CFLAGS += -Wall -O2 |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 13 | CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/include/uapi -I$(srctree)/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 |
| 19 | ifndef building_out_of_srctree |
Roman Gushchin | fb98266 | 2017-12-27 19:16:29 +0000 | [diff] [blame] | 20 | srctree := $(patsubst %/,%,$(dir $(CURDIR))) |
| 21 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 22 | endif |
| 23 | |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 24 | ifeq ($(V),1) |
| 25 | Q = |
| 26 | else |
| 27 | Q = @ |
| 28 | endif |
| 29 | |
Roman Gushchin | fb98266 | 2017-12-27 19:16:29 +0000 | [diff] [blame] | 30 | FEATURE_USER = .bpf |
| 31 | FEATURE_TESTS = libbfd disassembler-four-args |
| 32 | FEATURE_DISPLAY = libbfd disassembler-four-args |
| 33 | |
| 34 | check_feat := 1 |
| 35 | NON_CHECK_FEAT_TARGETS := clean bpftool_clean |
| 36 | ifdef MAKECMDGOALS |
| 37 | ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),) |
| 38 | check_feat := 0 |
| 39 | endif |
| 40 | endif |
| 41 | |
| 42 | ifeq ($(check_feat),1) |
| 43 | ifeq ($(FEATURES_DUMP),) |
| 44 | include $(srctree)/tools/build/Makefile.feature |
| 45 | else |
| 46 | include $(FEATURES_DUMP) |
| 47 | endif |
| 48 | endif |
| 49 | |
| 50 | ifeq ($(feature-disassembler-four-args), 1) |
| 51 | CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE |
| 52 | endif |
| 53 | |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 54 | $(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 55 | $(QUIET_BISON)$(YACC) -o $@ -d $< |
Daniel Borkmann | 3f35638 | 2013-12-11 23:43:44 +0100 | [diff] [blame] | 56 | |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 57 | $(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 58 | $(QUIET_FLEX)$(LEX) -o $@ $< |
Daniel Borkmann | 3f35638 | 2013-12-11 23:43:44 +0100 | [diff] [blame] | 59 | |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 60 | $(OUTPUT)%.o: $(srctree)/tools/bpf/%.c |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 61 | $(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 Borkmann | e306e2c | 2013-03-20 12:11:47 +0000 | [diff] [blame] | 67 | |
Jiri Benc | 6c07100 | 2018-03-08 23:00:38 +0100 | [diff] [blame] | 68 | PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm |
| 69 | |
| 70 | all: $(PROGS) bpftool |
Daniel Borkmann | e306e2c | 2013-03-20 12:11:47 +0000 | [diff] [blame] | 71 | |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 72 | $(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm' |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 73 | $(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 74 | $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl |
Daniel Borkmann | fd981e3 | 2013-12-11 23:43:43 +0100 | [diff] [blame] | 75 | |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 76 | $(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 77 | $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 78 | |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 79 | $(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] | 80 | $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ |
| 81 | |
Jiri Benc | ef8ba83b | 2018-03-08 23:00:41 +0100 | [diff] [blame] | 82 | $(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c |
John Fastabend | 9c299a3 | 2018-04-25 14:22:45 -0700 | [diff] [blame] | 83 | $(OUTPUT)bpf_exp.yacc.o: $(OUTPUT)bpf_exp.yacc.c |
| 84 | $(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c |
Daniel Borkmann | 3f35638 | 2013-12-11 23:43:44 +0100 | [diff] [blame] | 85 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 86 | clean: bpftool_clean |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 87 | $(call QUIET_CLEAN, bpf-progs) |
Quentin Monnet | fbdb620 | 2019-08-30 12:00:39 +0100 | [diff] [blame] | 88 | $(Q)$(RM) -r -- $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \ |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 89 | $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.* |
Jakub Kicinski | cc5b340 | 2018-03-15 23:26:17 -0700 | [diff] [blame] | 90 | $(call QUIET_CLEAN, core-gen) |
Quentin Monnet | fbdb620 | 2019-08-30 12:00:39 +0100 | [diff] [blame] | 91 | $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpf |
| 92 | $(Q)$(RM) -r -- $(OUTPUT)feature |
Daniel Borkmann | e306e2c | 2013-03-20 12:11:47 +0000 | [diff] [blame] | 93 | |
Jiri Benc | 6c07100 | 2018-03-08 23:00:38 +0100 | [diff] [blame] | 94 | install: $(PROGS) bpftool_install |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 95 | $(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 Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 102 | |
| 103 | bpftool: |
Jiri Benc | 58416c3 | 2018-03-08 23:00:39 +0100 | [diff] [blame] | 104 | $(call descend,bpftool) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 105 | |
| 106 | bpftool_install: |
Jiri Benc | 58416c3 | 2018-03-08 23:00:39 +0100 | [diff] [blame] | 107 | $(call descend,bpftool,install) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 108 | |
| 109 | bpftool_clean: |
Jiri Benc | 58416c3 | 2018-03-08 23:00:39 +0100 | [diff] [blame] | 110 | $(call descend,bpftool,clean) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 111 | |
Jakub Kicinski | 8050ea4 | 2018-03-15 23:26:16 -0700 | [diff] [blame] | 112 | .PHONY: all install clean bpftool bpftool_install bpftool_clean |