xref: /linux/tools/objtool/Makefile (revision dd590d4d57ebeeb826823c288741f2ed20f452af)
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)
150d83da43SJosh Poimboeuf	HAVE_XXHASH = $(shell echo "int main() {}" | \
160d83da43SJosh Poimboeuf		      $(HOSTCC) -xc - -o /dev/null -lxxhash 2> /dev/null && echo y || echo n)
170d83da43SJosh Poimboeuf	ifeq ($(HAVE_XXHASH),y)
18*dd590d4dSJosh 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
25*dd590d4dSJosh 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
73442f04c3SJosh PoimboeufAWK = awk
74bdb8bf7dSIan RogersMKDIR = mkdir
750decf1f8SMatt Helsley
7660cbdf5dSJosh Poimboeufexport srctree OUTPUT CFLAGS SRCARCH AWK
77442f04c3SJosh Poimboeufinclude $(srctree)/tools/build/Makefile.include
78442f04c3SJosh Poimboeuf
79cd955bddSIan Rogers$(OBJTOOL_IN): fixdep $(LIBSUBCMD) FORCE
808c4526caSIan Rogers	$(Q)$(CONFIG_SHELL) ./sync-check.sh
81cd955bddSIan Rogers	$(Q)$(MAKE) $(build)=objtool $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \
82cd955bddSIan Rogers		LDFLAGS="$(OBJTOOL_LDFLAGS)"
83cd955bddSIan Rogers
84442f04c3SJosh Poimboeuf
85442f04c3SJosh Poimboeuf$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
86cd955bddSIan Rogers	$(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(OBJTOOL_LDFLAGS) -o $@
87442f04c3SJosh Poimboeuf
88442f04c3SJosh Poimboeuf
89bdb8bf7dSIan Rogers$(LIBSUBCMD_OUTPUT):
908c4526caSIan Rogers	$(Q)$(MKDIR) -p $@
91442f04c3SJosh Poimboeuf
92bdb8bf7dSIan Rogers$(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE
938c4526caSIan Rogers	$(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
94bdb8bf7dSIan Rogers		DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \
95cd955bddSIan Rogers		$(HOST_OVERRIDES) EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \
96bdb8bf7dSIan Rogers		$@ install_headers
97bdb8bf7dSIan Rogers
98bdb8bf7dSIan Rogers$(LIBSUBCMD)-clean:
99bdb8bf7dSIan Rogers	$(call QUIET_CLEAN, libsubcmd)
100bdb8bf7dSIan Rogers	$(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT)
101bdb8bf7dSIan Rogers
102bdb8bf7dSIan Rogersclean: $(LIBSUBCMD)-clean
103442f04c3SJosh Poimboeuf	$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
104442f04c3SJosh Poimboeuf	$(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
105bdb8bf7dSIan Rogers	$(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
106442f04c3SJosh Poimboeuf
107442f04c3SJosh PoimboeufFORCE:
108442f04c3SJosh Poimboeuf
109442f04c3SJosh Poimboeuf.PHONY: clean FORCE
110