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 | |
Roman Gushchin | fb98266 | 2017-12-27 19:16:29 +0000 | [diff] [blame] | 15 | ifeq ($(srctree),) |
| 16 | srctree := $(patsubst %/,%,$(dir $(CURDIR))) |
| 17 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 18 | endif |
| 19 | |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 20 | ifeq ($(V),1) |
| 21 | Q = |
| 22 | else |
| 23 | Q = @ |
| 24 | endif |
| 25 | |
Roman Gushchin | fb98266 | 2017-12-27 19:16:29 +0000 | [diff] [blame] | 26 | FEATURE_USER = .bpf |
| 27 | FEATURE_TESTS = libbfd disassembler-four-args |
| 28 | FEATURE_DISPLAY = libbfd disassembler-four-args |
| 29 | |
| 30 | check_feat := 1 |
| 31 | NON_CHECK_FEAT_TARGETS := clean bpftool_clean |
| 32 | ifdef MAKECMDGOALS |
| 33 | ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),) |
| 34 | check_feat := 0 |
| 35 | endif |
| 36 | endif |
| 37 | |
| 38 | ifeq ($(check_feat),1) |
| 39 | ifeq ($(FEATURES_DUMP),) |
| 40 | include $(srctree)/tools/build/Makefile.feature |
| 41 | else |
| 42 | include $(FEATURES_DUMP) |
| 43 | endif |
| 44 | endif |
| 45 | |
| 46 | ifeq ($(feature-disassembler-four-args), 1) |
| 47 | CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE |
| 48 | endif |
| 49 | |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 50 | $(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 51 | $(QUIET_BISON)$(YACC) -o $@ -d $< |
Daniel Borkmann | 3f35638 | 2013-12-11 23:43:44 +0100 | [diff] [blame] | 52 | |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 53 | $(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 54 | $(QUIET_FLEX)$(LEX) -o $@ $< |
Daniel Borkmann | 3f35638 | 2013-12-11 23:43:44 +0100 | [diff] [blame] | 55 | |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 56 | $(OUTPUT)%.o: $(srctree)/tools/bpf/%.c |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 57 | $(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 Borkmann | e306e2c | 2013-03-20 12:11:47 +0000 | [diff] [blame] | 63 | |
Jiri Benc | 6c07100 | 2018-03-08 23:00:38 +0100 | [diff] [blame] | 64 | PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm |
| 65 | |
| 66 | all: $(PROGS) bpftool |
Daniel Borkmann | e306e2c | 2013-03-20 12:11:47 +0000 | [diff] [blame] | 67 | |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 68 | $(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm' |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 69 | $(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 70 | $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl |
Daniel Borkmann | fd981e3 | 2013-12-11 23:43:43 +0100 | [diff] [blame] | 71 | |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 72 | $(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 73 | $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 74 | |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 75 | $(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] | 76 | $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ |
| 77 | |
Jiri Benc | ef8ba83b | 2018-03-08 23:00:41 +0100 | [diff] [blame] | 78 | $(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c |
Daniel Borkmann | 3f35638 | 2013-12-11 23:43:44 +0100 | [diff] [blame] | 79 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 80 | clean: bpftool_clean |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 81 | $(call QUIET_CLEAN, bpf-progs) |
| 82 | $(Q)rm -rf $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \ |
Jiri Benc | 5a8997f | 2018-03-08 23:00:36 +0100 | [diff] [blame] | 83 | $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.* |
Jakub Kicinski | cc5b340 | 2018-03-15 23:26:17 -0700 | [diff] [blame] | 84 | $(call QUIET_CLEAN, core-gen) |
| 85 | $(Q)rm -f $(OUTPUT)FEATURE-DUMP.bpf |
Daniel Borkmann | e306e2c | 2013-03-20 12:11:47 +0000 | [diff] [blame] | 86 | |
Jiri Benc | 6c07100 | 2018-03-08 23:00:38 +0100 | [diff] [blame] | 87 | install: $(PROGS) bpftool_install |
Jiri Benc | a50b7f8 | 2018-03-08 23:00:40 +0100 | [diff] [blame] | 88 | $(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 Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 95 | |
| 96 | bpftool: |
Jiri Benc | 58416c3 | 2018-03-08 23:00:39 +0100 | [diff] [blame] | 97 | $(call descend,bpftool) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 98 | |
| 99 | bpftool_install: |
Jiri Benc | 58416c3 | 2018-03-08 23:00:39 +0100 | [diff] [blame] | 100 | $(call descend,bpftool,install) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 101 | |
| 102 | bpftool_clean: |
Jiri Benc | 58416c3 | 2018-03-08 23:00:39 +0100 | [diff] [blame] | 103 | $(call descend,bpftool,clean) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 104 | |
Jakub Kicinski | 8050ea4 | 2018-03-15 23:26:16 -0700 | [diff] [blame] | 105 | .PHONY: all install clean bpftool bpftool_install bpftool_clean |