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