12a171788SDavid S. Miller# SPDX-License-Identifier: GPL-2.0 25a8997f2SJiri Bencinclude ../scripts/Makefile.include 35a8997f2SJiri Benc 4fde68c5bSJiri Bencprefix ?= /usr/local 5a92bb546SJakub Kicinski 6a92bb546SJakub KicinskiLEX = flex 7a92bb546SJakub KicinskiYACC = bison 871bb428fSJakub KicinskiMAKE = make 9fde68c5bSJiri BencINSTALL ?= install 10a92bb546SJakub Kicinski 11a92bb546SJakub KicinskiCFLAGS += -Wall -O2 12f143c11bSWill DeaconCFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi \ 13f143c11bSWill Deacon -I$(srctree)/tools/include 14a92bb546SJakub Kicinski 1555d554f5SShuah Khan# This will work when bpf is built in tools env. where srctree 1655d554f5SShuah Khan# isn't set and when invoked from selftests build, where srctree 1755d554f5SShuah Khan# is set to ".". building_out_of_srctree is undefined for in srctree 1855d554f5SShuah Khan# builds 19a89b2cbfSQuentin Monnetifeq ($(srctree),) 20a89b2cbfSQuentin Monnetupdate_srctree := 1 21a89b2cbfSQuentin Monnetendif 2255d554f5SShuah Khanifndef building_out_of_srctree 23a89b2cbfSQuentin Monnetupdate_srctree := 1 24a89b2cbfSQuentin Monnetendif 25a89b2cbfSQuentin Monnetifeq ($(update_srctree),1) 26fb982666SRoman Gushchinsrctree := $(patsubst %/,%,$(dir $(CURDIR))) 27fb982666SRoman Gushchinsrctree := $(patsubst %/,%,$(dir $(srctree))) 28fb982666SRoman Gushchinendif 29fb982666SRoman Gushchin 30a50b7f8cSJiri Bencifeq ($(V),1) 31a50b7f8cSJiri Benc Q = 32a50b7f8cSJiri Bencelse 33a50b7f8cSJiri Benc Q = @ 34a50b7f8cSJiri Bencendif 35a50b7f8cSJiri Benc 36fb982666SRoman GushchinFEATURE_USER = .bpf 3796ed0660SAndres FreundFEATURE_TESTS = libbfd disassembler-four-args disassembler-init-styled 38*bab211f6SAndres FreundFEATURE_DISPLAY = libbfd 39fb982666SRoman Gushchin 40fb982666SRoman Gushchincheck_feat := 1 411eb832acSToke Høiland-JørgensenNON_CHECK_FEAT_TARGETS := clean bpftool_clean runqslower_clean resolve_btfids_clean 42fb982666SRoman Gushchinifdef MAKECMDGOALS 43fb982666SRoman Gushchinifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),) 44fb982666SRoman Gushchin check_feat := 0 45fb982666SRoman Gushchinendif 46fb982666SRoman Gushchinendif 47fb982666SRoman Gushchin 48fb982666SRoman Gushchinifeq ($(check_feat),1) 49fb982666SRoman Gushchinifeq ($(FEATURES_DUMP),) 50fb982666SRoman Gushchininclude $(srctree)/tools/build/Makefile.feature 51fb982666SRoman Gushchinelse 52fb982666SRoman Gushchininclude $(FEATURES_DUMP) 53fb982666SRoman Gushchinendif 54fb982666SRoman Gushchinendif 55fb982666SRoman Gushchin 56fb982666SRoman Gushchinifeq ($(feature-disassembler-four-args), 1) 57fb982666SRoman GushchinCFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE 58fb982666SRoman Gushchinendif 5996ed0660SAndres Freundifeq ($(feature-disassembler-init-styled), 1) 6096ed0660SAndres FreundCFLAGS += -DDISASM_INIT_STYLED 6196ed0660SAndres Freundendif 62fb982666SRoman Gushchin 635a8997f2SJiri Benc$(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y 64a50b7f8cSJiri Benc $(QUIET_BISON)$(YACC) -o $@ -d $< 65a92bb546SJakub Kicinski 665a8997f2SJiri Benc$(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l 67a50b7f8cSJiri Benc $(QUIET_FLEX)$(LEX) -o $@ $< 68a92bb546SJakub Kicinski 695a8997f2SJiri Benc$(OUTPUT)%.o: $(srctree)/tools/bpf/%.c 70d70a6be1SIlya Leoshkevich $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $< 71a50b7f8cSJiri Benc 72a50b7f8cSJiri Benc$(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c 73d70a6be1SIlya Leoshkevich $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $< 74a50b7f8cSJiri Benc$(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c 75d70a6be1SIlya Leoshkevich $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $< 76a92bb546SJakub Kicinski 776c071008SJiri BencPROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm 786c071008SJiri Benc 799c01546dSAndrii Nakryikoall: $(PROGS) bpftool runqslower 80a92bb546SJakub Kicinski 815a8997f2SJiri Benc$(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm' 825a8997f2SJiri Benc$(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o 83a50b7f8cSJiri Benc $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl 84a92bb546SJakub Kicinski 855a8997f2SJiri Benc$(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o 86a50b7f8cSJiri Benc $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline 875a8997f2SJiri Benc 885a8997f2SJiri Benc$(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o 89a50b7f8cSJiri Benc $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ 90a50b7f8cSJiri Benc 91ef8ba83bSJiri Benc$(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c 929c299a32SJohn Fastabend$(OUTPUT)bpf_exp.yacc.o: $(OUTPUT)bpf_exp.yacc.c 939c299a32SJohn Fastabend$(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c 94a92bb546SJakub Kicinski 951eb832acSToke Høiland-Jørgensenclean: bpftool_clean runqslower_clean resolve_btfids_clean 96a50b7f8cSJiri Benc $(call QUIET_CLEAN, bpf-progs) 97fbdb620bSQuentin Monnet $(Q)$(RM) -r -- $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \ 985a8997f2SJiri Benc $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.* 99cc5b3403SJakub Kicinski $(call QUIET_CLEAN, core-gen) 100fbdb620bSQuentin Monnet $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpf 101fbdb620bSQuentin Monnet $(Q)$(RM) -r -- $(OUTPUT)feature 102a92bb546SJakub Kicinski 1031d719254SWei Liinstall: $(PROGS) bpftool_install 104a50b7f8cSJiri Benc $(call QUIET_INSTALL, bpf_jit_disasm) 105a50b7f8cSJiri Benc $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin 106a50b7f8cSJiri Benc $(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm 107a50b7f8cSJiri Benc $(call QUIET_INSTALL, bpf_dbg) 108a50b7f8cSJiri Benc $(Q)$(INSTALL) $(OUTPUT)bpf_dbg $(DESTDIR)$(prefix)/bin/bpf_dbg 109a50b7f8cSJiri Benc $(call QUIET_INSTALL, bpf_asm) 110a50b7f8cSJiri Benc $(Q)$(INSTALL) $(OUTPUT)bpf_asm $(DESTDIR)$(prefix)/bin/bpf_asm 11171bb428fSJakub Kicinski 11271bb428fSJakub Kicinskibpftool: 11358416c37SJiri Benc $(call descend,bpftool) 11471bb428fSJakub Kicinski 11571bb428fSJakub Kicinskibpftool_install: 11658416c37SJiri Benc $(call descend,bpftool,install) 11771bb428fSJakub Kicinski 11871bb428fSJakub Kicinskibpftool_clean: 11958416c37SJiri Benc $(call descend,bpftool,clean) 12071bb428fSJakub Kicinski 1219c01546dSAndrii Nakryikorunqslower: 1229c01546dSAndrii Nakryiko $(call descend,runqslower) 1239c01546dSAndrii Nakryiko 1249c01546dSAndrii Nakryikorunqslower_clean: 1259c01546dSAndrii Nakryiko $(call descend,runqslower,clean) 1269c01546dSAndrii Nakryiko 12733a57ce0SJiri Olsaresolve_btfids: 12833a57ce0SJiri Olsa $(call descend,resolve_btfids) 12933a57ce0SJiri Olsa 13033a57ce0SJiri Olsaresolve_btfids_clean: 13133a57ce0SJiri Olsa $(call descend,resolve_btfids,clean) 13233a57ce0SJiri Olsa 1339c01546dSAndrii Nakryiko.PHONY: all install clean bpftool bpftool_install bpftool_clean \ 1341d719254SWei Li runqslower runqslower_clean \ 13533a57ce0SJiri Olsa resolve_btfids resolve_btfids_clean 136