Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 1 | include ../scripts/Makefile.include |
Arnaldo Carvalho de Melo | 630e7a2 | 2016-07-22 09:59:24 -0300 | [diff] [blame] | 2 | include ../scripts/Makefile.arch |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 3 | |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 4 | ifeq ($(ARCH),x86_64) |
| 5 | ARCH := x86 |
| 6 | endif |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 7 | |
Josh Poimboeuf | c1d45c3 | 2016-03-02 18:39:37 -0600 | [diff] [blame] | 8 | # always use the host compiler |
| 9 | CC = gcc |
| 10 | LD = ld |
| 11 | AR = ar |
| 12 | |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 13 | ifeq ($(srctree),) |
Uwe Kleine-König | e19b7ce | 2016-11-22 09:30:26 +0100 | [diff] [blame] | 14 | srctree := $(patsubst %/,%,$(dir $(CURDIR))) |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 15 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 16 | endif |
| 17 | |
Josh Poimboeuf | c1d45c3 | 2016-03-02 18:39:37 -0600 | [diff] [blame] | 18 | SUBCMD_SRCDIR = $(srctree)/tools/lib/subcmd/ |
Uwe Kleine-König | e19b7ce | 2016-11-22 09:30:26 +0100 | [diff] [blame] | 19 | LIBSUBCMD_OUTPUT = $(if $(OUTPUT),$(OUTPUT),$(CURDIR)/) |
Josh Poimboeuf | c1d45c3 | 2016-03-02 18:39:37 -0600 | [diff] [blame] | 20 | LIBSUBCMD = $(LIBSUBCMD_OUTPUT)libsubcmd.a |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 21 | |
| 22 | OBJTOOL := $(OUTPUT)objtool |
| 23 | OBJTOOL_IN := $(OBJTOOL)-in.o |
| 24 | |
| 25 | all: $(OBJTOOL) |
| 26 | |
Arnaldo Carvalho de Melo | 0cf6eb6 | 2016-07-22 16:28:46 -0300 | [diff] [blame] | 27 | INCLUDES := -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi |
Josh Poimboeuf | d435fb5 | 2016-03-09 00:06:53 -0600 | [diff] [blame] | 28 | CFLAGS += -Wall -Werror $(EXTRA_WARNINGS) -fomit-frame-pointer -O2 -g $(INCLUDES) |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 29 | LDFLAGS += -lelf $(LIBSUBCMD) |
| 30 | |
Jan Beulich | 2e51f26 | 2016-05-16 15:31:07 -0500 | [diff] [blame] | 31 | # Allow old libelf to be used: |
| 32 | elfshdr := $(shell echo '\#include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr) |
| 33 | CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED) |
| 34 | |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 35 | AWK = awk |
Josh Poimboeuf | 60cbdf5 | 2016-07-22 14:19:20 -0500 | [diff] [blame] | 36 | export srctree OUTPUT CFLAGS SRCARCH AWK |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 37 | include $(srctree)/tools/build/Makefile.include |
| 38 | |
| 39 | $(OBJTOOL_IN): fixdep FORCE |
| 40 | @$(MAKE) $(build)=objtool |
| 41 | |
Arnaldo Carvalho de Melo | 1a4bf28 | 2016-07-13 15:33:54 -0300 | [diff] [blame] | 42 | # Busybox's diff doesn't have -I, avoid warning in that case |
| 43 | # |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 44 | $(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN) |
Arnaldo Carvalho de Melo | 1a4bf28 | 2016-07-13 15:33:54 -0300 | [diff] [blame] | 45 | @(diff -I 2>&1 | grep -q 'option requires an argument' && \ |
| 46 | test -d ../../kernel -a -d ../../tools -a -d ../objtool && (( \ |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 47 | diff -I'^#include' arch/x86/insn/insn.c ../../arch/x86/lib/insn.c >/dev/null && \ |
| 48 | diff -I'^#include' arch/x86/insn/inat.c ../../arch/x86/lib/inat.c >/dev/null && \ |
| 49 | diff arch/x86/insn/x86-opcode-map.txt ../../arch/x86/lib/x86-opcode-map.txt >/dev/null && \ |
| 50 | diff arch/x86/insn/gen-insn-attr-x86.awk ../../arch/x86/tools/gen-insn-attr-x86.awk >/dev/null && \ |
| 51 | diff -I'^#include' arch/x86/insn/insn.h ../../arch/x86/include/asm/insn.h >/dev/null && \ |
| 52 | diff -I'^#include' arch/x86/insn/inat.h ../../arch/x86/include/asm/inat.h >/dev/null && \ |
| 53 | diff -I'^#include' arch/x86/insn/inat_types.h ../../arch/x86/include/asm/inat_types.h >/dev/null) \ |
Josh Poimboeuf | 2af04ea | 2016-07-28 19:15:00 -0500 | [diff] [blame] | 54 | || echo "warning: objtool: x86 instruction decoder differs from kernel" >&2 )) || true |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 55 | $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@ |
| 56 | |
| 57 | |
| 58 | $(LIBSUBCMD): fixdep FORCE |
Josh Poimboeuf | c1d45c3 | 2016-03-02 18:39:37 -0600 | [diff] [blame] | 59 | $(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT) |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 60 | |
Josh Poimboeuf | c1d45c3 | 2016-03-02 18:39:37 -0600 | [diff] [blame] | 61 | clean: |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 62 | $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL) |
| 63 | $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete |
| 64 | $(Q)$(RM) $(OUTPUT)arch/x86/insn/inat-tables.c $(OUTPUT)fixdep |
| 65 | |
| 66 | FORCE: |
| 67 | |
| 68 | .PHONY: clean FORCE |