162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ciinclude ../scripts/Makefile.include
362306a36Sopenharmony_ciinclude ../scripts/Makefile.arch
462306a36Sopenharmony_ci
562306a36Sopenharmony_ciifeq ($(srctree),)
662306a36Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(CURDIR)))
762306a36Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(srctree)))
862306a36Sopenharmony_ciendif
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ciLIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/
1162306a36Sopenharmony_ciifneq ($(OUTPUT),)
1262306a36Sopenharmony_ci  LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd
1362306a36Sopenharmony_cielse
1462306a36Sopenharmony_ci  LIBSUBCMD_OUTPUT = $(CURDIR)/libsubcmd
1562306a36Sopenharmony_ciendif
1662306a36Sopenharmony_ciLIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ciOBJTOOL    := $(OUTPUT)objtool
1962306a36Sopenharmony_ciOBJTOOL_IN := $(OBJTOOL)-in.o
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ciLIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null)
2262306a36Sopenharmony_ciLIBELF_LIBS  := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ciall: $(OBJTOOL)
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ciINCLUDES := -I$(srctree)/tools/include \
2762306a36Sopenharmony_ci	    -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
2862306a36Sopenharmony_ci	    -I$(srctree)/tools/arch/$(SRCARCH)/include	\
2962306a36Sopenharmony_ci	    -I$(srctree)/tools/objtool/include \
3062306a36Sopenharmony_ci	    -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \
3162306a36Sopenharmony_ci	    -I$(LIBSUBCMD_OUTPUT)/include
3262306a36Sopenharmony_ci# Note, EXTRA_WARNINGS here was determined for CC and not HOSTCC, it
3362306a36Sopenharmony_ci# is passed here to match a legacy behavior.
3462306a36Sopenharmony_ciWARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
3562306a36Sopenharmony_ciOBJTOOL_CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
3662306a36Sopenharmony_ciOBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci# Allow old libelf to be used:
3962306a36Sopenharmony_cielfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - | grep elf_getshdr)
4062306a36Sopenharmony_ciOBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci# Always want host compilation.
4362306a36Sopenharmony_ciHOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)"
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ciAWK = awk
4662306a36Sopenharmony_ciMKDIR = mkdir
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ciifeq ($(V),1)
4962306a36Sopenharmony_ci  Q =
5062306a36Sopenharmony_cielse
5162306a36Sopenharmony_ci  Q = @
5262306a36Sopenharmony_ciendif
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ciBUILD_ORC := n
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ciifeq ($(SRCARCH),x86)
5762306a36Sopenharmony_ci	BUILD_ORC := y
5862306a36Sopenharmony_ciendif
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ciexport BUILD_ORC
6162306a36Sopenharmony_ciexport srctree OUTPUT CFLAGS SRCARCH AWK
6262306a36Sopenharmony_ciinclude $(srctree)/tools/build/Makefile.include
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci$(OBJTOOL_IN): fixdep $(LIBSUBCMD) FORCE
6562306a36Sopenharmony_ci	$(Q)$(CONFIG_SHELL) ./sync-check.sh
6662306a36Sopenharmony_ci	$(Q)$(MAKE) $(build)=objtool $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \
6762306a36Sopenharmony_ci		LDFLAGS="$(OBJTOOL_LDFLAGS)"
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
7162306a36Sopenharmony_ci	$(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(OBJTOOL_LDFLAGS) -o $@
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci$(LIBSUBCMD_OUTPUT):
7562306a36Sopenharmony_ci	$(Q)$(MKDIR) -p $@
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci$(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE
7862306a36Sopenharmony_ci	$(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
7962306a36Sopenharmony_ci		DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \
8062306a36Sopenharmony_ci		$(HOST_OVERRIDES) EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \
8162306a36Sopenharmony_ci		$@ install_headers
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci$(LIBSUBCMD)-clean:
8462306a36Sopenharmony_ci	$(call QUIET_CLEAN, libsubcmd)
8562306a36Sopenharmony_ci	$(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT)
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ciclean: $(LIBSUBCMD)-clean
8862306a36Sopenharmony_ci	$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
8962306a36Sopenharmony_ci	$(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
9062306a36Sopenharmony_ci	$(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ciFORCE:
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci.PHONY: clean FORCE
95