18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ciinclude ../scripts/Makefile.include
38c2ecf20Sopenharmony_ciinclude ../scripts/Makefile.arch
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci# always use the host compiler
68c2ecf20Sopenharmony_ciAR	 = $(HOSTAR)
78c2ecf20Sopenharmony_ciCC	 = $(HOSTCC)
88c2ecf20Sopenharmony_ciLD	 = $(HOSTLD)
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciifeq ($(srctree),)
118c2ecf20Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(CURDIR)))
128c2ecf20Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(srctree)))
138c2ecf20Sopenharmony_ciendif
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciSUBCMD_SRCDIR		= $(srctree)/tools/lib/subcmd/
168c2ecf20Sopenharmony_ciLIBSUBCMD_OUTPUT	= $(if $(OUTPUT),$(OUTPUT),$(CURDIR)/)
178c2ecf20Sopenharmony_ciLIBSUBCMD		= $(LIBSUBCMD_OUTPUT)libsubcmd.a
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ciOBJTOOL    := $(OUTPUT)objtool
208c2ecf20Sopenharmony_ciOBJTOOL_IN := $(OBJTOOL)-in.o
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciLIBELF_FLAGS := $(shell pkg-config libelf --cflags 2>/dev/null)
238c2ecf20Sopenharmony_ciLIBELF_LIBS  := $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf)
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ciall: $(OBJTOOL)
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciINCLUDES := -I$(srctree)/tools/include \
288c2ecf20Sopenharmony_ci	    -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
298c2ecf20Sopenharmony_ci	    -I$(srctree)/tools/arch/$(SRCARCH)/include	\
308c2ecf20Sopenharmony_ci	    -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include
318c2ecf20Sopenharmony_ciWARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
328c2ecf20Sopenharmony_ciCFLAGS   := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
338c2ecf20Sopenharmony_ciLDFLAGS  += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci# Allow old libelf to be used:
368c2ecf20Sopenharmony_cielfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
378c2ecf20Sopenharmony_ciCFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ciAWK = awk
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciSUBCMD_CHECK := n
428c2ecf20Sopenharmony_ciSUBCMD_ORC := n
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ciifeq ($(SRCARCH),x86)
458c2ecf20Sopenharmony_ci	SUBCMD_CHECK := y
468c2ecf20Sopenharmony_ci	SUBCMD_ORC := y
478c2ecf20Sopenharmony_ciendif
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ciexport SUBCMD_CHECK SUBCMD_ORC
508c2ecf20Sopenharmony_ciexport srctree OUTPUT CFLAGS SRCARCH AWK
518c2ecf20Sopenharmony_ciinclude $(srctree)/tools/build/Makefile.include
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci$(OBJTOOL_IN): fixdep FORCE
548c2ecf20Sopenharmony_ci	@$(CONFIG_SHELL) ./sync-check.sh
558c2ecf20Sopenharmony_ci	@$(MAKE) $(build)=objtool
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
588c2ecf20Sopenharmony_ci	$(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci$(LIBSUBCMD): fixdep FORCE
628c2ecf20Sopenharmony_ci	$(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT)
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ciclean:
658c2ecf20Sopenharmony_ci	$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
668c2ecf20Sopenharmony_ci	$(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
678c2ecf20Sopenharmony_ci	$(Q)$(RM) $(OUTPUT)arch/x86/inat-tables.c $(OUTPUT)fixdep
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ciFORCE:
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci.PHONY: clean FORCE
72