blob: 6976c73e60c444b50320adfc081ecd6beaec681f [file] [log] [blame]
Josh Poimboeuf442f04c2016-02-28 22:22:41 -06001include ../scripts/Makefile.include
Arnaldo Carvalho de Melo630e7a22016-07-22 09:59:24 -03002include ../scripts/Makefile.arch
Josh Poimboeuf442f04c2016-02-28 22:22:41 -06003
Josh Poimboeuf442f04c2016-02-28 22:22:41 -06004ifeq ($(ARCH),x86_64)
5ARCH := x86
6endif
Josh Poimboeuf442f04c2016-02-28 22:22:41 -06007
Josh Poimboeufc1d45c32016-03-02 18:39:37 -06008# always use the host compiler
9CC = gcc
10LD = ld
11AR = ar
12
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060013ifeq ($(srctree),)
Uwe Kleine-Könige19b7ce2016-11-22 09:30:26 +010014srctree := $(patsubst %/,%,$(dir $(CURDIR)))
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060015srctree := $(patsubst %/,%,$(dir $(srctree)))
16endif
17
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060018SUBCMD_SRCDIR = $(srctree)/tools/lib/subcmd/
Uwe Kleine-Könige19b7ce2016-11-22 09:30:26 +010019LIBSUBCMD_OUTPUT = $(if $(OUTPUT),$(OUTPUT),$(CURDIR)/)
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060020LIBSUBCMD = $(LIBSUBCMD_OUTPUT)libsubcmd.a
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060021
22OBJTOOL := $(OUTPUT)objtool
23OBJTOOL_IN := $(OBJTOOL)-in.o
24
25all: $(OBJTOOL)
26
Arnaldo Carvalho de Melo0cf6eb62016-07-22 16:28:46 -030027INCLUDES := -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi
Josh Poimboeuf21ec3bf2017-07-27 15:56:56 -050028WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed
29CFLAGS += -Wall -Werror $(WARNINGS) -fomit-frame-pointer -O2 -g $(INCLUDES)
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060030LDFLAGS += -lelf $(LIBSUBCMD)
31
Jan Beulich2e51f262016-05-16 15:31:07 -050032# Allow old libelf to be used:
33elfshdr := $(shell echo '\#include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
34CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
35
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060036AWK = awk
Josh Poimboeuf60cbdf52016-07-22 14:19:20 -050037export srctree OUTPUT CFLAGS SRCARCH AWK
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060038include $(srctree)/tools/build/Makefile.include
39
40$(OBJTOOL_IN): fixdep FORCE
41 @$(MAKE) $(build)=objtool
42
Arnaldo Carvalho de Melo1a4bf282016-07-13 15:33:54 -030043# Busybox's diff doesn't have -I, avoid warning in that case
44#
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060045$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
Arnaldo Carvalho de Melo1a4bf282016-07-13 15:33:54 -030046 @(diff -I 2>&1 | grep -q 'option requires an argument' && \
47 test -d ../../kernel -a -d ../../tools -a -d ../objtool && (( \
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060048 diff -I'^#include' arch/x86/insn/insn.c ../../arch/x86/lib/insn.c >/dev/null && \
49 diff -I'^#include' arch/x86/insn/inat.c ../../arch/x86/lib/inat.c >/dev/null && \
50 diff arch/x86/insn/x86-opcode-map.txt ../../arch/x86/lib/x86-opcode-map.txt >/dev/null && \
51 diff arch/x86/insn/gen-insn-attr-x86.awk ../../arch/x86/tools/gen-insn-attr-x86.awk >/dev/null && \
52 diff -I'^#include' arch/x86/insn/insn.h ../../arch/x86/include/asm/insn.h >/dev/null && \
53 diff -I'^#include' arch/x86/insn/inat.h ../../arch/x86/include/asm/inat.h >/dev/null && \
54 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 -050055 || echo "warning: objtool: x86 instruction decoder differs from kernel" >&2 )) || true
Josh Poimboeuf39358a02017-07-11 10:33:43 -050056 @(test -d ../../kernel -a -d ../../tools -a -d ../objtool && (( \
57 diff ../../arch/x86/include/asm/orc_types.h orc_types.h >/dev/null) \
58 || echo "warning: objtool: orc_types.h differs from kernel" >&2 )) || true
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060059 $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
60
61
62$(LIBSUBCMD): fixdep FORCE
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060063 $(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT)
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060064
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060065clean:
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060066 $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
67 $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
68 $(Q)$(RM) $(OUTPUT)arch/x86/insn/inat-tables.c $(OUTPUT)fixdep
69
70FORCE:
71
72.PHONY: clean FORCE