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