1# SPDX-License-Identifier: GPL-2.0-only 2include ../../scripts/Makefile.include 3include ../../scripts/Makefile.arch 4 5srctree := $(abspath $(CURDIR)/../../../) 6 7ifeq ($(V),1) 8 Q = 9 msg = 10else 11 Q = @ 12 ifeq ($(silent),1) 13 msg = 14 else 15 msg = @printf ' %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))"; 16 endif 17 MAKEFLAGS=--no-print-directory 18endif 19 20# always use the host compiler 21AR = $(HOSTAR) 22CC = $(HOSTCC) 23LD = $(HOSTLD) 24ARCH = $(HOSTARCH) 25RM ?= rm 26 27OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/ 28 29LIBBPF_SRC := $(srctree)/tools/lib/bpf/ 30SUBCMD_SRC := $(srctree)/tools/lib/subcmd/ 31 32BPFOBJ := $(OUTPUT)/libbpf/libbpf.a 33SUBCMDOBJ := $(OUTPUT)/libsubcmd/libsubcmd.a 34 35BINARY := $(OUTPUT)/resolve_btfids 36BINARY_IN := $(BINARY)-in.o 37 38all: $(BINARY) 39 40$(OUTPUT) $(OUTPUT)/libbpf $(OUTPUT)/libsubcmd: 41 $(call msg,MKDIR,,$@) 42 $(Q)mkdir -p $(@) 43 44$(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd 45 $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@) 46 47$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)/libbpf 48 $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@) 49 50CFLAGS := -g \ 51 -I$(srctree)/tools/include \ 52 -I$(srctree)/tools/include/uapi \ 53 -I$(LIBBPF_SRC) \ 54 -I$(SUBCMD_SRC) 55 56LIBS = -lelf -lz 57 58export srctree OUTPUT CFLAGS Q 59include $(srctree)/tools/build/Makefile.include 60 61$(BINARY_IN): fixdep FORCE | $(OUTPUT) 62 $(Q)$(MAKE) $(build)=resolve_btfids 63 64$(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN) 65 $(call msg,LINK,$@) 66 $(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS) 67 68clean_objects := $(wildcard $(OUTPUT)/*.o \ 69 $(OUTPUT)/.*.o.cmd \ 70 $(OUTPUT)/.*.o.d \ 71 $(OUTPUT)/libbpf \ 72 $(OUTPUT)/libsubcmd \ 73 $(OUTPUT)/resolve_btfids) 74 75ifneq ($(clean_objects),) 76clean: fixdep-clean 77 $(call msg,CLEAN,$(BINARY)) 78 $(Q)$(RM) -rf $(clean_objects) 79else 80clean: 81endif 82 83tags: 84 $(call msg,GEN,,tags) 85 $(Q)ctags -R . $(LIBBPF_SRC) $(SUBCMD_SRC) 86 87FORCE: 88 89.PHONY: all FORCE clean tags 90