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