12a171788SDavid S. Miller# SPDX-License-Identifier: GPL-2.0 25a8997f2SJiri Bencinclude ../scripts/Makefile.include 35a8997f2SJiri Benc 4fde68c5bSJiri Bencprefix ?= /usr/local 5a92bb546SJakub Kicinski 6a92bb546SJakub KicinskiCC = gcc 7a92bb546SJakub KicinskiLEX = flex 8a92bb546SJakub KicinskiYACC = bison 971bb428fSJakub KicinskiMAKE = make 10fde68c5bSJiri BencINSTALL ?= install 11a92bb546SJakub Kicinski 12a92bb546SJakub KicinskiCFLAGS += -Wall -O2 135a8997f2SJiri BencCFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/include/uapi -I$(srctree)/include 14a92bb546SJakub Kicinski 15fb982666SRoman Gushchinifeq ($(srctree),) 16fb982666SRoman Gushchinsrctree := $(patsubst %/,%,$(dir $(CURDIR))) 17fb982666SRoman Gushchinsrctree := $(patsubst %/,%,$(dir $(srctree))) 18fb982666SRoman Gushchinendif 19fb982666SRoman Gushchin 20a50b7f8cSJiri Bencifeq ($(V),1) 21a50b7f8cSJiri Benc Q = 22a50b7f8cSJiri Bencelse 23a50b7f8cSJiri Benc Q = @ 24a50b7f8cSJiri Bencendif 25a50b7f8cSJiri Benc 26fb982666SRoman GushchinFEATURE_USER = .bpf 27fb982666SRoman GushchinFEATURE_TESTS = libbfd disassembler-four-args 28fb982666SRoman GushchinFEATURE_DISPLAY = libbfd disassembler-four-args 29fb982666SRoman Gushchin 30fb982666SRoman Gushchincheck_feat := 1 31fb982666SRoman GushchinNON_CHECK_FEAT_TARGETS := clean bpftool_clean 32fb982666SRoman Gushchinifdef MAKECMDGOALS 33fb982666SRoman Gushchinifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),) 34fb982666SRoman Gushchin check_feat := 0 35fb982666SRoman Gushchinendif 36fb982666SRoman Gushchinendif 37fb982666SRoman Gushchin 38fb982666SRoman Gushchinifeq ($(check_feat),1) 39fb982666SRoman Gushchinifeq ($(FEATURES_DUMP),) 40fb982666SRoman Gushchininclude $(srctree)/tools/build/Makefile.feature 41fb982666SRoman Gushchinelse 42fb982666SRoman Gushchininclude $(FEATURES_DUMP) 43fb982666SRoman Gushchinendif 44fb982666SRoman Gushchinendif 45fb982666SRoman Gushchin 46fb982666SRoman Gushchinifeq ($(feature-disassembler-four-args), 1) 47fb982666SRoman GushchinCFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE 48fb982666SRoman Gushchinendif 49fb982666SRoman Gushchin 505a8997f2SJiri Benc$(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y 51a50b7f8cSJiri Benc $(QUIET_BISON)$(YACC) -o $@ -d $< 52a92bb546SJakub Kicinski 535a8997f2SJiri Benc$(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l 54a50b7f8cSJiri Benc $(QUIET_FLEX)$(LEX) -o $@ $< 55a92bb546SJakub Kicinski 565a8997f2SJiri Benc$(OUTPUT)%.o: $(srctree)/tools/bpf/%.c 57a50b7f8cSJiri Benc $(QUIET_CC)$(COMPILE.c) -o $@ $< 58a50b7f8cSJiri Benc 59a50b7f8cSJiri Benc$(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c 60a50b7f8cSJiri Benc $(QUIET_CC)$(COMPILE.c) -o $@ $< 61a50b7f8cSJiri Benc$(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c 62a50b7f8cSJiri Benc $(QUIET_CC)$(COMPILE.c) -o $@ $< 63a92bb546SJakub Kicinski 646c071008SJiri BencPROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm 656c071008SJiri Benc 666c071008SJiri Bencall: $(PROGS) bpftool 67a92bb546SJakub Kicinski 685a8997f2SJiri Benc$(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm' 695a8997f2SJiri Benc$(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o 70a50b7f8cSJiri Benc $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl 71a92bb546SJakub Kicinski 725a8997f2SJiri Benc$(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o 73a50b7f8cSJiri Benc $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline 745a8997f2SJiri Benc 755a8997f2SJiri Benc$(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o 76a50b7f8cSJiri Benc $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ 77a50b7f8cSJiri Benc 78*ef8ba83bSJiri Benc$(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c 79a92bb546SJakub Kicinski 8071bb428fSJakub Kicinskiclean: bpftool_clean 81a50b7f8cSJiri Benc $(call QUIET_CLEAN, bpf-progs) 82a50b7f8cSJiri Benc $(Q)rm -rf $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \ 835a8997f2SJiri Benc $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.* 84a92bb546SJakub Kicinski 856c071008SJiri Bencinstall: $(PROGS) bpftool_install 86a50b7f8cSJiri Benc $(call QUIET_INSTALL, bpf_jit_disasm) 87a50b7f8cSJiri Benc $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin 88a50b7f8cSJiri Benc $(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm 89a50b7f8cSJiri Benc $(call QUIET_INSTALL, bpf_dbg) 90a50b7f8cSJiri Benc $(Q)$(INSTALL) $(OUTPUT)bpf_dbg $(DESTDIR)$(prefix)/bin/bpf_dbg 91a50b7f8cSJiri Benc $(call QUIET_INSTALL, bpf_asm) 92a50b7f8cSJiri Benc $(Q)$(INSTALL) $(OUTPUT)bpf_asm $(DESTDIR)$(prefix)/bin/bpf_asm 9371bb428fSJakub Kicinski 9471bb428fSJakub Kicinskibpftool: 9558416c37SJiri Benc $(call descend,bpftool) 9671bb428fSJakub Kicinski 9771bb428fSJakub Kicinskibpftool_install: 9858416c37SJiri Benc $(call descend,bpftool,install) 9971bb428fSJakub Kicinski 10071bb428fSJakub Kicinskibpftool_clean: 10158416c37SJiri Benc $(call descend,bpftool,clean) 10271bb428fSJakub Kicinski 10371bb428fSJakub Kicinski.PHONY: bpftool FORCE 104