blob: 84756140a8a8ed5967f9e7830acf34e5b349c656 [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
Nathan Chancellor2bfc2e32019-05-16 12:49:42 -050010HOSTAR ?= ar
Greg Kroah-Hartmanb790b4f2018-06-03 12:35:15 +020011HOSTCC ?= gcc
12HOSTLD ?= ld
Nathan Chancellor2bfc2e32019-05-16 12:49:42 -050013AR = $(HOSTAR)
Greg Kroah-Hartmanb790b4f2018-06-03 12:35:15 +020014CC = $(HOSTCC)
15LD = $(HOSTLD)
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060016
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060017ifeq ($(srctree),)
Greg Kroah-Hartmanb790b4f2018-06-03 12:35:15 +020018srctree := $(patsubst %/,%,$(dir $(CURDIR)))
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060019srctree := $(patsubst %/,%,$(dir $(srctree)))
20endif
21
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060022SUBCMD_SRCDIR = $(srctree)/tools/lib/subcmd/
Greg Kroah-Hartmanb790b4f2018-06-03 12:35:15 +020023LIBSUBCMD_OUTPUT = $(if $(OUTPUT),$(OUTPUT),$(CURDIR)/)
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060024LIBSUBCMD = $(LIBSUBCMD_OUTPUT)libsubcmd.a
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060025
26OBJTOOL := $(OUTPUT)objtool
27OBJTOOL_IN := $(OBJTOOL)-in.o
28
29all: $(OBJTOOL)
30
Greg Kroah-Hartmanb790b4f2018-06-03 12:35:15 +020031INCLUDES := -I$(srctree)/tools/include \
32 -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
33 -I$(srctree)/tools/objtool/arch/$(ARCH)/include
34WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed
Josh Poimboeufcb40b5b2019-08-29 18:28:49 -050035CFLAGS := -Wall -Werror $(WARNINGS) -fomit-frame-pointer -O2 -g $(INCLUDES)
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060036LDFLAGS += -lelf $(LIBSUBCMD)
37
Jan Beulich2e51f262016-05-16 15:31:07 -050038# Allow old libelf to be used:
Rasmus Villemoesb5d7d7d2018-04-08 23:35:28 +020039elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
Jan Beulich2e51f262016-05-16 15:31:07 -050040CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
41
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060042AWK = awk
Josh Poimboeuf60cbdf52016-07-22 14:19:20 -050043export srctree OUTPUT CFLAGS SRCARCH AWK
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060044include $(srctree)/tools/build/Makefile.include
45
46$(OBJTOOL_IN): fixdep FORCE
47 @$(MAKE) $(build)=objtool
48
49$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
Greg Kroah-Hartmanb790b4f2018-06-03 12:35:15 +020050 @$(CONFIG_SHELL) ./sync-check.sh
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060051 $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
52
53
54$(LIBSUBCMD): fixdep FORCE
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060055 $(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT)
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060056
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060057clean:
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060058 $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
59 $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
Greg Kroah-Hartmanb790b4f2018-06-03 12:35:15 +020060 $(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060061
62FORCE:
63
64.PHONY: clean FORCE