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 21ifneq ($(LLVM),) 22HOSTAR ?= llvm-ar 23HOSTCC ?= clang 24HOSTLD ?= ld.lld 25else 26HOSTAR ?= ar 27HOSTCC ?= gcc 28HOSTLD ?= ld 29endif 30AR = $(HOSTAR) 31CC = $(HOSTCC) 32LD = $(HOSTLD) 33ARCH = $(HOSTARCH) 34 35OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/ 36 37LIBBPF_SRC := $(srctree)/tools/lib/bpf/ 38SUBCMD_SRC := $(srctree)/tools/lib/subcmd/ 39 40BPFOBJ := $(OUTPUT)/libbpf.a 41SUBCMDOBJ := $(OUTPUT)/libsubcmd.a 42 43BINARY := $(OUTPUT)/resolve_btfids 44BINARY_IN := $(BINARY)-in.o 45 46all: $(BINARY) 47 48$(OUTPUT): 49 $(call msg,MKDIR,,$@) 50 $(Q)mkdir -p $(OUTPUT) 51 52$(SUBCMDOBJ): fixdep FORCE 53 $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(OUTPUT) 54 55$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT) 56 $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@) 57 58CFLAGS := -g \ 59 -I$(srctree)/tools/include \ 60 -I$(srctree)/tools/include/uapi \ 61 -I$(LIBBPF_SRC) \ 62 -I$(SUBCMD_SRC) 63 64LIBS = -lelf -lz 65 66export srctree OUTPUT CFLAGS Q 67include $(srctree)/tools/build/Makefile.include 68 69$(BINARY_IN): fixdep FORCE 70 $(Q)$(MAKE) $(build)=resolve_btfids 71 72$(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN) 73 $(call msg,LINK,$@) 74 $(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS) 75 76libsubcmd-clean: 77 $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(OUTPUT) clean 78 79libbpf-clean: 80 $(Q)$(MAKE) -C $(LIBBPF_SRC) OUTPUT=$(OUTPUT) clean 81 82clean: libsubcmd-clean libbpf-clean fixdep-clean 83 $(call msg,CLEAN,$(BINARY)) 84 $(Q)$(RM) -f $(BINARY); \ 85 $(RM) -rf $(if $(OUTPUT),$(OUTPUT),.)/feature; \ 86 find $(if $(OUTPUT),$(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM) 87 88tags: 89 $(call msg,GEN,,tags) 90 $(Q)ctags -R . $(LIBBPF_SRC) $(SUBCMD_SRC) 91 92FORCE: 93 94.PHONY: all FORCE clean tags 95