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 | |
Jan Beulich | 2e51f26 | 2016-05-16 15:31:07 -0500 | [diff] [blame] | 33 | # Allow old libelf to be used: |
| 34 | elfshdr := $(shell echo '\#include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr) |
| 35 | CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED) |
| 36 | |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 37 | AWK = awk |
| 38 | export srctree OUTPUT CFLAGS ARCH AWK |
| 39 | include $(srctree)/tools/build/Makefile.include |
| 40 | |
| 41 | $(OBJTOOL_IN): fixdep FORCE |
| 42 | @$(MAKE) $(build)=objtool |
| 43 | |
Arnaldo Carvalho de Melo | 1a4bf28 | 2016-07-13 15:33:54 -0300 | [diff] [blame^] | 44 | # Busybox's diff doesn't have -I, avoid warning in that case |
| 45 | # |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 46 | $(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN) |
Arnaldo Carvalho de Melo | 1a4bf28 | 2016-07-13 15:33:54 -0300 | [diff] [blame^] | 47 | @(diff -I 2>&1 | grep -q 'option requires an argument' && \ |
| 48 | test -d ../../kernel -a -d ../../tools -a -d ../objtool && (( \ |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 49 | 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 Poimboeuf | c1d45c3 | 2016-03-02 18:39:37 -0600 | [diff] [blame] | 61 | $(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT) |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 62 | |
Josh Poimboeuf | c1d45c3 | 2016-03-02 18:39:37 -0600 | [diff] [blame] | 63 | clean: |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 64 | $(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 | |
| 68 | FORCE: |
| 69 | |
| 70 | .PHONY: clean FORCE |