blob: a43096f713c7be14d16f14613ab73fbfb27ec1ec [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001# SPDX-License-Identifier: GPL-2.0
2include ../scripts/Makefile.include
3include ../scripts/Makefile.arch
4
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00005# always use the host compiler
David Brazdil0f672f62019-12-10 10:32:29 +00006AR = $(HOSTAR)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00007CC = $(HOSTCC)
8LD = $(HOSTLD)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00009
10ifeq ($(srctree),)
11srctree := $(patsubst %/,%,$(dir $(CURDIR)))
12srctree := $(patsubst %/,%,$(dir $(srctree)))
13endif
14
15SUBCMD_SRCDIR = $(srctree)/tools/lib/subcmd/
16LIBSUBCMD_OUTPUT = $(if $(OUTPUT),$(OUTPUT),$(CURDIR)/)
17LIBSUBCMD = $(LIBSUBCMD_OUTPUT)libsubcmd.a
18
19OBJTOOL := $(OUTPUT)objtool
20OBJTOOL_IN := $(OBJTOOL)-in.o
21
David Brazdil0f672f62019-12-10 10:32:29 +000022LIBELF_FLAGS := $(shell pkg-config libelf --cflags 2>/dev/null)
23LIBELF_LIBS := $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf)
24
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000025all: $(OBJTOOL)
26
27INCLUDES := -I$(srctree)/tools/include \
28 -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
Olivier Deprez157378f2022-04-04 15:47:50 +020029 -I$(srctree)/tools/arch/$(SRCARCH)/include \
30 -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include
31WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
David Brazdil0f672f62019-12-10 10:32:29 +000032CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
33LDFLAGS += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000034
35# Allow old libelf to be used:
36elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
37CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
38
39AWK = awk
Olivier Deprez157378f2022-04-04 15:47:50 +020040
41SUBCMD_CHECK := n
42SUBCMD_ORC := n
43
44ifeq ($(SRCARCH),x86)
45 SUBCMD_CHECK := y
46 SUBCMD_ORC := y
47endif
48
Olivier Deprez157378f2022-04-04 15:47:50 +020049export SUBCMD_CHECK SUBCMD_ORC
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000050export srctree OUTPUT CFLAGS SRCARCH AWK
51include $(srctree)/tools/build/Makefile.include
52
53$(OBJTOOL_IN): fixdep FORCE
Olivier Deprez157378f2022-04-04 15:47:50 +020054 @$(CONFIG_SHELL) ./sync-check.sh
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000055 @$(MAKE) $(build)=objtool
56
57$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000058 $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
59
60
61$(LIBSUBCMD): fixdep FORCE
62 $(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT)
63
64clean:
65 $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
66 $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
David Brazdil0f672f62019-12-10 10:32:29 +000067 $(Q)$(RM) $(OUTPUT)arch/x86/inat-tables.c $(OUTPUT)fixdep
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000068
69FORCE:
70
71.PHONY: clean FORCE