Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 2 | include ../scripts/Makefile.include |
Arnaldo Carvalho de Melo | 630e7a2 | 2016-07-22 09:59:24 -0300 | [diff] [blame] | 3 | include ../scripts/Makefile.arch |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 4 | |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 5 | ifeq ($(ARCH),x86_64) |
| 6 | ARCH := x86 |
| 7 | endif |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 8 | |
Josh Poimboeuf | c1d45c3 | 2016-03-02 18:39:37 -0600 | [diff] [blame] | 9 | # always use the host compiler |
| 10 | CC = gcc |
| 11 | LD = ld |
| 12 | AR = ar |
| 13 | |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 14 | ifeq ($(srctree),) |
Uwe Kleine-König | e19b7ce | 2016-11-22 09:30:26 +0100 | [diff] [blame] | 15 | srctree := $(patsubst %/,%,$(dir $(CURDIR))) |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 16 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 17 | endif |
| 18 | |
Josh Poimboeuf | c1d45c3 | 2016-03-02 18:39:37 -0600 | [diff] [blame] | 19 | SUBCMD_SRCDIR = $(srctree)/tools/lib/subcmd/ |
Uwe Kleine-König | e19b7ce | 2016-11-22 09:30:26 +0100 | [diff] [blame] | 20 | LIBSUBCMD_OUTPUT = $(if $(OUTPUT),$(OUTPUT),$(CURDIR)/) |
Josh Poimboeuf | c1d45c3 | 2016-03-02 18:39:37 -0600 | [diff] [blame] | 21 | LIBSUBCMD = $(LIBSUBCMD_OUTPUT)libsubcmd.a |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 22 | |
| 23 | OBJTOOL := $(OUTPUT)objtool |
| 24 | OBJTOOL_IN := $(OBJTOOL)-in.o |
| 25 | |
| 26 | all: $(OBJTOOL) |
| 27 | |
Arnaldo Carvalho de Melo | 0cf6eb6 | 2016-07-22 16:28:46 -0300 | [diff] [blame] | 28 | INCLUDES := -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi |
Josh Poimboeuf | 21ec3bf | 2017-07-27 15:56:56 -0500 | [diff] [blame] | 29 | WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed |
| 30 | CFLAGS += -Wall -Werror $(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 |
Josh Poimboeuf | 60cbdf5 | 2016-07-22 14:19:20 -0500 | [diff] [blame] | 38 | export srctree OUTPUT CFLAGS SRCARCH AWK |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 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) \ |
Josh Poimboeuf | 2af04ea | 2016-07-28 19:15:00 -0500 | [diff] [blame] | 56 | || echo "warning: objtool: x86 instruction decoder differs from kernel" >&2 )) || true |
Josh Poimboeuf | 39358a0 | 2017-07-11 10:33:43 -0500 | [diff] [blame] | 57 | @(test -d ../../kernel -a -d ../../tools -a -d ../objtool && (( \ |
| 58 | diff ../../arch/x86/include/asm/orc_types.h orc_types.h >/dev/null) \ |
| 59 | || echo "warning: objtool: orc_types.h differs from kernel" >&2 )) || true |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 60 | $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@ |
| 61 | |
| 62 | |
| 63 | $(LIBSUBCMD): fixdep FORCE |
Josh Poimboeuf | c1d45c3 | 2016-03-02 18:39:37 -0600 | [diff] [blame] | 64 | $(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT) |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 65 | |
Josh Poimboeuf | c1d45c3 | 2016-03-02 18:39:37 -0600 | [diff] [blame] | 66 | clean: |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 67 | $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL) |
| 68 | $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete |
| 69 | $(Q)$(RM) $(OUTPUT)arch/x86/insn/inat-tables.c $(OUTPUT)fixdep |
| 70 | |
| 71 | FORCE: |
| 72 | |
| 73 | .PHONY: clean FORCE |