1 # SPDX-License-Identifier: GPL-2.0 1 # SPDX-License-Identifier: GPL-2.0 2 include ../scripts/Makefile.include 2 include ../scripts/Makefile.include 3 3 4 prefix ?= /usr/local 4 prefix ?= /usr/local 5 5 6 LEX = flex 6 LEX = flex 7 YACC = bison 7 YACC = bison 8 MAKE = make 8 MAKE = make 9 INSTALL ?= install 9 INSTALL ?= install 10 10 11 CFLAGS += -Wall -O2 11 CFLAGS += -Wall -O2 12 CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/ 12 CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi \ 13 -I$(srctree)/tools/include 13 -I$(srctree)/tools/include 14 14 15 # This will work when bpf is built in tools en 15 # This will work when bpf is built in tools env. where srctree 16 # isn't set and when invoked from selftests bu 16 # isn't set and when invoked from selftests build, where srctree 17 # is set to ".". building_out_of_srctree is un 17 # is set to ".". building_out_of_srctree is undefined for in srctree 18 # builds 18 # builds 19 ifeq ($(srctree),) 19 ifeq ($(srctree),) 20 update_srctree := 1 20 update_srctree := 1 21 endif 21 endif 22 ifndef building_out_of_srctree 22 ifndef building_out_of_srctree 23 update_srctree := 1 23 update_srctree := 1 24 endif 24 endif 25 ifeq ($(update_srctree),1) 25 ifeq ($(update_srctree),1) 26 srctree := $(patsubst %/,%,$(dir $(CURDIR))) 26 srctree := $(patsubst %/,%,$(dir $(CURDIR))) 27 srctree := $(patsubst %/,%,$(dir $(srctree))) 27 srctree := $(patsubst %/,%,$(dir $(srctree))) 28 endif 28 endif 29 29 30 ifeq ($(V),1) 30 ifeq ($(V),1) 31 Q = 31 Q = 32 else 32 else 33 Q = @ 33 Q = @ 34 endif 34 endif 35 35 36 FEATURE_USER = .bpf 36 FEATURE_USER = .bpf 37 FEATURE_TESTS = libbfd disassembler-four-args !! 37 FEATURE_TESTS = libbfd disassembler-four-args 38 FEATURE_DISPLAY = libbfd !! 38 FEATURE_DISPLAY = libbfd disassembler-four-args 39 39 40 check_feat := 1 40 check_feat := 1 41 NON_CHECK_FEAT_TARGETS := clean bpftool_clean 41 NON_CHECK_FEAT_TARGETS := clean bpftool_clean runqslower_clean resolve_btfids_clean 42 ifdef MAKECMDGOALS 42 ifdef MAKECMDGOALS 43 ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$ 43 ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),) 44 check_feat := 0 44 check_feat := 0 45 endif 45 endif 46 endif 46 endif 47 47 48 ifeq ($(check_feat),1) 48 ifeq ($(check_feat),1) 49 ifeq ($(FEATURES_DUMP),) 49 ifeq ($(FEATURES_DUMP),) 50 include $(srctree)/tools/build/Makefile.featur 50 include $(srctree)/tools/build/Makefile.feature 51 else 51 else 52 include $(FEATURES_DUMP) 52 include $(FEATURES_DUMP) 53 endif 53 endif 54 endif 54 endif 55 55 56 ifeq ($(feature-disassembler-four-args), 1) 56 ifeq ($(feature-disassembler-four-args), 1) 57 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE 57 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE 58 endif << 59 ifeq ($(feature-disassembler-init-styled), 1) << 60 CFLAGS += -DDISASM_INIT_STYLED << 61 endif 58 endif 62 59 63 $(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y 60 $(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y 64 $(QUIET_BISON)$(YACC) -o $@ -d $< 61 $(QUIET_BISON)$(YACC) -o $@ -d $< 65 62 66 $(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l 63 $(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l 67 $(QUIET_FLEX)$(LEX) -o $@ $< 64 $(QUIET_FLEX)$(LEX) -o $@ $< 68 65 69 $(OUTPUT)%.o: $(srctree)/tools/bpf/%.c 66 $(OUTPUT)%.o: $(srctree)/tools/bpf/%.c 70 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $< 67 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $< 71 68 72 $(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c 69 $(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c 73 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $< 70 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $< 74 $(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c 71 $(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c 75 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $< 72 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $< 76 73 77 PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_d 74 PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm 78 75 79 all: $(PROGS) bpftool runqslower 76 all: $(PROGS) bpftool runqslower 80 77 81 $(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE=' 78 $(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm' 82 $(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disa 79 $(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o 83 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ 80 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl 84 81 85 $(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o 82 $(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o 86 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ 83 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline 87 84 88 $(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT) 85 $(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o 89 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ 86 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ 90 87 91 $(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc. 88 $(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c 92 $(OUTPUT)bpf_exp.yacc.o: $(OUTPUT)bpf_exp.yacc 89 $(OUTPUT)bpf_exp.yacc.o: $(OUTPUT)bpf_exp.yacc.c 93 $(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c 90 $(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c 94 91 95 clean: bpftool_clean runqslower_clean resolve_ 92 clean: bpftool_clean runqslower_clean resolve_btfids_clean 96 $(call QUIET_CLEAN, bpf-progs) 93 $(call QUIET_CLEAN, bpf-progs) 97 $(Q)$(RM) -r -- $(OUTPUT)*.o $(OUTPUT) 94 $(Q)$(RM) -r -- $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \ 98 $(OUTPUT)bpf_asm $(OUTPUT)bpf_e 95 $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.* 99 $(call QUIET_CLEAN, core-gen) 96 $(call QUIET_CLEAN, core-gen) 100 $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpf 97 $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpf 101 $(Q)$(RM) -r -- $(OUTPUT)feature 98 $(Q)$(RM) -r -- $(OUTPUT)feature 102 99 103 install: $(PROGS) bpftool_install 100 install: $(PROGS) bpftool_install 104 $(call QUIET_INSTALL, bpf_jit_disasm) 101 $(call QUIET_INSTALL, bpf_jit_disasm) 105 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$( 102 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin 106 $(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm 103 $(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm 107 $(call QUIET_INSTALL, bpf_dbg) 104 $(call QUIET_INSTALL, bpf_dbg) 108 $(Q)$(INSTALL) $(OUTPUT)bpf_dbg $(DEST 105 $(Q)$(INSTALL) $(OUTPUT)bpf_dbg $(DESTDIR)$(prefix)/bin/bpf_dbg 109 $(call QUIET_INSTALL, bpf_asm) 106 $(call QUIET_INSTALL, bpf_asm) 110 $(Q)$(INSTALL) $(OUTPUT)bpf_asm $(DEST 107 $(Q)$(INSTALL) $(OUTPUT)bpf_asm $(DESTDIR)$(prefix)/bin/bpf_asm 111 108 112 bpftool: 109 bpftool: 113 $(call descend,bpftool) 110 $(call descend,bpftool) 114 111 115 bpftool_install: 112 bpftool_install: 116 $(call descend,bpftool,install) 113 $(call descend,bpftool,install) 117 114 118 bpftool_clean: 115 bpftool_clean: 119 $(call descend,bpftool,clean) 116 $(call descend,bpftool,clean) 120 117 121 runqslower: 118 runqslower: 122 $(call descend,runqslower) 119 $(call descend,runqslower) 123 120 124 runqslower_clean: 121 runqslower_clean: 125 $(call descend,runqslower,clean) 122 $(call descend,runqslower,clean) 126 123 127 resolve_btfids: 124 resolve_btfids: 128 $(call descend,resolve_btfids) 125 $(call descend,resolve_btfids) 129 126 130 resolve_btfids_clean: 127 resolve_btfids_clean: 131 $(call descend,resolve_btfids,clean) 128 $(call descend,resolve_btfids,clean) 132 129 133 .PHONY: all install clean bpftool bpftool_inst 130 .PHONY: all install clean bpftool bpftool_install bpftool_clean \ 134 runqslower runqslower_clean \ 131 runqslower runqslower_clean \ 135 resolve_btfids resolve_btfids_clean 132 resolve_btfids resolve_btfids_clean
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.