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