xref: /openbmc/linux/tools/objtool/Makefile (revision 6c9111bc)
1# SPDX-License-Identifier: GPL-2.0
2include ../scripts/Makefile.include
3include ../scripts/Makefile.arch
4
5# always use the host compiler
6ifneq ($(LLVM),)
7HOSTAR	?= llvm-ar
8HOSTCC	?= clang
9HOSTLD	?= ld.lld
10else
11HOSTAR	?= ar
12HOSTCC	?= gcc
13HOSTLD	?= ld
14endif
15AR	 = $(HOSTAR)
16CC	 = $(HOSTCC)
17LD	 = $(HOSTLD)
18
19ifeq ($(srctree),)
20srctree := $(patsubst %/,%,$(dir $(CURDIR)))
21srctree := $(patsubst %/,%,$(dir $(srctree)))
22endif
23
24SUBCMD_SRCDIR		= $(srctree)/tools/lib/subcmd/
25LIBSUBCMD_OUTPUT	= $(if $(OUTPUT),$(OUTPUT),$(CURDIR)/)
26LIBSUBCMD		= $(LIBSUBCMD_OUTPUT)libsubcmd.a
27
28OBJTOOL    := $(OUTPUT)objtool
29OBJTOOL_IN := $(OBJTOOL)-in.o
30
31LIBELF_FLAGS := $(shell pkg-config libelf --cflags 2>/dev/null)
32LIBELF_LIBS  := $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf)
33
34all: $(OBJTOOL)
35
36INCLUDES := -I$(srctree)/tools/include \
37	    -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
38	    -I$(srctree)/tools/arch/$(SRCARCH)/include	\
39	    -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include
40WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
41CFLAGS   := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
42LDFLAGS  += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
43
44# Allow old libelf to be used:
45elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
46CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
47
48AWK = awk
49
50SUBCMD_CHECK := n
51SUBCMD_ORC := n
52
53ifeq ($(SRCARCH),x86)
54	SUBCMD_CHECK := y
55	SUBCMD_ORC := y
56endif
57
58ifeq ($(SUBCMD_ORC),y)
59	CFLAGS += -DINSN_USE_ORC
60endif
61
62export SUBCMD_CHECK SUBCMD_ORC
63export srctree OUTPUT CFLAGS SRCARCH AWK
64include $(srctree)/tools/build/Makefile.include
65
66$(OBJTOOL_IN): fixdep FORCE
67	@$(CONFIG_SHELL) ./sync-check.sh
68	@$(MAKE) $(build)=objtool
69
70$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
71	$(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
72
73
74$(LIBSUBCMD): fixdep FORCE
75	$(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT)
76
77clean:
78	$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
79	$(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
80	$(Q)$(RM) $(OUTPUT)arch/x86/inat-tables.c $(OUTPUT)fixdep
81
82FORCE:
83
84.PHONY: clean FORCE
85