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