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 \ 276a77cff8SJosh Poimboeuf -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \ 286f8ca676SJulien Thierry -I$(srctree)/tools/arch/$(SRCARCH)/include \ 297786032eSVasily Gorbik -I$(srctree)/tools/objtool/include \ 30bdb8bf7dSIan Rogers -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \ 31bdb8bf7dSIan Rogers -I$(LIBSUBCMD_OUTPUT)/include 32*cd955bddSIan Rogers# Note, EXTRA_WARNINGS here was determined for CC and not HOSTCC, it 33*cd955bddSIan Rogers# is passed here to match a legacy behavior. 342486baaeSVasily GorbikWARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs 35*cd955bddSIan RogersOBJTOOL_CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS) 36*cd955bddSIan RogersOBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) 37442f04c3SJosh Poimboeuf 382e51f262SJan Beulich# Allow old libelf to be used: 39*cd955bddSIan Rogerselfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - | grep elf_getshdr) 40*cd955bddSIan RogersOBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED) 41*cd955bddSIan Rogers 42*cd955bddSIan Rogers# Always want host compilation. 43*cd955bddSIan RogersHOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)" 442e51f262SJan Beulich 45442f04c3SJosh PoimboeufAWK = awk 46bdb8bf7dSIan RogersMKDIR = mkdir 470decf1f8SMatt Helsley 488c4526caSIan Rogersifeq ($(V),1) 498c4526caSIan Rogers Q = 508c4526caSIan Rogerselse 518c4526caSIan Rogers Q = @ 528c4526caSIan Rogersendif 538c4526caSIan Rogers 54b51277ebSJosh PoimboeufBUILD_ORC := n 550decf1f8SMatt Helsley 560decf1f8SMatt Helsleyifeq ($(SRCARCH),x86) 57b51277ebSJosh Poimboeuf BUILD_ORC := y 580decf1f8SMatt Helsleyendif 590decf1f8SMatt Helsley 60b51277ebSJosh Poimboeufexport BUILD_ORC 6160cbdf5dSJosh Poimboeufexport srctree OUTPUT CFLAGS SRCARCH AWK 62442f04c3SJosh Poimboeufinclude $(srctree)/tools/build/Makefile.include 63442f04c3SJosh Poimboeuf 64*cd955bddSIan Rogers$(OBJTOOL_IN): fixdep $(LIBSUBCMD) FORCE 658c4526caSIan Rogers $(Q)$(CONFIG_SHELL) ./sync-check.sh 66*cd955bddSIan Rogers $(Q)$(MAKE) $(build)=objtool $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \ 67*cd955bddSIan Rogers LDFLAGS="$(OBJTOOL_LDFLAGS)" 68*cd955bddSIan Rogers 69442f04c3SJosh Poimboeuf 70442f04c3SJosh Poimboeuf$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN) 71*cd955bddSIan Rogers $(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(OBJTOOL_LDFLAGS) -o $@ 72442f04c3SJosh Poimboeuf 73442f04c3SJosh Poimboeuf 74bdb8bf7dSIan Rogers$(LIBSUBCMD_OUTPUT): 758c4526caSIan Rogers $(Q)$(MKDIR) -p $@ 76442f04c3SJosh Poimboeuf 77bdb8bf7dSIan Rogers$(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE 788c4526caSIan Rogers $(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \ 79bdb8bf7dSIan Rogers DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \ 80*cd955bddSIan Rogers $(HOST_OVERRIDES) EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \ 81bdb8bf7dSIan Rogers $@ install_headers 82bdb8bf7dSIan Rogers 83bdb8bf7dSIan Rogers$(LIBSUBCMD)-clean: 84bdb8bf7dSIan Rogers $(call QUIET_CLEAN, libsubcmd) 85bdb8bf7dSIan Rogers $(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT) 86bdb8bf7dSIan Rogers 87bdb8bf7dSIan Rogersclean: $(LIBSUBCMD)-clean 88442f04c3SJosh Poimboeuf $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL) 89442f04c3SJosh Poimboeuf $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete 90bdb8bf7dSIan Rogers $(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep 91442f04c3SJosh Poimboeuf 92442f04c3SJosh PoimboeufFORCE: 93442f04c3SJosh Poimboeuf 94442f04c3SJosh Poimboeuf.PHONY: clean FORCE 95