Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 1 | include ../scripts/Makefile.include |
| 2 | |
| 3 | ifndef ($(ARCH)) |
| 4 | ARCH ?= $(shell uname -m) |
| 5 | ifeq ($(ARCH),x86_64) |
| 6 | ARCH := x86 |
| 7 | endif |
| 8 | endif |
| 9 | |
Josh Poimboeuf | c1d45c3 | 2016-03-02 18:39:37 -0600 | [diff] [blame] | 10 | # always use the host compiler |
| 11 | CC = gcc |
| 12 | LD = ld |
| 13 | AR = ar |
| 14 | |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 15 | ifeq ($(srctree),) |
| 16 | srctree := $(patsubst %/,%,$(dir $(shell pwd))) |
| 17 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 18 | endif |
| 19 | |
Josh Poimboeuf | c1d45c3 | 2016-03-02 18:39:37 -0600 | [diff] [blame] | 20 | SUBCMD_SRCDIR = $(srctree)/tools/lib/subcmd/ |
| 21 | LIBSUBCMD_OUTPUT = $(if $(OUTPUT),$(OUTPUT),$(PWD)/) |
| 22 | LIBSUBCMD = $(LIBSUBCMD_OUTPUT)libsubcmd.a |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 23 | |
| 24 | OBJTOOL := $(OUTPUT)objtool |
| 25 | OBJTOOL_IN := $(OBJTOOL)-in.o |
| 26 | |
| 27 | all: $(OBJTOOL) |
| 28 | |
| 29 | INCLUDES := -I$(srctree)/tools/include |
Josh Poimboeuf | d435fb5 | 2016-03-09 00:06:53 -0600 | [diff] [blame] | 30 | CFLAGS += -Wall -Werror $(EXTRA_WARNINGS) -fomit-frame-pointer -O2 -g $(INCLUDES) |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 31 | LDFLAGS += -lelf $(LIBSUBCMD) |
| 32 | |
| 33 | AWK = awk |
| 34 | export srctree OUTPUT CFLAGS ARCH AWK |
| 35 | include $(srctree)/tools/build/Makefile.include |
| 36 | |
| 37 | $(OBJTOOL_IN): fixdep FORCE |
| 38 | @$(MAKE) $(build)=objtool |
| 39 | |
| 40 | $(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN) |
| 41 | @(test -d ../../kernel -a -d ../../tools -a -d ../objtool && (( \ |
| 42 | diff -I'^#include' arch/x86/insn/insn.c ../../arch/x86/lib/insn.c >/dev/null && \ |
| 43 | diff -I'^#include' arch/x86/insn/inat.c ../../arch/x86/lib/inat.c >/dev/null && \ |
| 44 | diff arch/x86/insn/x86-opcode-map.txt ../../arch/x86/lib/x86-opcode-map.txt >/dev/null && \ |
| 45 | diff arch/x86/insn/gen-insn-attr-x86.awk ../../arch/x86/tools/gen-insn-attr-x86.awk >/dev/null && \ |
| 46 | diff -I'^#include' arch/x86/insn/insn.h ../../arch/x86/include/asm/insn.h >/dev/null && \ |
| 47 | diff -I'^#include' arch/x86/insn/inat.h ../../arch/x86/include/asm/inat.h >/dev/null && \ |
| 48 | diff -I'^#include' arch/x86/insn/inat_types.h ../../arch/x86/include/asm/inat_types.h >/dev/null) \ |
| 49 | || echo "Warning: objtool: x86 instruction decoder differs from kernel" >&2 )) || true |
| 50 | $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@ |
| 51 | |
| 52 | |
| 53 | $(LIBSUBCMD): fixdep FORCE |
Josh Poimboeuf | c1d45c3 | 2016-03-02 18:39:37 -0600 | [diff] [blame] | 54 | $(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT) |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 55 | |
Josh Poimboeuf | c1d45c3 | 2016-03-02 18:39:37 -0600 | [diff] [blame] | 56 | clean: |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 57 | $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL) |
| 58 | $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete |
| 59 | $(Q)$(RM) $(OUTPUT)arch/x86/insn/inat-tables.c $(OUTPUT)fixdep |
| 60 | |
| 61 | FORCE: |
| 62 | |
| 63 | .PHONY: clean FORCE |