1 # SPDX-License-Identifier: GPL-2.0
2 include ../scripts/Makefile.include
3 include ../scripts/Makefile.arch
6 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
7 srctree := $(patsubst %/,%,$(dir $(srctree)))
10 LIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/
12 LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd
14 LIBSUBCMD_OUTPUT = $(CURDIR)/libsubcmd
16 LIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a
18 OBJTOOL := $(OUTPUT)objtool
19 OBJTOOL_IN := $(OBJTOOL)-in.o
21 LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null)
22 LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)
26 INCLUDES := -I$(srctree)/tools/include \
27 -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
28 -I$(srctree)/tools/arch/$(SRCARCH)/include \
29 -I$(srctree)/tools/objtool/include \
30 -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \
31 -I$(LIBSUBCMD_OUTPUT)/include
32 # Note, EXTRA_WARNINGS here was determined for CC and not HOSTCC, it
33 # is passed here to match a legacy behavior.
34 WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
35 OBJTOOL_CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
36 OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
38 # Allow old libelf to be used:
39 elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - | grep elf_getshdr)
40 OBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
42 # Always want host compilation.
43 HOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)"
61 export srctree OUTPUT CFLAGS SRCARCH AWK
62 include $(srctree)/tools/build/Makefile.include
64 $(OBJTOOL_IN): fixdep $(LIBSUBCMD) FORCE
65 $(Q)$(CONFIG_SHELL) ./sync-check.sh
66 $(Q)$(MAKE) $(build)=objtool $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \
67 LDFLAGS="$(OBJTOOL_LDFLAGS)"
70 $(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
71 $(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(OBJTOOL_LDFLAGS) -o $@
77 $(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE
78 $(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
79 DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \
80 $(HOST_OVERRIDES) EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \
84 $(call QUIET_CLEAN, libsubcmd)
85 $(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT)
87 clean: $(LIBSUBCMD)-clean
88 $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
89 $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
90 $(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep