xref: /linux/tools/objtool/Makefile (revision 31eca25f3a3b0de960ca9a478e5a4b2d0b2e8558)
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
26*31eca25fSJosh PoimboeufWARNINGS := -Werror -Wall -Wextra -Wmissing-prototypes			\
27*31eca25fSJosh Poimboeuf	    -Wmissing-declarations -Wwrite-strings			\
28*31eca25fSJosh Poimboeuf	    -Wno-implicit-fallthrough -Wno-sign-compare			\
29*31eca25fSJosh Poimboeuf	    -Wno-unused-parameter
30*31eca25fSJosh Poimboeuf
316a77cff8SJosh PoimboeufINCLUDES := -I$(srctree)/tools/include \
3232b50485SHONG Yifan	    -I$(srctree)/tools/include/uapi \
336a77cff8SJosh Poimboeuf	    -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
346f8ca676SJulien Thierry	    -I$(srctree)/tools/arch/$(SRCARCH)/include	\
357786032eSVasily Gorbik	    -I$(srctree)/tools/objtool/include \
36bdb8bf7dSIan Rogers	    -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \
37bdb8bf7dSIan Rogers	    -I$(LIBSUBCMD_OUTPUT)/include
38*31eca25fSJosh Poimboeuf
39*31eca25fSJosh PoimboeufOBJTOOL_CFLAGS  := -std=gnu11 -fomit-frame-pointer -O2 -g \
40*31eca25fSJosh Poimboeuf		   $(WARNINGS) $(INCLUDES) $(LIBELF_FLAGS) $(HOSTCFLAGS)
41*31eca25fSJosh Poimboeuf
42*31eca25fSJosh PoimboeufOBJTOOL_LDFLAGS := $(LIBSUBCMD) $(LIBELF_LIBS) $(HOSTLDFLAGS)
43442f04c3SJosh Poimboeuf
442e51f262SJan Beulich# Allow old libelf to be used:
45bf71940fSDavid Engrafelfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - 2>/dev/null | grep elf_getshdr)
46cd955bddSIan RogersOBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
47cd955bddSIan Rogers
48cd955bddSIan Rogers# Always want host compilation.
49cd955bddSIan RogersHOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)"
502e51f262SJan Beulich
51442f04c3SJosh PoimboeufAWK = awk
52bdb8bf7dSIan RogersMKDIR = mkdir
530decf1f8SMatt Helsley
54b51277ebSJosh PoimboeufBUILD_ORC := n
550decf1f8SMatt Helsley
560decf1f8SMatt Helsleyifeq ($(SRCARCH),x86)
57b51277ebSJosh Poimboeuf	BUILD_ORC := y
580decf1f8SMatt Helsleyendif
590decf1f8SMatt Helsley
603c7266cdSTiezhu Yangifeq ($(SRCARCH),loongarch)
613c7266cdSTiezhu Yang	BUILD_ORC := y
623c7266cdSTiezhu Yangendif
633c7266cdSTiezhu Yang
64b51277ebSJosh Poimboeufexport BUILD_ORC
6560cbdf5dSJosh Poimboeufexport srctree OUTPUT CFLAGS SRCARCH AWK
66442f04c3SJosh Poimboeufinclude $(srctree)/tools/build/Makefile.include
67442f04c3SJosh Poimboeuf
68cd955bddSIan Rogers$(OBJTOOL_IN): fixdep $(LIBSUBCMD) FORCE
698c4526caSIan Rogers	$(Q)$(CONFIG_SHELL) ./sync-check.sh
70cd955bddSIan Rogers	$(Q)$(MAKE) $(build)=objtool $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \
71cd955bddSIan Rogers		LDFLAGS="$(OBJTOOL_LDFLAGS)"
72cd955bddSIan Rogers
73442f04c3SJosh Poimboeuf
74442f04c3SJosh Poimboeuf$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
75cd955bddSIan Rogers	$(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(OBJTOOL_LDFLAGS) -o $@
76442f04c3SJosh Poimboeuf
77442f04c3SJosh Poimboeuf
78bdb8bf7dSIan Rogers$(LIBSUBCMD_OUTPUT):
798c4526caSIan Rogers	$(Q)$(MKDIR) -p $@
80442f04c3SJosh Poimboeuf
81bdb8bf7dSIan Rogers$(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE
828c4526caSIan Rogers	$(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
83bdb8bf7dSIan Rogers		DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \
84cd955bddSIan Rogers		$(HOST_OVERRIDES) EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \
85bdb8bf7dSIan Rogers		$@ install_headers
86bdb8bf7dSIan Rogers
87bdb8bf7dSIan Rogers$(LIBSUBCMD)-clean:
88bdb8bf7dSIan Rogers	$(call QUIET_CLEAN, libsubcmd)
89bdb8bf7dSIan Rogers	$(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT)
90bdb8bf7dSIan Rogers
91bdb8bf7dSIan Rogersclean: $(LIBSUBCMD)-clean
92442f04c3SJosh Poimboeuf	$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
93442f04c3SJosh Poimboeuf	$(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
94bdb8bf7dSIan Rogers	$(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
95442f04c3SJosh Poimboeuf
96442f04c3SJosh PoimboeufFORCE:
97442f04c3SJosh Poimboeuf
98442f04c3SJosh Poimboeuf.PHONY: clean FORCE
99