blob: 9a3110cac6040e41250e1d87b533494b7acd3b57 [file] [log] [blame]
Josh Poimboeuf442f04c2016-02-28 22:22:41 -06001include ../scripts/Makefile.include
2
3ifndef ($(ARCH))
4ARCH ?= $(shell uname -m)
5ifeq ($(ARCH),x86_64)
6ARCH := x86
7endif
8endif
9
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060010# always use the host compiler
11CC = gcc
12LD = ld
13AR = ar
14
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060015ifeq ($(srctree),)
16srctree := $(patsubst %/,%,$(dir $(shell pwd)))
17srctree := $(patsubst %/,%,$(dir $(srctree)))
18endif
19
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060020SUBCMD_SRCDIR = $(srctree)/tools/lib/subcmd/
21LIBSUBCMD_OUTPUT = $(if $(OUTPUT),$(OUTPUT),$(PWD)/)
22LIBSUBCMD = $(LIBSUBCMD_OUTPUT)libsubcmd.a
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060023
24OBJTOOL := $(OUTPUT)objtool
25OBJTOOL_IN := $(OBJTOOL)-in.o
26
27all: $(OBJTOOL)
28
29INCLUDES := -I$(srctree)/tools/include
Josh Poimboeufd435fb52016-03-09 00:06:53 -060030CFLAGS += -Wall -Werror $(EXTRA_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
38export srctree OUTPUT CFLAGS ARCH AWK
39include $(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) \
56 || echo "Warning: objtool: x86 instruction decoder differs from kernel" >&2 )) || true
57 $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
58
59
60$(LIBSUBCMD): fixdep FORCE
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060061 $(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT)
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060062
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060063clean:
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060064 $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
65 $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
66 $(Q)$(RM) $(OUTPUT)arch/x86/insn/inat-tables.c $(OUTPUT)fixdep
67
68FORCE:
69
70.PHONY: clean FORCE