1# SPDX-License-Identifier: GPL-2.0 2include ../scripts/Makefile.include 3include ../scripts/Makefile.arch 4 5ifeq ($(srctree),) 6srctree := $(patsubst %/,%,$(dir $(CURDIR))) 7srctree := $(patsubst %/,%,$(dir $(srctree))) 8endif 9 10LIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/ 11ifneq ($(OUTPUT),) 12 LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd 13else 14 LIBSUBCMD_OUTPUT = $(CURDIR)/libsubcmd 15endif 16LIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a 17 18OBJTOOL := $(OUTPUT)objtool 19OBJTOOL_IN := $(OBJTOOL)-in.o 20 21LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null) 22LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf) 23 24all: $(OBJTOOL) 25 26INCLUDES := -I$(srctree)/tools/include \ 27 -I$(srctree)/tools/include/uapi \ 28 -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \ 29 -I$(srctree)/tools/arch/$(SRCARCH)/include \ 30 -I$(srctree)/tools/objtool/include \ 31 -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \ 32 -I$(LIBSUBCMD_OUTPUT)/include 33# Note, EXTRA_WARNINGS here was determined for CC and not HOSTCC, it 34# is passed here to match a legacy behavior. 35WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs 36OBJTOOL_CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS) 37OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) 38 39# Allow old libelf to be used: 40elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - | grep elf_getshdr) 41OBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED) 42 43# Always want host compilation. 44HOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)" 45 46AWK = awk 47MKDIR = mkdir 48 49ifeq ($(V),1) 50 Q = 51else 52 Q = @ 53endif 54 55BUILD_ORC := n 56 57ifeq ($(SRCARCH),x86) 58 BUILD_ORC := y 59endif 60 61ifeq ($(SRCARCH),loongarch) 62 BUILD_ORC := y 63endif 64 65export BUILD_ORC 66export srctree OUTPUT CFLAGS SRCARCH AWK 67include $(srctree)/tools/build/Makefile.include 68 69$(OBJTOOL_IN): fixdep $(LIBSUBCMD) FORCE 70 $(Q)$(CONFIG_SHELL) ./sync-check.sh 71 $(Q)$(MAKE) $(build)=objtool $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \ 72 LDFLAGS="$(OBJTOOL_LDFLAGS)" 73 74 75$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN) 76 $(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(OBJTOOL_LDFLAGS) -o $@ 77 78 79$(LIBSUBCMD_OUTPUT): 80 $(Q)$(MKDIR) -p $@ 81 82$(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE 83 $(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \ 84 DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \ 85 $(HOST_OVERRIDES) EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \ 86 $@ install_headers 87 88$(LIBSUBCMD)-clean: 89 $(call QUIET_CLEAN, libsubcmd) 90 $(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT) 91 92clean: $(LIBSUBCMD)-clean 93 $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL) 94 $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete 95 $(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep 96 97FORCE: 98 99.PHONY: clean FORCE 100