xref: /linux/tools/objtool/Makefile (revision 0d83da43b1e1c8ce19f2bb10f54a0fdf795364f7)
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
2442f04c3SJosh Poimboeufinclude ../scripts/Makefile.include
3630e7a29SArnaldo Carvalho de Meloinclude ../scripts/Makefile.arch
4442f04c3SJosh Poimboeuf
5*0d83da43SJosh Poimboeufifeq ($(SRCARCH),x86)
6*0d83da43SJosh Poimboeuf	BUILD_ORC    := y
7*0d83da43SJosh Poimboeuf	ARCH_HAS_KLP := y
8*0d83da43SJosh Poimboeufendif
9*0d83da43SJosh Poimboeuf
10*0d83da43SJosh Poimboeufifeq ($(SRCARCH),loongarch)
11*0d83da43SJosh Poimboeuf	BUILD_ORC	   := y
12*0d83da43SJosh Poimboeufendif
13*0d83da43SJosh Poimboeuf
14*0d83da43SJosh Poimboeufifeq ($(ARCH_HAS_KLP),y)
15*0d83da43SJosh Poimboeuf	HAVE_XXHASH = $(shell echo "int main() {}" | \
16*0d83da43SJosh Poimboeuf		      $(HOSTCC) -xc - -o /dev/null -lxxhash 2> /dev/null && echo y || echo n)
17*0d83da43SJosh Poimboeuf	ifeq ($(HAVE_XXHASH),y)
18*0d83da43SJosh Poimboeuf		LIBXXHASH_CFLAGS := $(shell $(HOSTPKG_CONFIG) libxxhash --cflags 2>/dev/null) \
19*0d83da43SJosh Poimboeuf				    -DBUILD_KLP
20*0d83da43SJosh Poimboeuf		LIBXXHASH_LIBS   := $(shell $(HOSTPKG_CONFIG) libxxhash --libs 2>/dev/null || echo -lxxhash)
21*0d83da43SJosh Poimboeuf	endif
22*0d83da43SJosh Poimboeufendif
23*0d83da43SJosh Poimboeuf
24*0d83da43SJosh Poimboeufexport BUILD_ORC
25*0d83da43SJosh Poimboeuf
26442f04c3SJosh Poimboeufifeq ($(srctree),)
27e19b7ceeSUwe Kleine-Königsrctree := $(patsubst %/,%,$(dir $(CURDIR)))
28442f04c3SJosh Poimboeufsrctree := $(patsubst %/,%,$(dir $(srctree)))
29442f04c3SJosh Poimboeufendif
30442f04c3SJosh Poimboeuf
31bdb8bf7dSIan RogersLIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/
32bdb8bf7dSIan Rogersifneq ($(OUTPUT),)
33bdb8bf7dSIan Rogers  LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd
34bdb8bf7dSIan Rogerselse
35bdb8bf7dSIan Rogers  LIBSUBCMD_OUTPUT = $(CURDIR)/libsubcmd
36bdb8bf7dSIan Rogersendif
37bdb8bf7dSIan RogersLIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a
38442f04c3SJosh Poimboeuf
39442f04c3SJosh PoimboeufOBJTOOL    := $(OUTPUT)objtool
40442f04c3SJosh PoimboeufOBJTOOL_IN := $(OBJTOOL)-in.o
41442f04c3SJosh Poimboeuf
42d5ea4fecSChun-Tse ShaoLIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null)
43d5ea4fecSChun-Tse ShaoLIBELF_LIBS  := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)
44056d28d1SRolf Eike Beer
45442f04c3SJosh Poimboeufall: $(OBJTOOL)
46442f04c3SJosh Poimboeuf
4731eca25fSJosh PoimboeufWARNINGS := -Werror -Wall -Wextra -Wmissing-prototypes			\
4831eca25fSJosh Poimboeuf	    -Wmissing-declarations -Wwrite-strings			\
4931eca25fSJosh Poimboeuf	    -Wno-implicit-fallthrough -Wno-sign-compare			\
5031eca25fSJosh Poimboeuf	    -Wno-unused-parameter
5131eca25fSJosh Poimboeuf
526a77cff8SJosh PoimboeufINCLUDES := -I$(srctree)/tools/include \
5332b50485SHONG Yifan	    -I$(srctree)/tools/include/uapi \
546a77cff8SJosh Poimboeuf	    -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
556f8ca676SJulien Thierry	    -I$(srctree)/tools/arch/$(SRCARCH)/include	\
567786032eSVasily Gorbik	    -I$(srctree)/tools/objtool/include \
57bdb8bf7dSIan Rogers	    -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \
58bdb8bf7dSIan Rogers	    -I$(LIBSUBCMD_OUTPUT)/include
5931eca25fSJosh Poimboeuf
60*0d83da43SJosh PoimboeufOBJTOOL_CFLAGS  := -std=gnu11 -fomit-frame-pointer -O2 -g $(WARNINGS)	\
61*0d83da43SJosh Poimboeuf		   $(INCLUDES) $(LIBELF_FLAGS) $(LIBXXHASH_CFLAGS) $(HOSTCFLAGS)
6231eca25fSJosh Poimboeuf
63*0d83da43SJosh PoimboeufOBJTOOL_LDFLAGS := $(LIBSUBCMD) $(LIBELF_LIBS) $(LIBXXHASH_LIBS) $(HOSTLDFLAGS)
64442f04c3SJosh Poimboeuf
652e51f262SJan Beulich# Allow old libelf to be used:
66bf71940fSDavid Engrafelfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - 2>/dev/null | grep elf_getshdr)
67cd955bddSIan RogersOBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
68cd955bddSIan Rogers
69cd955bddSIan Rogers# Always want host compilation.
70cd955bddSIan RogersHOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)"
712e51f262SJan Beulich
72442f04c3SJosh PoimboeufAWK = awk
73bdb8bf7dSIan RogersMKDIR = mkdir
740decf1f8SMatt Helsley
7560cbdf5dSJosh Poimboeufexport srctree OUTPUT CFLAGS SRCARCH AWK
76442f04c3SJosh Poimboeufinclude $(srctree)/tools/build/Makefile.include
77442f04c3SJosh Poimboeuf
78cd955bddSIan Rogers$(OBJTOOL_IN): fixdep $(LIBSUBCMD) FORCE
798c4526caSIan Rogers	$(Q)$(CONFIG_SHELL) ./sync-check.sh
80cd955bddSIan Rogers	$(Q)$(MAKE) $(build)=objtool $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \
81cd955bddSIan Rogers		LDFLAGS="$(OBJTOOL_LDFLAGS)"
82cd955bddSIan Rogers
83442f04c3SJosh Poimboeuf
84442f04c3SJosh Poimboeuf$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
85cd955bddSIan Rogers	$(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(OBJTOOL_LDFLAGS) -o $@
86442f04c3SJosh Poimboeuf
87442f04c3SJosh Poimboeuf
88bdb8bf7dSIan Rogers$(LIBSUBCMD_OUTPUT):
898c4526caSIan Rogers	$(Q)$(MKDIR) -p $@
90442f04c3SJosh Poimboeuf
91bdb8bf7dSIan Rogers$(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE
928c4526caSIan Rogers	$(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
93bdb8bf7dSIan Rogers		DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \
94cd955bddSIan Rogers		$(HOST_OVERRIDES) EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \
95bdb8bf7dSIan Rogers		$@ install_headers
96bdb8bf7dSIan Rogers
97bdb8bf7dSIan Rogers$(LIBSUBCMD)-clean:
98bdb8bf7dSIan Rogers	$(call QUIET_CLEAN, libsubcmd)
99bdb8bf7dSIan Rogers	$(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT)
100bdb8bf7dSIan Rogers
101bdb8bf7dSIan Rogersclean: $(LIBSUBCMD)-clean
102442f04c3SJosh Poimboeuf	$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
103442f04c3SJosh Poimboeuf	$(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
104bdb8bf7dSIan Rogers	$(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
105442f04c3SJosh Poimboeuf
106442f04c3SJosh PoimboeufFORCE:
107442f04c3SJosh Poimboeuf
108442f04c3SJosh Poimboeuf.PHONY: clean FORCE
109