1 # SPDX-License-Identifier: GPL-2.0-only 1 # SPDX-License-Identifier: GPL-2.0-only 2 include ../../scripts/Makefile.include 2 include ../../scripts/Makefile.include 3 include ../../scripts/Makefile.arch << 4 3 5 srctree := $(abspath $(CURDIR)/../../../) !! 4 ifeq ($(srctree),) >> 5 srctree := $(patsubst %/,%,$(dir $(CURDIR))) >> 6 srctree := $(patsubst %/,%,$(dir $(srctree))) >> 7 srctree := $(patsubst %/,%,$(dir $(srctree))) >> 8 endif 6 9 7 ifeq ($(V),1) 10 ifeq ($(V),1) 8 Q = 11 Q = 9 msg = 12 msg = 10 else 13 else 11 Q = @ 14 Q = @ 12 ifeq ($(silent),1) !! 15 msg = @printf ' %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))"; 13 msg = << 14 else << 15 msg = @printf ' %-8s %s%s\n' "$(1)" "$(no << 16 endif << 17 MAKEFLAGS=--no-print-directory 16 MAKEFLAGS=--no-print-directory 18 endif 17 endif 19 18 20 # Overrides for the prepare step libraries. !! 19 # always use the host compiler 21 HOST_OVERRIDES := AR="$(HOSTAR)" CC="$(HOSTCC) !! 20 ifneq ($(LLVM),) 22 CROSS_COMPILE="" EXTRA_CFLAG !! 21 HOSTAR ?= llvm-ar 23 !! 22 HOSTCC ?= clang 24 RM ?= rm !! 23 HOSTLD ?= ld.lld >> 24 else >> 25 HOSTAR ?= ar 25 HOSTCC ?= gcc 26 HOSTCC ?= gcc 26 HOSTLD ?= ld 27 HOSTLD ?= ld 27 HOSTAR ?= ar !! 28 endif 28 CROSS_COMPILE = !! 29 AR = $(HOSTAR) >> 30 CC = $(HOSTCC) >> 31 LD = $(HOSTLD) 29 32 30 OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/ 33 OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/ 31 34 32 LIBBPF_SRC := $(srctree)/tools/lib/bpf/ 35 LIBBPF_SRC := $(srctree)/tools/lib/bpf/ 33 SUBCMD_SRC := $(srctree)/tools/lib/subcmd/ 36 SUBCMD_SRC := $(srctree)/tools/lib/subcmd/ 34 37 35 BPFOBJ := $(OUTPUT)/libbpf/libbpf.a !! 38 BPFOBJ := $(OUTPUT)/libbpf.a 36 LIBBPF_OUT := $(abspath $(dir $(BPFOBJ)))/ !! 39 SUBCMDOBJ := $(OUTPUT)/libsubcmd.a 37 SUBCMDOBJ := $(OUTPUT)/libsubcmd/libsubcmd.a << 38 SUBCMD_OUT := $(abspath $(dir $(SUBCMDOBJ)))/ << 39 << 40 LIBBPF_DESTDIR := $(LIBBPF_OUT) << 41 LIBBPF_INCLUDE := $(LIBBPF_DESTDIR)include << 42 << 43 SUBCMD_DESTDIR := $(SUBCMD_OUT) << 44 SUBCMD_INCLUDE := $(SUBCMD_DESTDIR)include << 45 40 46 BINARY := $(OUTPUT)/resolve_btfids 41 BINARY := $(OUTPUT)/resolve_btfids 47 BINARY_IN := $(BINARY)-in.o 42 BINARY_IN := $(BINARY)-in.o 48 43 49 all: $(BINARY) 44 all: $(BINARY) 50 45 51 prepare: $(BPFOBJ) $(SUBCMDOBJ) !! 46 $(OUTPUT): 52 << 53 $(OUTPUT) $(OUTPUT)/libsubcmd $(LIBBPF_OUT): << 54 $(call msg,MKDIR,,$@) 47 $(call msg,MKDIR,,$@) 55 $(Q)mkdir -p $(@) !! 48 $(Q)mkdir -p $(OUTPUT) 56 49 57 $(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubc !! 50 $(SUBCMDOBJ): fixdep FORCE 58 $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$( !! 51 $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(OUTPUT) 59 DESTDIR=$(SUBCMD_DESTDIR) << 60 $(abspath $@) install_head << 61 << 62 $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(L << 63 $(Q)$(MAKE) $(submake_extras) -C $(LIB << 64 DESTDIR=$(LIBBPF_DESTDIR) << 65 $(abspath $@) install_head << 66 52 67 LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libe !! 53 $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT) 68 LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libe !! 54 $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@) 69 55 70 HOSTCFLAGS_resolve_btfids += -g \ !! 56 CFLAGS := -g \ 71 -I$(srctree)/tools/include \ 57 -I$(srctree)/tools/include \ 72 -I$(srctree)/tools/include/uapi \ 58 -I$(srctree)/tools/include/uapi \ 73 -I$(LIBBPF_INCLUDE) \ !! 59 -I$(LIBBPF_SRC) \ 74 -I$(SUBCMD_INCLUDE) \ !! 60 -I$(SUBCMD_SRC) 75 $(LIBELF_FLAGS) << 76 61 77 LIBS = $(LIBELF_LIBS) -lz !! 62 LIBS = -lelf -lz 78 63 79 export srctree OUTPUT HOSTCFLAGS_resolve_btfid !! 64 export srctree OUTPUT CFLAGS Q 80 include $(srctree)/tools/build/Makefile.includ 65 include $(srctree)/tools/build/Makefile.include 81 66 82 $(BINARY_IN): fixdep FORCE prepare | $(OUTPUT) !! 67 $(BINARY_IN): fixdep FORCE 83 $(Q)$(MAKE) $(build)=resolve_btfids 68 $(Q)$(MAKE) $(build)=resolve_btfids 84 69 85 $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN) 70 $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN) 86 $(call msg,LINK,$@) 71 $(call msg,LINK,$@) 87 $(Q)$(HOSTCC) $(BINARY_IN) $(KBUILD_HO !! 72 $(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS) 88 73 89 clean_objects := $(wildcard $(OUTPUT)/*.o !! 74 libsubcmd-clean: 90 $(OUTPUT)/.*.o.cmd !! 75 $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(OUTPUT) clean 91 $(OUTPUT)/.*.o.d << 92 $(LIBBPF_OUT) << 93 $(LIBBPF_DESTDIR) << 94 $(SUBCMD_OUT) << 95 $(SUBCMD_DESTDIR) << 96 $(OUTPUT)/resolve_ << 97 76 98 ifneq ($(clean_objects),) !! 77 libbpf-clean: 99 clean: fixdep-clean !! 78 $(Q)$(MAKE) -C $(LIBBPF_SRC) OUTPUT=$(OUTPUT) clean >> 79 >> 80 clean: libsubcmd-clean libbpf-clean fixdep-clean 100 $(call msg,CLEAN,$(BINARY)) 81 $(call msg,CLEAN,$(BINARY)) 101 $(Q)$(RM) -rf $(clean_objects) !! 82 $(Q)$(RM) -f $(BINARY); \ 102 else !! 83 $(RM) -rf $(if $(OUTPUT),$(OUTPUT),.)/feature; \ 103 clean: !! 84 find $(if $(OUTPUT),$(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM) 104 endif << 105 85 106 tags: 86 tags: 107 $(call msg,GEN,,tags) 87 $(call msg,GEN,,tags) 108 $(Q)ctags -R . $(LIBBPF_SRC) $(SUBCMD_ 88 $(Q)ctags -R . $(LIBBPF_SRC) $(SUBCMD_SRC) 109 89 110 FORCE: 90 FORCE: 111 91 112 .PHONY: all FORCE clean tags prepare !! 92 .PHONY: all FORCE clean tags
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.