xref: /linux/tools/objtool/Makefile (revision ae22a94997b8a03dcb3c922857c203246711f9d4)
1# SPDX-License-Identifier: GPL-2.0
2include ../scripts/Makefile.include
3include ../scripts/Makefile.arch
4
5ifeq ($(srctree),)
6srctree := $(patsubst %/,%,$(dir $(CURDIR)))
7srctree := $(patsubst %/,%,$(dir $(srctree)))
8endif
9
10LIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/
11ifneq ($(OUTPUT),)
12  LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd
13else
14  LIBSUBCMD_OUTPUT = $(CURDIR)/libsubcmd
15endif
16LIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a
17
18OBJTOOL    := $(OUTPUT)objtool
19OBJTOOL_IN := $(OBJTOOL)-in.o
20
21LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null)
22LIBELF_LIBS  := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)
23
24all: $(OBJTOOL)
25
26INCLUDES := -I$(srctree)/tools/include \
27	    -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
28	    -I$(srctree)/tools/arch/$(SRCARCH)/include	\
29	    -I$(srctree)/tools/objtool/include \
30	    -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \
31	    -I$(LIBSUBCMD_OUTPUT)/include
32# Note, EXTRA_WARNINGS here was determined for CC and not HOSTCC, it
33# is passed here to match a legacy behavior.
34WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
35OBJTOOL_CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
36OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
37
38# Allow old libelf to be used:
39elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - | grep elf_getshdr)
40OBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
41
42# Always want host compilation.
43HOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)"
44
45AWK = awk
46MKDIR = mkdir
47
48ifeq ($(V),1)
49  Q =
50else
51  Q = @
52endif
53
54BUILD_ORC := n
55
56ifeq ($(SRCARCH),x86)
57	BUILD_ORC := y
58endif
59
60ifeq ($(SRCARCH),loongarch)
61	BUILD_ORC := y
62endif
63
64export BUILD_ORC
65export srctree OUTPUT CFLAGS SRCARCH AWK
66include $(srctree)/tools/build/Makefile.include
67
68$(OBJTOOL_IN): fixdep $(LIBSUBCMD) FORCE
69	$(Q)$(CONFIG_SHELL) ./sync-check.sh
70	$(Q)$(MAKE) $(build)=objtool $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \
71		LDFLAGS="$(OBJTOOL_LDFLAGS)"
72
73
74$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
75	$(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(OBJTOOL_LDFLAGS) -o $@
76
77
78$(LIBSUBCMD_OUTPUT):
79	$(Q)$(MKDIR) -p $@
80
81$(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE
82	$(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
83		DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \
84		$(HOST_OVERRIDES) EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \
85		$@ install_headers
86
87$(LIBSUBCMD)-clean:
88	$(call QUIET_CLEAN, libsubcmd)
89	$(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT)
90
91clean: $(LIBSUBCMD)-clean
92	$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
93	$(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
94	$(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
95
96FORCE:
97
98.PHONY: clean FORCE
99