xref: /openbmc/linux/tools/objtool/Makefile (revision ba61bb17)
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
28all: $(OBJTOOL)
29
30INCLUDES := -I$(srctree)/tools/include \
31	    -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
32	    -I$(srctree)/tools/objtool/arch/$(ARCH)/include
33WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed
34CFLAGS   += -Werror $(WARNINGS) $(HOSTCFLAGS) -g $(INCLUDES)
35LDFLAGS  += -lelf $(LIBSUBCMD) $(HOSTLDFLAGS)
36
37# Allow old libelf to be used:
38elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
39CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
40
41AWK = awk
42export srctree OUTPUT CFLAGS SRCARCH AWK
43include $(srctree)/tools/build/Makefile.include
44
45$(OBJTOOL_IN): fixdep FORCE
46	@$(MAKE) $(build)=objtool
47
48$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
49	@$(CONFIG_SHELL) ./sync-check.sh
50	$(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
51
52
53$(LIBSUBCMD): fixdep FORCE
54	$(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT)
55
56clean:
57	$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
58	$(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
59	$(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
60
61FORCE:
62
63.PHONY: clean FORCE
64