136 lines · plain
1# SPDX-License-Identifier: GPL-2.02include ../scripts/Makefile.include3 4prefix ?= /usr/local5 6LEX = flex7YACC = bison8MAKE = make9INSTALL ?= install10 11CFLAGS += -Wall -O212CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi \13 -I$(srctree)/tools/include14 15# This will work when bpf is built in tools env. where srctree16# isn't set and when invoked from selftests build, where srctree17# is set to ".". building_out_of_srctree is undefined for in srctree18# builds19ifeq ($(srctree),)20update_srctree := 121endif22ifndef building_out_of_srctree23update_srctree := 124endif25ifeq ($(update_srctree),1)26srctree := $(patsubst %/,%,$(dir $(CURDIR)))27srctree := $(patsubst %/,%,$(dir $(srctree)))28endif29 30ifeq ($(V),1)31 Q =32else33 Q = @34endif35 36FEATURE_USER = .bpf37FEATURE_TESTS = libbfd disassembler-four-args disassembler-init-styled38FEATURE_DISPLAY = libbfd39 40check_feat := 141NON_CHECK_FEAT_TARGETS := clean bpftool_clean runqslower_clean resolve_btfids_clean42ifdef MAKECMDGOALS43ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)44 check_feat := 045endif46endif47 48ifeq ($(check_feat),1)49ifeq ($(FEATURES_DUMP),)50include $(srctree)/tools/build/Makefile.feature51else52include $(FEATURES_DUMP)53endif54endif55 56ifeq ($(feature-disassembler-four-args), 1)57CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE58endif59ifeq ($(feature-disassembler-init-styled), 1)60CFLAGS += -DDISASM_INIT_STYLED61endif62 63$(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y64 $(QUIET_BISON)$(YACC) -o $@ -d $<65 66$(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l67 $(QUIET_FLEX)$(LEX) -o $@ $<68 69$(OUTPUT)%.o: $(srctree)/tools/bpf/%.c70 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<71 72$(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c73 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<74$(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c75 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<76 77PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm78 79all: $(PROGS) bpftool runqslower80 81$(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm'82$(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o83 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl84 85$(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o86 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline87 88$(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o89 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^90 91$(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c92$(OUTPUT)bpf_exp.yacc.o: $(OUTPUT)bpf_exp.yacc.c93$(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c94 95clean: bpftool_clean runqslower_clean resolve_btfids_clean96 $(call QUIET_CLEAN, bpf-progs)97 $(Q)$(RM) -r -- $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \98 $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.*99 $(call QUIET_CLEAN, core-gen)100 $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpf101 $(Q)$(RM) -r -- $(OUTPUT)feature102 103install: $(PROGS) bpftool_install104 $(call QUIET_INSTALL, bpf_jit_disasm)105 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin106 $(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm107 $(call QUIET_INSTALL, bpf_dbg)108 $(Q)$(INSTALL) $(OUTPUT)bpf_dbg $(DESTDIR)$(prefix)/bin/bpf_dbg109 $(call QUIET_INSTALL, bpf_asm)110 $(Q)$(INSTALL) $(OUTPUT)bpf_asm $(DESTDIR)$(prefix)/bin/bpf_asm111 112bpftool:113 $(call descend,bpftool)114 115bpftool_install:116 $(call descend,bpftool,install)117 118bpftool_clean:119 $(call descend,bpftool,clean)120 121runqslower:122 $(call descend,runqslower)123 124runqslower_clean:125 $(call descend,runqslower,clean)126 127resolve_btfids:128 $(call descend,resolve_btfids)129 130resolve_btfids_clean:131 $(call descend,resolve_btfids,clean)132 133.PHONY: all install clean bpftool bpftool_install bpftool_clean \134 runqslower runqslower_clean \135 resolve_btfids resolve_btfids_clean136