1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 2442f04c3SJosh Poimboeufinclude ../scripts/Makefile.include 3630e7a29SArnaldo Carvalho de Meloinclude ../scripts/Makefile.arch 4442f04c3SJosh Poimboeuf 5442f04c3SJosh Poimboeufifeq ($(srctree),) 6e19b7ceeSUwe Kleine-Königsrctree := $(patsubst %/,%,$(dir $(CURDIR))) 7442f04c3SJosh Poimboeufsrctree := $(patsubst %/,%,$(dir $(srctree))) 8442f04c3SJosh Poimboeufendif 9442f04c3SJosh Poimboeuf 10bdb8bf7dSIan RogersLIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/ 11bdb8bf7dSIan Rogersifneq ($(OUTPUT),) 12bdb8bf7dSIan Rogers LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd 13bdb8bf7dSIan Rogerselse 14bdb8bf7dSIan Rogers LIBSUBCMD_OUTPUT = $(CURDIR)/libsubcmd 15bdb8bf7dSIan Rogersendif 16bdb8bf7dSIan RogersLIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a 17442f04c3SJosh Poimboeuf 18442f04c3SJosh PoimboeufOBJTOOL := $(OUTPUT)objtool 19442f04c3SJosh PoimboeufOBJTOOL_IN := $(OBJTOOL)-in.o 20442f04c3SJosh Poimboeuf 21d5ea4fecSChun-Tse ShaoLIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null) 22d5ea4fecSChun-Tse ShaoLIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf) 23056d28d1SRolf Eike Beer 24442f04c3SJosh Poimboeufall: $(OBJTOOL) 25442f04c3SJosh Poimboeuf 266a77cff8SJosh PoimboeufINCLUDES := -I$(srctree)/tools/include \ 27*32b50485SHONG Yifan -I$(srctree)/tools/include/uapi \ 286a77cff8SJosh Poimboeuf -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \ 296f8ca676SJulien Thierry -I$(srctree)/tools/arch/$(SRCARCH)/include \ 307786032eSVasily Gorbik -I$(srctree)/tools/objtool/include \ 31bdb8bf7dSIan Rogers -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \ 32bdb8bf7dSIan Rogers -I$(LIBSUBCMD_OUTPUT)/include 33cd955bddSIan Rogers# Note, EXTRA_WARNINGS here was determined for CC and not HOSTCC, it 34cd955bddSIan Rogers# is passed here to match a legacy behavior. 352486baaeSVasily GorbikWARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs 36cd955bddSIan RogersOBJTOOL_CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS) 37cd955bddSIan RogersOBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) 38442f04c3SJosh Poimboeuf 392e51f262SJan Beulich# Allow old libelf to be used: 40cd955bddSIan Rogerselfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - 2>/dev/null | grep elf_getshdr) 41cd955bddSIan RogersOBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED) 42cd955bddSIan Rogers 43cd955bddSIan Rogers# Always want host compilation. 44cd955bddSIan RogersHOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)" 452e51f262SJan Beulich 46442f04c3SJosh PoimboeufAWK = awk 47bdb8bf7dSIan RogersMKDIR = mkdir 480decf1f8SMatt Helsley 49b51277ebSJosh PoimboeufBUILD_ORC := n 500decf1f8SMatt Helsley 510decf1f8SMatt Helsleyifeq ($(SRCARCH),x86) 52b51277ebSJosh Poimboeuf BUILD_ORC := y 530decf1f8SMatt Helsleyendif 540decf1f8SMatt Helsley 553c7266cdSTiezhu Yangifeq ($(SRCARCH),loongarch) 563c7266cdSTiezhu Yang BUILD_ORC := y 573c7266cdSTiezhu Yangendif 583c7266cdSTiezhu Yang 59b51277ebSJosh Poimboeufexport BUILD_ORC 6060cbdf5dSJosh Poimboeufexport srctree OUTPUT CFLAGS SRCARCH AWK 61442f04c3SJosh Poimboeufinclude $(srctree)/tools/build/Makefile.include 62442f04c3SJosh Poimboeuf 63cd955bddSIan Rogers$(OBJTOOL_IN): fixdep $(LIBSUBCMD) FORCE 648c4526caSIan Rogers $(Q)$(CONFIG_SHELL) ./sync-check.sh 65cd955bddSIan Rogers $(Q)$(MAKE) $(build)=objtool $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \ 66cd955bddSIan Rogers LDFLAGS="$(OBJTOOL_LDFLAGS)" 67cd955bddSIan Rogers 68442f04c3SJosh Poimboeuf 69442f04c3SJosh Poimboeuf$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN) 70cd955bddSIan Rogers $(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(OBJTOOL_LDFLAGS) -o $@ 71442f04c3SJosh Poimboeuf 72442f04c3SJosh Poimboeuf 73bdb8bf7dSIan Rogers$(LIBSUBCMD_OUTPUT): 748c4526caSIan Rogers $(Q)$(MKDIR) -p $@ 75442f04c3SJosh Poimboeuf 76bdb8bf7dSIan Rogers$(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE 778c4526caSIan Rogers $(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \ 78bdb8bf7dSIan Rogers DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \ 79cd955bddSIan Rogers $(HOST_OVERRIDES) EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \ 80bdb8bf7dSIan Rogers $@ install_headers 81bdb8bf7dSIan Rogers 82bdb8bf7dSIan Rogers$(LIBSUBCMD)-clean: 83bdb8bf7dSIan Rogers $(call QUIET_CLEAN, libsubcmd) 84bdb8bf7dSIan Rogers $(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT) 85bdb8bf7dSIan Rogers 86bdb8bf7dSIan Rogersclean: $(LIBSUBCMD)-clean 87442f04c3SJosh Poimboeuf $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL) 88442f04c3SJosh Poimboeuf $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete 89bdb8bf7dSIan Rogers $(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep 90442f04c3SJosh Poimboeuf 91442f04c3SJosh PoimboeufFORCE: 92442f04c3SJosh Poimboeuf 93442f04c3SJosh Poimboeuf.PHONY: clean FORCE 94