blob: ae0272f9a09184db54933fe079b9cf529bcf47d5 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Josh Poimboeuf442f04c2016-02-28 22:22:41 -06002include ../scripts/Makefile.include
Arnaldo Carvalho de Melo630e7a22016-07-22 09:59:24 -03003include ../scripts/Makefile.arch
Josh Poimboeuf442f04c2016-02-28 22:22:41 -06004
Josh Poimboeuf442f04c2016-02-28 22:22:41 -06005ifeq ($(ARCH),x86_64)
6ARCH := x86
7endif
Josh Poimboeuf442f04c2016-02-28 22:22:41 -06008
Josh Poimboeufc1d45c32016-03-02 18:39:37 -06009# always use the host compiler
Mikulas Patocka14c47b542017-12-02 16:17:44 -060010HOSTCC ?= gcc
11HOSTLD ?= ld
12CC = $(HOSTCC)
13LD = $(HOSTLD)
14AR = ar
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060015
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060016ifeq ($(srctree),)
Uwe Kleine-Könige19b7ce2016-11-22 09:30:26 +010017srctree := $(patsubst %/,%,$(dir $(CURDIR)))
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060018srctree := $(patsubst %/,%,$(dir $(srctree)))
19endif
20
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060021SUBCMD_SRCDIR = $(srctree)/tools/lib/subcmd/
Uwe Kleine-Könige19b7ce2016-11-22 09:30:26 +010022LIBSUBCMD_OUTPUT = $(if $(OUTPUT),$(OUTPUT),$(CURDIR)/)
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060023LIBSUBCMD = $(LIBSUBCMD_OUTPUT)libsubcmd.a
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060024
25OBJTOOL := $(OUTPUT)objtool
26OBJTOOL_IN := $(OBJTOOL)-in.o
27
28all: $(OBJTOOL)
29
Josh Poimboeuf6a77cff2017-11-06 07:21:50 -060030INCLUDES := -I$(srctree)/tools/include \
31 -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
Josh Poimboeuf9eb71982017-11-07 21:01:52 -060032 -I$(srctree)/tools/objtool/arch/$(ARCH)/include
Josh Poimboeuf21ec3bf2017-07-27 15:56:56 -050033WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed
34CFLAGS += -Wall -Werror $(WARNINGS) -fomit-frame-pointer -O2 -g $(INCLUDES)
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060035LDFLAGS += -lelf $(LIBSUBCMD)
36
Jan Beulich2e51f262016-05-16 15:31:07 -050037# Allow old libelf to be used:
38elfshdr := $(shell echo '\#include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
39CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
40
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060041AWK = awk
Josh Poimboeuf60cbdf52016-07-22 14:19:20 -050042export srctree OUTPUT CFLAGS SRCARCH AWK
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060043include $(srctree)/tools/build/Makefile.include
44
45$(OBJTOOL_IN): fixdep FORCE
46 @$(MAKE) $(build)=objtool
47
48$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
Josh Poimboeuf3bd51c52017-11-06 07:21:51 -060049 @./sync-check.sh
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060050 $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
51
52
53$(LIBSUBCMD): fixdep FORCE
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060054 $(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT)
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060055
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060056clean:
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060057 $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
58 $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
Josh Poimboeuf6a77cff2017-11-06 07:21:50 -060059 $(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060060
61FORCE:
62
63.PHONY: clean FORCE