18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ciinclude ../../scripts/Makefile.include
38c2ecf20Sopenharmony_ciinclude ../../scripts/Makefile.arch
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_cisrctree := $(abspath $(CURDIR)/../../../)
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ciifeq ($(V),1)
88c2ecf20Sopenharmony_ci  Q =
98c2ecf20Sopenharmony_ci  msg =
108c2ecf20Sopenharmony_cielse
118c2ecf20Sopenharmony_ci  Q = @
128c2ecf20Sopenharmony_ci  ifeq ($(silent),1)
138c2ecf20Sopenharmony_ci    msg =
148c2ecf20Sopenharmony_ci  else
158c2ecf20Sopenharmony_ci    msg = @printf '  %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))";
168c2ecf20Sopenharmony_ci  endif
178c2ecf20Sopenharmony_ci  MAKEFLAGS=--no-print-directory
188c2ecf20Sopenharmony_ciendif
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci# always use the host compiler
218c2ecf20Sopenharmony_ciAR       = $(HOSTAR)
228c2ecf20Sopenharmony_ciCC       = $(HOSTCC)
238c2ecf20Sopenharmony_ciLD       = $(HOSTLD)
248c2ecf20Sopenharmony_ciARCH     = $(HOSTARCH)
258c2ecf20Sopenharmony_ciRM      ?= rm
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciOUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciLIBBPF_SRC := $(srctree)/tools/lib/bpf/
308c2ecf20Sopenharmony_ciSUBCMD_SRC := $(srctree)/tools/lib/subcmd/
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ciBPFOBJ     := $(OUTPUT)/libbpf/libbpf.a
338c2ecf20Sopenharmony_ciSUBCMDOBJ  := $(OUTPUT)/libsubcmd/libsubcmd.a
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ciBINARY     := $(OUTPUT)/resolve_btfids
368c2ecf20Sopenharmony_ciBINARY_IN  := $(BINARY)-in.o
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ciall: $(BINARY)
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci$(OUTPUT) $(OUTPUT)/libbpf $(OUTPUT)/libsubcmd:
418c2ecf20Sopenharmony_ci	$(call msg,MKDIR,,$@)
428c2ecf20Sopenharmony_ci	$(Q)mkdir -p $(@)
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci$(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd
458c2ecf20Sopenharmony_ci	$(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)/libbpf
488c2ecf20Sopenharmony_ci	$(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC)  OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ciCFLAGS := -g \
518c2ecf20Sopenharmony_ci          -I$(srctree)/tools/include \
528c2ecf20Sopenharmony_ci          -I$(srctree)/tools/include/uapi \
538c2ecf20Sopenharmony_ci          -I$(LIBBPF_SRC) \
548c2ecf20Sopenharmony_ci          -I$(SUBCMD_SRC)
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ciLIBS = -lelf -lz
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ciexport srctree OUTPUT CFLAGS Q
598c2ecf20Sopenharmony_ciinclude $(srctree)/tools/build/Makefile.include
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci$(BINARY_IN): fixdep FORCE | $(OUTPUT)
628c2ecf20Sopenharmony_ci	$(Q)$(MAKE) $(build)=resolve_btfids
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci$(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN)
658c2ecf20Sopenharmony_ci	$(call msg,LINK,$@)
668c2ecf20Sopenharmony_ci	$(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS)
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ciclean_objects := $(wildcard $(OUTPUT)/*.o                \
698c2ecf20Sopenharmony_ci                            $(OUTPUT)/.*.o.cmd           \
708c2ecf20Sopenharmony_ci                            $(OUTPUT)/.*.o.d             \
718c2ecf20Sopenharmony_ci                            $(OUTPUT)/libbpf             \
728c2ecf20Sopenharmony_ci                            $(OUTPUT)/libsubcmd          \
738c2ecf20Sopenharmony_ci                            $(OUTPUT)/resolve_btfids)
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ciifneq ($(clean_objects),)
768c2ecf20Sopenharmony_ciclean: fixdep-clean
778c2ecf20Sopenharmony_ci	$(call msg,CLEAN,$(BINARY))
788c2ecf20Sopenharmony_ci	$(Q)$(RM) -rf $(clean_objects)
798c2ecf20Sopenharmony_cielse
808c2ecf20Sopenharmony_ciclean:
818c2ecf20Sopenharmony_ciendif
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_citags:
848c2ecf20Sopenharmony_ci	$(call msg,GEN,,tags)
858c2ecf20Sopenharmony_ci	$(Q)ctags -R . $(LIBBPF_SRC) $(SUBCMD_SRC)
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ciFORCE:
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci.PHONY: all FORCE clean tags
90