xref: /openbmc/linux/tools/objtool/Makefile (revision 25c2e591)
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	= $(or $(OUTPUT),$(CURDIR)/)
17LIBSUBCMD		= $(LIBSUBCMD_OUTPUT)libsubcmd.a
18
19OBJTOOL    := $(OUTPUT)objtool
20OBJTOOL_IN := $(OBJTOOL)-in.o
21
22LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null)
23LIBELF_LIBS  := $(shell $(HOSTPKG_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/include \
31	    -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include
32WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
33CFLAGS   := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
34LDFLAGS  += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
35
36# Allow old libelf to be used:
37elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
38CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
39
40AWK = awk
41
42BUILD_ORC := n
43
44ifeq ($(SRCARCH),x86)
45	BUILD_ORC := y
46endif
47
48export BUILD_ORC
49export srctree OUTPUT CFLAGS SRCARCH AWK
50include $(srctree)/tools/build/Makefile.include
51
52$(OBJTOOL_IN): fixdep FORCE
53	@$(CONFIG_SHELL) ./sync-check.sh
54	@$(MAKE) $(build)=objtool
55
56$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
57	$(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
58
59
60$(LIBSUBCMD): fixdep FORCE
61	$(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT)
62
63clean:
64	$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
65	$(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
66	$(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep $(LIBSUBCMD)
67
68FORCE:
69
70.PHONY: clean FORCE
71