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