xref: /linux-6.15/tools/objtool/Makefile (revision bdb8bf7d)
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
15*bdb8bf7dSIan RogersLIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/
16*bdb8bf7dSIan Rogersifneq ($(OUTPUT),)
17*bdb8bf7dSIan Rogers  LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd
18*bdb8bf7dSIan Rogerselse
19*bdb8bf7dSIan Rogers  LIBSUBCMD_OUTPUT = $(CURDIR)/libsubcmd
20*bdb8bf7dSIan Rogersendif
21*bdb8bf7dSIan 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 \
35*bdb8bf7dSIan Rogers	    -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \
36*bdb8bf7dSIan 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
46*bdb8bf7dSIan RogersMKDIR = mkdir
470decf1f8SMatt Helsley
48b51277ebSJosh PoimboeufBUILD_ORC := n
490decf1f8SMatt Helsley
500decf1f8SMatt Helsleyifeq ($(SRCARCH),x86)
51b51277ebSJosh Poimboeuf	BUILD_ORC := y
520decf1f8SMatt Helsleyendif
530decf1f8SMatt Helsley
54b51277ebSJosh Poimboeufexport BUILD_ORC
5560cbdf5dSJosh Poimboeufexport srctree OUTPUT CFLAGS SRCARCH AWK
56442f04c3SJosh Poimboeufinclude $(srctree)/tools/build/Makefile.include
57442f04c3SJosh Poimboeuf
58442f04c3SJosh Poimboeuf$(OBJTOOL_IN): fixdep FORCE
59aa584727SJulien Thierry	@$(CONFIG_SHELL) ./sync-check.sh
60442f04c3SJosh Poimboeuf	@$(MAKE) $(build)=objtool
61442f04c3SJosh Poimboeuf
62442f04c3SJosh Poimboeuf$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
63442f04c3SJosh Poimboeuf	$(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
64442f04c3SJosh Poimboeuf
65442f04c3SJosh Poimboeuf
66*bdb8bf7dSIan Rogers$(LIBSUBCMD_OUTPUT):
67*bdb8bf7dSIan Rogers	@$(MKDIR) -p $@
68442f04c3SJosh Poimboeuf
69*bdb8bf7dSIan Rogers$(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE
70*bdb8bf7dSIan Rogers	@$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
71*bdb8bf7dSIan Rogers		DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \
72*bdb8bf7dSIan Rogers		$@ install_headers
73*bdb8bf7dSIan Rogers
74*bdb8bf7dSIan Rogers$(LIBSUBCMD)-clean:
75*bdb8bf7dSIan Rogers	$(call QUIET_CLEAN, libsubcmd)
76*bdb8bf7dSIan Rogers	$(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT)
77*bdb8bf7dSIan Rogers
78*bdb8bf7dSIan Rogersclean: $(LIBSUBCMD)-clean
79442f04c3SJosh Poimboeuf	$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
80442f04c3SJosh Poimboeuf	$(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
81*bdb8bf7dSIan Rogers	$(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
82442f04c3SJosh Poimboeuf
83442f04c3SJosh PoimboeufFORCE:
84442f04c3SJosh Poimboeuf
85442f04c3SJosh Poimboeuf.PHONY: clean FORCE
86