blob: 8ae824dbfca3fea24889064aca1fd46d60f0cbf2 [file] [log] [blame]
Greg Kroah-Hartmanb790b4f2018-06-03 12:35:15 +02001# 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
Greg Kroah-Hartmanb790b4f2018-06-03 12:35:15 +020010HOSTCC ?= 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),)
Greg Kroah-Hartmanb790b4f2018-06-03 12:35:15 +020017srctree := $(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/
Greg Kroah-Hartmanb790b4f2018-06-03 12:35:15 +020022LIBSUBCMD_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
Greg Kroah-Hartmanb790b4f2018-06-03 12:35:15 +020030INCLUDES := -I$(srctree)/tools/include \
31 -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
32 -I$(srctree)/tools/objtool/arch/$(ARCH)/include
33WARNINGS := $(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:
Rasmus Villemoesb5d7d7d2018-04-08 23:35:28 +020038elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
Jan Beulich2e51f262016-05-16 15:31:07 -050039CFLAGS += $(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)
Greg Kroah-Hartmanb790b4f2018-06-03 12:35:15 +020049 @$(CONFIG_SHELL) ./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
Greg Kroah-Hartmanb790b4f2018-06-03 12:35:15 +020059 $(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