1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 2442f04c3SJosh Poimboeufinclude ../scripts/Makefile.include 3630e7a29SArnaldo Carvalho de Meloinclude ../scripts/Makefile.arch 4442f04c3SJosh Poimboeuf 50d83da43SJosh Poimboeufifeq ($(SRCARCH),x86) 60d83da43SJosh Poimboeuf BUILD_ORC := y 70d83da43SJosh Poimboeuf ARCH_HAS_KLP := y 80d83da43SJosh Poimboeufendif 90d83da43SJosh Poimboeuf 100d83da43SJosh Poimboeufifeq ($(SRCARCH),loongarch) 110d83da43SJosh Poimboeuf BUILD_ORC := y 120d83da43SJosh Poimboeufendif 130d83da43SJosh Poimboeuf 140d83da43SJosh Poimboeufifeq ($(ARCH_HAS_KLP),y) 15ee0b48faSJosh Poimboeuf HAVE_XXHASH = $(shell printf "$(pound)include <xxhash.h>\nXXH3_state_t *state;int main() {}" | \ 160d83da43SJosh Poimboeuf $(HOSTCC) -xc - -o /dev/null -lxxhash 2> /dev/null && echo y || echo n) 170d83da43SJosh Poimboeuf ifeq ($(HAVE_XXHASH),y) 18dd590d4dSJosh Poimboeuf BUILD_KLP := y 190d83da43SJosh Poimboeuf LIBXXHASH_CFLAGS := $(shell $(HOSTPKG_CONFIG) libxxhash --cflags 2>/dev/null) \ 200d83da43SJosh Poimboeuf -DBUILD_KLP 210d83da43SJosh Poimboeuf LIBXXHASH_LIBS := $(shell $(HOSTPKG_CONFIG) libxxhash --libs 2>/dev/null || echo -lxxhash) 220d83da43SJosh Poimboeuf endif 230d83da43SJosh Poimboeufendif 240d83da43SJosh Poimboeuf 25dd590d4dSJosh Poimboeufexport BUILD_ORC BUILD_KLP 260d83da43SJosh Poimboeuf 27442f04c3SJosh Poimboeufifeq ($(srctree),) 28e19b7ceeSUwe Kleine-Königsrctree := $(patsubst %/,%,$(dir $(CURDIR))) 29442f04c3SJosh Poimboeufsrctree := $(patsubst %/,%,$(dir $(srctree))) 30442f04c3SJosh Poimboeufendif 31442f04c3SJosh Poimboeuf 32bdb8bf7dSIan RogersLIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/ 33bdb8bf7dSIan Rogersifneq ($(OUTPUT),) 34bdb8bf7dSIan Rogers LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd 35bdb8bf7dSIan Rogerselse 36bdb8bf7dSIan Rogers LIBSUBCMD_OUTPUT = $(CURDIR)/libsubcmd 37bdb8bf7dSIan Rogersendif 38bdb8bf7dSIan RogersLIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a 39442f04c3SJosh Poimboeuf 40442f04c3SJosh PoimboeufOBJTOOL := $(OUTPUT)objtool 41442f04c3SJosh PoimboeufOBJTOOL_IN := $(OBJTOOL)-in.o 42442f04c3SJosh Poimboeuf 43d5ea4fecSChun-Tse ShaoLIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null) 44d5ea4fecSChun-Tse ShaoLIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf) 45056d28d1SRolf Eike Beer 46442f04c3SJosh Poimboeufall: $(OBJTOOL) 47442f04c3SJosh Poimboeuf 4831eca25fSJosh PoimboeufWARNINGS := -Werror -Wall -Wextra -Wmissing-prototypes \ 4931eca25fSJosh Poimboeuf -Wmissing-declarations -Wwrite-strings \ 5031eca25fSJosh Poimboeuf -Wno-implicit-fallthrough -Wno-sign-compare \ 5131eca25fSJosh Poimboeuf -Wno-unused-parameter 5231eca25fSJosh Poimboeuf 536a77cff8SJosh PoimboeufINCLUDES := -I$(srctree)/tools/include \ 5432b50485SHONG Yifan -I$(srctree)/tools/include/uapi \ 556a77cff8SJosh Poimboeuf -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \ 566f8ca676SJulien Thierry -I$(srctree)/tools/arch/$(SRCARCH)/include \ 577786032eSVasily Gorbik -I$(srctree)/tools/objtool/include \ 58bdb8bf7dSIan Rogers -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \ 59bdb8bf7dSIan Rogers -I$(LIBSUBCMD_OUTPUT)/include 6031eca25fSJosh Poimboeuf 610d83da43SJosh PoimboeufOBJTOOL_CFLAGS := -std=gnu11 -fomit-frame-pointer -O2 -g $(WARNINGS) \ 620d83da43SJosh Poimboeuf $(INCLUDES) $(LIBELF_FLAGS) $(LIBXXHASH_CFLAGS) $(HOSTCFLAGS) 6331eca25fSJosh Poimboeuf 640d83da43SJosh PoimboeufOBJTOOL_LDFLAGS := $(LIBSUBCMD) $(LIBELF_LIBS) $(LIBXXHASH_LIBS) $(HOSTLDFLAGS) 65442f04c3SJosh Poimboeuf 662e51f262SJan Beulich# Allow old libelf to be used: 67bf71940fSDavid Engrafelfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - 2>/dev/null | grep elf_getshdr) 68cd955bddSIan RogersOBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED) 69cd955bddSIan Rogers 70cd955bddSIan Rogers# Always want host compilation. 71cd955bddSIan RogersHOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)" 722e51f262SJan Beulich 7359953303SAlexandre Chartre# 7459953303SAlexandre Chartre# To support disassembly, objtool needs libopcodes which is provided 75*436326bcSSasha Levin# with libbfd (binutils-dev or binutils-devel package). 7659953303SAlexandre Chartre# 77*436326bcSSasha Levin# We check using HOSTCC directly rather than the shared feature framework 78*436326bcSSasha Levin# because objtool is a host tool that links against host libraries. 79*436326bcSSasha Levin# 80*436326bcSSasha LevinHAVE_LIBOPCODES := $(shell echo 'int main(void) { return 0; }' | \ 81*436326bcSSasha Levin $(HOSTCC) -xc - -o /dev/null -lopcodes 2>/dev/null && echo y) 8259953303SAlexandre Chartre 83*436326bcSSasha Levin# Styled disassembler support requires binutils >= 2.39 84*436326bcSSasha LevinHAVE_DISASM_STYLED := $(shell echo '$(pound)include <dis-asm.h>' | \ 85*436326bcSSasha Levin $(HOSTCC) -E -xc - 2>/dev/null | grep -q disassembler_style && echo y) 8659953303SAlexandre Chartre 8759953303SAlexandre ChartreBUILD_DISAS := n 8859953303SAlexandre Chartre 89*436326bcSSasha Levinifeq ($(HAVE_LIBOPCODES),y) 9059953303SAlexandre Chartre BUILD_DISAS := y 91*436326bcSSasha Levin OBJTOOL_CFLAGS += -DDISAS -DPACKAGE='"objtool"' 9259953303SAlexandre Chartre OBJTOOL_LDFLAGS += -lopcodes 93*436326bcSSasha Levinifeq ($(HAVE_DISASM_STYLED),y) 94*436326bcSSasha Levin OBJTOOL_CFLAGS += -DDISASM_INIT_STYLED 95*436326bcSSasha Levinendif 9659953303SAlexandre Chartreendif 9759953303SAlexandre Chartre 9859953303SAlexandre Chartreexport BUILD_DISAS 9959953303SAlexandre Chartre 100442f04c3SJosh PoimboeufAWK = awk 101bdb8bf7dSIan RogersMKDIR = mkdir 1020decf1f8SMatt Helsley 10360cbdf5dSJosh Poimboeufexport srctree OUTPUT CFLAGS SRCARCH AWK 104442f04c3SJosh Poimboeufinclude $(srctree)/tools/build/Makefile.include 105442f04c3SJosh Poimboeuf 106cd955bddSIan Rogers$(OBJTOOL_IN): fixdep $(LIBSUBCMD) FORCE 1078c4526caSIan Rogers $(Q)$(CONFIG_SHELL) ./sync-check.sh 108cd955bddSIan Rogers $(Q)$(MAKE) $(build)=objtool $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \ 109cd955bddSIan Rogers LDFLAGS="$(OBJTOOL_LDFLAGS)" 110cd955bddSIan Rogers 111442f04c3SJosh Poimboeuf 112442f04c3SJosh Poimboeuf$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN) 113cd955bddSIan Rogers $(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(OBJTOOL_LDFLAGS) -o $@ 114442f04c3SJosh Poimboeuf 115442f04c3SJosh Poimboeuf 116bdb8bf7dSIan Rogers$(LIBSUBCMD_OUTPUT): 1178c4526caSIan Rogers $(Q)$(MKDIR) -p $@ 118442f04c3SJosh Poimboeuf 119bdb8bf7dSIan Rogers$(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE 1208c4526caSIan Rogers $(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \ 121bdb8bf7dSIan Rogers DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \ 122cd955bddSIan Rogers $(HOST_OVERRIDES) EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \ 123bdb8bf7dSIan Rogers $@ install_headers 124bdb8bf7dSIan Rogers 125bdb8bf7dSIan Rogers$(LIBSUBCMD)-clean: 126bdb8bf7dSIan Rogers $(call QUIET_CLEAN, libsubcmd) 127bdb8bf7dSIan Rogers $(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT) 128bdb8bf7dSIan Rogers 129bdb8bf7dSIan Rogersclean: $(LIBSUBCMD)-clean 130442f04c3SJosh Poimboeuf $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL) 131442f04c3SJosh Poimboeuf $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete 1328308fd00SAlexandre Chartre $(Q)$(RM) $(OUTPUT)arch/x86/lib/cpu-feature-names.c $(OUTPUT)fixdep 133bdb8bf7dSIan Rogers $(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep 13459953303SAlexandre Chartre $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.objtool 13559953303SAlexandre Chartre $(Q)$(RM) -r -- $(OUTPUT)feature 136442f04c3SJosh Poimboeuf 137442f04c3SJosh PoimboeufFORCE: 138442f04c3SJosh Poimboeuf 139442f04c3SJosh Poimboeuf.PHONY: clean FORCE 140