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