1 # SPDX-License-Identifier: GPL-2.0
2 include ../scripts/Makefile.include
3 include ../scripts/Makefile.arch
5 # always use the host compiler
20 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
21 srctree := $(patsubst %/,%,$(dir $(srctree)))
24 SUBCMD_SRCDIR = $(srctree)/tools/lib/subcmd/
25 LIBSUBCMD_OUTPUT = $(if $(OUTPUT),$(OUTPUT),$(CURDIR)/)
26 LIBSUBCMD = $(LIBSUBCMD_OUTPUT)libsubcmd.a
28 OBJTOOL := $(OUTPUT)objtool
29 OBJTOOL_IN := $(OBJTOOL)-in.o
31 LIBELF_FLAGS := $(shell pkg-config libelf --cflags 2>/dev/null)
32 LIBELF_LIBS := $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf)
36 INCLUDES := -I$(srctree)/tools/include \
37 -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
38 -I$(srctree)/tools/arch/$(SRCARCH)/include
39 WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed
40 CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
41 LDFLAGS += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
43 # Allow old libelf to be used:
44 elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
45 CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
48 export srctree OUTPUT CFLAGS SRCARCH AWK
49 include $(srctree)/tools/build/Makefile.include
51 $(OBJTOOL_IN): fixdep FORCE
52 @$(MAKE) $(build)=objtool
54 $(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
55 @$(CONFIG_SHELL) ./sync-check.sh
56 $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
59 $(LIBSUBCMD): fixdep FORCE
60 $(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT)
63 $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
64 $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
65 $(Q)$(RM) $(OUTPUT)arch/x86/inat-tables.c $(OUTPUT)fixdep