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 29LIBBPF_OUT := $(abspath $(dir $(BPFOBJ)))/ 30SUBCMDOBJ := $(OUTPUT)/libsubcmd/libsubcmd.a 31 32BINARY := $(OUTPUT)/resolve_btfids 33BINARY_IN := $(BINARY)-in.o 34 35all: $(BINARY) 36 37$(OUTPUT) $(OUTPUT)/libbpf $(OUTPUT)/libsubcmd: 38 $(call msg,MKDIR,,$@) 39 $(Q)mkdir -p $(@) 40 41$(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd 42 $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@) 43 44$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)/libbpf 45 $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(LIBBPF_OUT) $(abspath $@) 46 47CFLAGS := -g \ 48 -I$(srctree)/tools/include \ 49 -I$(srctree)/tools/include/uapi \ 50 -I$(LIBBPF_OUT) \ 51 -I$(LIBBPF_SRC) \ 52 -I$(SUBCMD_SRC) 53 54LIBS = -lelf -lz 55 56export srctree OUTPUT CFLAGS Q 57include $(srctree)/tools/build/Makefile.include 58 59$(BINARY_IN): $(BPFOBJ) fixdep FORCE | $(OUTPUT) 60 $(Q)$(MAKE) $(build)=resolve_btfids 61 62$(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN) 63 $(call msg,LINK,$@) 64 $(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS) 65 66clean_objects := $(wildcard $(OUTPUT)/*.o \ 67 $(OUTPUT)/.*.o.cmd \ 68 $(OUTPUT)/.*.o.d \ 69 $(OUTPUT)/libbpf \ 70 $(OUTPUT)/libsubcmd \ 71 $(OUTPUT)/resolve_btfids) 72 73ifneq ($(clean_objects),) 74clean: fixdep-clean 75 $(call msg,CLEAN,$(BINARY)) 76 $(Q)$(RM) -rf $(clean_objects) 77else 78clean: 79endif 80 81tags: 82 $(call msg,GEN,,tags) 83 $(Q)ctags -R . $(LIBBPF_SRC) $(SUBCMD_SRC) 84 85FORCE: 86 87.PHONY: all FORCE clean tags 88