blob: 424b1965d06f2f95d701d19284cc0f3f7e6e82ea [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Josh Poimboeuf442f04c2016-02-28 22:22:41 -06002include ../scripts/Makefile.include
Arnaldo Carvalho de Melo630e7a22016-07-22 09:59:24 -03003include ../scripts/Makefile.arch
Josh Poimboeuf442f04c2016-02-28 22:22:41 -06004
Josh Poimboeuf442f04c2016-02-28 22:22:41 -06005ifeq ($(ARCH),x86_64)
6ARCH := x86
7endif
Josh Poimboeuf442f04c2016-02-28 22:22:41 -06008
Josh Poimboeufc1d45c32016-03-02 18:39:37 -06009# always use the host compiler
10CC = gcc
11LD = ld
12AR = ar
13
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060014ifeq ($(srctree),)
Uwe Kleine-Könige19b7ce2016-11-22 09:30:26 +010015srctree := $(patsubst %/,%,$(dir $(CURDIR)))
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060016srctree := $(patsubst %/,%,$(dir $(srctree)))
17endif
18
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060019SUBCMD_SRCDIR = $(srctree)/tools/lib/subcmd/
Uwe Kleine-Könige19b7ce2016-11-22 09:30:26 +010020LIBSUBCMD_OUTPUT = $(if $(OUTPUT),$(OUTPUT),$(CURDIR)/)
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060021LIBSUBCMD = $(LIBSUBCMD_OUTPUT)libsubcmd.a
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060022
23OBJTOOL := $(OUTPUT)objtool
24OBJTOOL_IN := $(OBJTOOL)-in.o
25
26all: $(OBJTOOL)
27
Arnaldo Carvalho de Melo0cf6eb62016-07-22 16:28:46 -030028INCLUDES := -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi
Josh Poimboeuf21ec3bf2017-07-27 15:56:56 -050029WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed
30CFLAGS += -Wall -Werror $(WARNINGS) -fomit-frame-pointer -O2 -g $(INCLUDES)
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060031LDFLAGS += -lelf $(LIBSUBCMD)
32
Jan Beulich2e51f262016-05-16 15:31:07 -050033# Allow old libelf to be used:
34elfshdr := $(shell echo '\#include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
35CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
36
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060037AWK = awk
Josh Poimboeuf60cbdf52016-07-22 14:19:20 -050038export srctree OUTPUT CFLAGS SRCARCH AWK
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060039include $(srctree)/tools/build/Makefile.include
40
41$(OBJTOOL_IN): fixdep FORCE
42 @$(MAKE) $(build)=objtool
43
Arnaldo Carvalho de Melo1a4bf282016-07-13 15:33:54 -030044# Busybox's diff doesn't have -I, avoid warning in that case
45#
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060046$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
Arnaldo Carvalho de Melo1a4bf282016-07-13 15:33:54 -030047 @(diff -I 2>&1 | grep -q 'option requires an argument' && \
48 test -d ../../kernel -a -d ../../tools -a -d ../objtool && (( \
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060049 diff -I'^#include' arch/x86/insn/insn.c ../../arch/x86/lib/insn.c >/dev/null && \
50 diff -I'^#include' arch/x86/insn/inat.c ../../arch/x86/lib/inat.c >/dev/null && \
51 diff arch/x86/insn/x86-opcode-map.txt ../../arch/x86/lib/x86-opcode-map.txt >/dev/null && \
52 diff arch/x86/insn/gen-insn-attr-x86.awk ../../arch/x86/tools/gen-insn-attr-x86.awk >/dev/null && \
53 diff -I'^#include' arch/x86/insn/insn.h ../../arch/x86/include/asm/insn.h >/dev/null && \
54 diff -I'^#include' arch/x86/insn/inat.h ../../arch/x86/include/asm/inat.h >/dev/null && \
55 diff -I'^#include' arch/x86/insn/inat_types.h ../../arch/x86/include/asm/inat_types.h >/dev/null) \
Josh Poimboeuf2af04ea2016-07-28 19:15:00 -050056 || echo "warning: objtool: x86 instruction decoder differs from kernel" >&2 )) || true
Josh Poimboeuf39358a02017-07-11 10:33:43 -050057 @(test -d ../../kernel -a -d ../../tools -a -d ../objtool && (( \
58 diff ../../arch/x86/include/asm/orc_types.h orc_types.h >/dev/null) \
59 || echo "warning: objtool: orc_types.h differs from kernel" >&2 )) || true
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060060 $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
61
62
63$(LIBSUBCMD): fixdep FORCE
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060064 $(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT)
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060065
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060066clean:
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060067 $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
68 $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
69 $(Q)$(RM) $(OUTPUT)arch/x86/insn/inat-tables.c $(OUTPUT)fixdep
70
71FORCE:
72
73.PHONY: clean FORCE