xref: /linux-6.15/tools/objtool/Makefile (revision 8c4526ca)
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
2442f04c3SJosh Poimboeufinclude ../scripts/Makefile.include
3630e7a29SArnaldo Carvalho de Meloinclude ../scripts/Makefile.arch
4442f04c3SJosh Poimboeuf
5c1d45c3aSJosh Poimboeuf# always use the host compiler
68ea58f1eSNathan ChancellorAR	 = $(HOSTAR)
714c47b54SMikulas PatockaCC	 = $(HOSTCC)
814c47b54SMikulas PatockaLD	 = $(HOSTLD)
9c1d45c3aSJosh Poimboeuf
10442f04c3SJosh Poimboeufifeq ($(srctree),)
11e19b7ceeSUwe Kleine-Königsrctree := $(patsubst %/,%,$(dir $(CURDIR)))
12442f04c3SJosh Poimboeufsrctree := $(patsubst %/,%,$(dir $(srctree)))
13442f04c3SJosh Poimboeufendif
14442f04c3SJosh Poimboeuf
15bdb8bf7dSIan RogersLIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/
16bdb8bf7dSIan Rogersifneq ($(OUTPUT),)
17bdb8bf7dSIan Rogers  LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd
18bdb8bf7dSIan Rogerselse
19bdb8bf7dSIan Rogers  LIBSUBCMD_OUTPUT = $(CURDIR)/libsubcmd
20bdb8bf7dSIan Rogersendif
21bdb8bf7dSIan RogersLIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a
22442f04c3SJosh Poimboeuf
23442f04c3SJosh PoimboeufOBJTOOL    := $(OUTPUT)objtool
24442f04c3SJosh PoimboeufOBJTOOL_IN := $(OBJTOOL)-in.o
25442f04c3SJosh Poimboeuf
26d5ea4fecSChun-Tse ShaoLIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null)
27d5ea4fecSChun-Tse ShaoLIBELF_LIBS  := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)
28056d28d1SRolf Eike Beer
29442f04c3SJosh Poimboeufall: $(OBJTOOL)
30442f04c3SJosh Poimboeuf
316a77cff8SJosh PoimboeufINCLUDES := -I$(srctree)/tools/include \
326a77cff8SJosh Poimboeuf	    -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
336f8ca676SJulien Thierry	    -I$(srctree)/tools/arch/$(SRCARCH)/include	\
347786032eSVasily Gorbik	    -I$(srctree)/tools/objtool/include \
35bdb8bf7dSIan Rogers	    -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \
36bdb8bf7dSIan Rogers	    -I$(LIBSUBCMD_OUTPUT)/include
372486baaeSVasily GorbikWARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
38f73b3cc3SJosh PoimboeufCFLAGS   := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
39056d28d1SRolf Eike BeerLDFLAGS  += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
40442f04c3SJosh Poimboeuf
412e51f262SJan Beulich# Allow old libelf to be used:
429564a8cfSRasmus Villemoeselfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
432e51f262SJan BeulichCFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
442e51f262SJan Beulich
45442f04c3SJosh PoimboeufAWK = awk
46bdb8bf7dSIan RogersMKDIR = mkdir
470decf1f8SMatt Helsley
48*8c4526caSIan Rogersifeq ($(V),1)
49*8c4526caSIan Rogers  Q =
50*8c4526caSIan Rogerselse
51*8c4526caSIan Rogers  Q = @
52*8c4526caSIan Rogersendif
53*8c4526caSIan 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
64442f04c3SJosh Poimboeuf$(OBJTOOL_IN): fixdep FORCE
65*8c4526caSIan Rogers	$(Q)$(CONFIG_SHELL) ./sync-check.sh
66*8c4526caSIan Rogers	$(Q)$(MAKE) $(build)=objtool
67442f04c3SJosh Poimboeuf
68442f04c3SJosh Poimboeuf$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
69442f04c3SJosh Poimboeuf	$(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
70442f04c3SJosh Poimboeuf
71442f04c3SJosh Poimboeuf
72bdb8bf7dSIan Rogers$(LIBSUBCMD_OUTPUT):
73*8c4526caSIan Rogers	$(Q)$(MKDIR) -p $@
74442f04c3SJosh Poimboeuf
75bdb8bf7dSIan Rogers$(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE
76*8c4526caSIan Rogers	$(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
77bdb8bf7dSIan Rogers		DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \
78bdb8bf7dSIan Rogers		$@ install_headers
79bdb8bf7dSIan Rogers
80bdb8bf7dSIan Rogers$(LIBSUBCMD)-clean:
81bdb8bf7dSIan Rogers	$(call QUIET_CLEAN, libsubcmd)
82bdb8bf7dSIan Rogers	$(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT)
83bdb8bf7dSIan Rogers
84bdb8bf7dSIan Rogersclean: $(LIBSUBCMD)-clean
85442f04c3SJosh Poimboeuf	$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
86442f04c3SJosh Poimboeuf	$(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
87bdb8bf7dSIan Rogers	$(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
88442f04c3SJosh Poimboeuf
89442f04c3SJosh PoimboeufFORCE:
90442f04c3SJosh Poimboeuf
91442f04c3SJosh Poimboeuf.PHONY: clean FORCE
92