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