Merge tag 'for-5.12-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave...
[linux-2.6-microblaze.git] / tools / objtool / Makefile
1 # SPDX-License-Identifier: GPL-2.0
2 include ../scripts/Makefile.include
3 include ../scripts/Makefile.arch
4
5 # always use the host compiler
6 AR       = $(HOSTAR)
7 CC       = $(HOSTCC)
8 LD       = $(HOSTLD)
9
10 ifeq ($(srctree),)
11 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
12 srctree := $(patsubst %/,%,$(dir $(srctree)))
13 endif
14
15 SUBCMD_SRCDIR           = $(srctree)/tools/lib/subcmd/
16 LIBSUBCMD_OUTPUT        = $(if $(OUTPUT),$(OUTPUT),$(CURDIR)/)
17 LIBSUBCMD               = $(LIBSUBCMD_OUTPUT)libsubcmd.a
18
19 OBJTOOL    := $(OUTPUT)objtool
20 OBJTOOL_IN := $(OBJTOOL)-in.o
21
22 LIBELF_FLAGS := $(shell pkg-config libelf --cflags 2>/dev/null)
23 LIBELF_LIBS  := $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf)
24
25 all: $(OBJTOOL)
26
27 INCLUDES := -I$(srctree)/tools/include \
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 WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
33 CFLAGS   := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
34 LDFLAGS  += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
35
36 # Allow old libelf to be used:
37 elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
38 CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
39
40 AWK = awk
41
42 SUBCMD_CHECK := n
43 SUBCMD_ORC := n
44
45 ifeq ($(SRCARCH),x86)
46         SUBCMD_CHECK := y
47         SUBCMD_ORC := y
48 endif
49
50 export SUBCMD_CHECK SUBCMD_ORC
51 export srctree OUTPUT CFLAGS SRCARCH AWK
52 include $(srctree)/tools/build/Makefile.include
53
54 $(OBJTOOL_IN): fixdep FORCE
55         @$(CONFIG_SHELL) ./sync-check.sh
56         @$(MAKE) $(build)=objtool
57
58 $(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
59         $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
60
61
62 $(LIBSUBCMD): fixdep FORCE
63         $(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT)
64
65 clean:
66         $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
67         $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
68         $(Q)$(RM) $(OUTPUT)arch/x86/inat-tables.c $(OUTPUT)fixdep
69
70 FORCE:
71
72 .PHONY: clean FORCE