xref: /linux-6.15/tools/objtool/Makefile (revision 6a77cff8)
1# SPDX-License-Identifier: GPL-2.0
2include ../scripts/Makefile.include
3include ../scripts/Makefile.arch
4
5ifeq ($(ARCH),x86_64)
6ARCH := x86
7endif
8
9# always use the host compiler
10CC = gcc
11LD = ld
12AR = ar
13
14ifeq ($(srctree),)
15srctree := $(patsubst %/,%,$(dir $(CURDIR)))
16srctree := $(patsubst %/,%,$(dir $(srctree)))
17endif
18
19SUBCMD_SRCDIR		= $(srctree)/tools/lib/subcmd/
20LIBSUBCMD_OUTPUT	= $(if $(OUTPUT),$(OUTPUT),$(CURDIR)/)
21LIBSUBCMD		= $(LIBSUBCMD_OUTPUT)libsubcmd.a
22
23OBJTOOL    := $(OUTPUT)objtool
24OBJTOOL_IN := $(OBJTOOL)-in.o
25
26all: $(OBJTOOL)
27
28INCLUDES := -I$(srctree)/tools/include \
29	    -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
30	    -I$(srctree)/tools/objtool/arch/$(HOSTARCH)/include
31WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed
32CFLAGS   += -Wall -Werror $(WARNINGS) -fomit-frame-pointer -O2 -g $(INCLUDES)
33LDFLAGS  += -lelf $(LIBSUBCMD)
34
35# Allow old libelf to be used:
36elfshdr := $(shell echo '\#include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
37CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
38
39AWK = awk
40export srctree OUTPUT CFLAGS SRCARCH AWK
41include $(srctree)/tools/build/Makefile.include
42
43$(OBJTOOL_IN): fixdep FORCE
44	@$(MAKE) $(build)=objtool
45
46# Busybox's diff doesn't have -I, avoid warning in that case
47#
48$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
49	@(diff -I 2>&1 | grep -q 'option requires an argument' && \
50	test -d ../../kernel -a -d ../../tools -a -d ../objtool && (( \
51	diff arch/x86/lib/insn.c ../../arch/x86/lib/insn.c >/dev/null && \
52	diff arch/x86/lib/inat.c ../../arch/x86/lib/inat.c >/dev/null && \
53	diff arch/x86/lib/x86-opcode-map.txt ../../arch/x86/lib/x86-opcode-map.txt >/dev/null && \
54	diff arch/x86/tools/gen-insn-attr-x86.awk ../../arch/x86/tools/gen-insn-attr-x86.awk >/dev/null && \
55	diff arch/x86/include/asm/insn.h ../../arch/x86/include/asm/insn.h >/dev/null && \
56	diff arch/x86/include/asm/inat.h ../../arch/x86/include/asm/inat.h >/dev/null && \
57	diff arch/x86/include/asm/inat_types.h ../../arch/x86/include/asm/inat_types.h >/dev/null) \
58	|| echo "warning: objtool: x86 instruction decoder differs from kernel" >&2 )) || true
59	@(test -d ../../kernel -a -d ../../tools -a -d ../objtool && (( \
60	diff ../../arch/x86/include/asm/orc_types.h arch/x86/include/asm/orc_types.h >/dev/null) \
61	|| echo "warning: objtool: orc_types.h differs from kernel" >&2 )) || true
62	$(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
63
64
65$(LIBSUBCMD): fixdep FORCE
66	$(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT)
67
68clean:
69	$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
70	$(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
71	$(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
72
73FORCE:
74
75.PHONY: clean FORCE
76