Makefile 2.7 KB
Newer Older
1
# SPDX-License-Identifier: GPL-2.0
2
include ../scripts/Makefile.include
3
include ../scripts/Makefile.arch
4 5 6 7 8

ifeq ($(ARCH),x86_64)
ARCH := x86
endif

J
Josh Poimboeuf 已提交
9 10 11 12 13
# always use the host compiler
CC = gcc
LD = ld
AR = ar

14
ifeq ($(srctree),)
15
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
16 17 18
srctree := $(patsubst %/,%,$(dir $(srctree)))
endif

J
Josh Poimboeuf 已提交
19
SUBCMD_SRCDIR		= $(srctree)/tools/lib/subcmd/
20
LIBSUBCMD_OUTPUT	= $(if $(OUTPUT),$(OUTPUT),$(CURDIR)/)
J
Josh Poimboeuf 已提交
21
LIBSUBCMD		= $(LIBSUBCMD_OUTPUT)libsubcmd.a
22 23 24 25 26 27

OBJTOOL    := $(OUTPUT)objtool
OBJTOOL_IN := $(OBJTOOL)-in.o

all: $(OBJTOOL)

28 29 30
INCLUDES := -I$(srctree)/tools/include \
	    -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
	    -I$(srctree)/tools/objtool/arch/$(HOSTARCH)/include
31 32
WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed
CFLAGS   += -Wall -Werror $(WARNINGS) -fomit-frame-pointer -O2 -g $(INCLUDES)
33 34
LDFLAGS  += -lelf $(LIBSUBCMD)

35 36 37 38
# Allow old libelf to be used:
elfshdr := $(shell echo '\#include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)

39
AWK = awk
40
export srctree OUTPUT CFLAGS SRCARCH AWK
41 42 43 44 45
include $(srctree)/tools/build/Makefile.include

$(OBJTOOL_IN): fixdep FORCE
	@$(MAKE) $(build)=objtool

46 47
# Busybox's diff doesn't have -I, avoid warning in that case
#
48
$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
49 50
	@(diff -I 2>&1 | grep -q 'option requires an argument' && \
	test -d ../../kernel -a -d ../../tools -a -d ../objtool && (( \
51 52 53 54 55 56 57
	diff arch/x86/lib/insn.c ../../arch/x86/lib/insn.c >/dev/null && \
	diff arch/x86/lib/inat.c ../../arch/x86/lib/inat.c >/dev/null && \
	diff arch/x86/lib/x86-opcode-map.txt ../../arch/x86/lib/x86-opcode-map.txt >/dev/null && \
	diff arch/x86/tools/gen-insn-attr-x86.awk ../../arch/x86/tools/gen-insn-attr-x86.awk >/dev/null && \
	diff arch/x86/include/asm/insn.h ../../arch/x86/include/asm/insn.h >/dev/null && \
	diff arch/x86/include/asm/inat.h ../../arch/x86/include/asm/inat.h >/dev/null && \
	diff arch/x86/include/asm/inat_types.h ../../arch/x86/include/asm/inat_types.h >/dev/null) \
58
	|| echo "warning: objtool: x86 instruction decoder differs from kernel" >&2 )) || true
59
	@(test -d ../../kernel -a -d ../../tools -a -d ../objtool && (( \
60
	diff ../../arch/x86/include/asm/orc_types.h arch/x86/include/asm/orc_types.h >/dev/null) \
61
	|| echo "warning: objtool: orc_types.h differs from kernel" >&2 )) || true
62 63 64 65
	$(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@


$(LIBSUBCMD): fixdep FORCE
J
Josh Poimboeuf 已提交
66
	$(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT)
67

J
Josh Poimboeuf 已提交
68
clean:
69 70
	$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
	$(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
71
	$(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
72 73 74 75

FORCE:

.PHONY: clean FORCE