blob: 92ce4fce7bc7301ca603e088478c9b6d65c1e42f [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 Poimboeufc1d45c32016-03-02 18:39:37 -06005# always use the host compiler
Nathan Chancellor8ea58f12019-05-16 12:49:42 -05006AR = $(HOSTAR)
Mikulas Patocka14c47b542017-12-02 16:17:44 -06007CC = $(HOSTCC)
8LD = $(HOSTLD)
Josh Poimboeufc1d45c32016-03-02 18:39:37 -06009
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060010ifeq ($(srctree),)
Uwe Kleine-Könige19b7ce2016-11-22 09:30:26 +010011srctree := $(patsubst %/,%,$(dir $(CURDIR)))
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060012srctree := $(patsubst %/,%,$(dir $(srctree)))
13endif
14
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060015SUBCMD_SRCDIR = $(srctree)/tools/lib/subcmd/
Uwe Kleine-Könige19b7ce2016-11-22 09:30:26 +010016LIBSUBCMD_OUTPUT = $(if $(OUTPUT),$(OUTPUT),$(CURDIR)/)
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060017LIBSUBCMD = $(LIBSUBCMD_OUTPUT)libsubcmd.a
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060018
19OBJTOOL := $(OUTPUT)objtool
20OBJTOOL_IN := $(OBJTOOL)-in.o
21
Rolf Eike Beer056d28d2019-03-26 12:48:39 -050022LIBELF_FLAGS := $(shell pkg-config libelf --cflags 2>/dev/null)
23LIBELF_LIBS := $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf)
24
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060025all: $(OBJTOOL)
26
Josh Poimboeuf6a77cff2017-11-06 07:21:50 -060027INCLUDES := -I$(srctree)/tools/include \
28 -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
Julien Thierry6f8ca672020-03-27 15:28:46 +000029 -I$(srctree)/tools/arch/$(SRCARCH)/include \
Vasily Gorbik77860322020-11-13 00:03:32 +010030 -I$(srctree)/tools/objtool/include \
Julien Thierry6f8ca672020-03-27 15:28:46 +000031 -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include
Vasily Gorbik2486baa2020-10-05 17:50:28 +020032WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
Josh Poimboeuff73b3cc2019-08-29 18:28:49 -050033CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
Rolf Eike Beer056d28d2019-03-26 12:48:39 -050034LDFLAGS += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060035
Jan Beulich2e51f262016-05-16 15:31:07 -050036# Allow old libelf to be used:
Rasmus Villemoes9564a8c2018-04-08 23:35:28 +020037elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
Jan Beulich2e51f262016-05-16 15:31:07 -050038CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
39
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060040AWK = awk
Matt Helsley0decf1f2020-05-19 13:55:33 -070041
42SUBCMD_CHECK := n
43SUBCMD_ORC := n
44
45ifeq ($(SRCARCH),x86)
46 SUBCMD_CHECK := y
47 SUBCMD_ORC := y
48endif
49
50export SUBCMD_CHECK SUBCMD_ORC
Josh Poimboeuf60cbdf52016-07-22 14:19:20 -050051export srctree OUTPUT CFLAGS SRCARCH AWK
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060052include $(srctree)/tools/build/Makefile.include
53
54$(OBJTOOL_IN): fixdep FORCE
Julien Thierryaa584722020-03-27 15:28:38 +000055 @$(CONFIG_SHELL) ./sync-check.sh
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060056 @$(MAKE) $(build)=objtool
57
58$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060059 $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
60
61
62$(LIBSUBCMD): fixdep FORCE
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060063 $(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT)
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060064
Josh Poimboeufc1d45c32016-03-02 18:39:37 -060065clean:
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060066 $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
67 $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
Josh Poimboeufd046b722019-08-29 17:41:18 -050068 $(Q)$(RM) $(OUTPUT)arch/x86/inat-tables.c $(OUTPUT)fixdep
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060069
70FORCE:
71
72.PHONY: clean FORCE