Merge tag 'for-linus' of git://github.com/openrisc/linux
[platform/kernel/linux-rpi.git] / tools / objtool / Makefile
1 # SPDX-License-Identifier: GPL-2.0
2 include ../scripts/Makefile.include
3 include ../scripts/Makefile.arch
4
5 # always use the host compiler
6 HOSTAR  ?= ar
7 HOSTCC  ?= gcc
8 HOSTLD  ?= ld
9 AR       = $(HOSTAR)
10 CC       = $(HOSTCC)
11 LD       = $(HOSTLD)
12
13 ifeq ($(srctree),)
14 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
15 srctree := $(patsubst %/,%,$(dir $(srctree)))
16 endif
17
18 SUBCMD_SRCDIR           = $(srctree)/tools/lib/subcmd/
19 LIBSUBCMD_OUTPUT        = $(if $(OUTPUT),$(OUTPUT),$(CURDIR)/)
20 LIBSUBCMD               = $(LIBSUBCMD_OUTPUT)libsubcmd.a
21
22 OBJTOOL    := $(OUTPUT)objtool
23 OBJTOOL_IN := $(OBJTOOL)-in.o
24
25 LIBELF_FLAGS := $(shell pkg-config libelf --cflags 2>/dev/null)
26 LIBELF_LIBS  := $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf)
27
28 all: $(OBJTOOL)
29
30 INCLUDES := -I$(srctree)/tools/include \
31             -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
32             -I$(srctree)/tools/arch/$(SRCARCH)/include
33 WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed
34 CFLAGS   := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
35 LDFLAGS  += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
36
37 # Allow old libelf to be used:
38 elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
39 CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
40
41 AWK = awk
42 export srctree OUTPUT CFLAGS SRCARCH AWK
43 include $(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
56 clean:
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/inat-tables.c $(OUTPUT)fixdep
60
61 FORCE:
62
63 .PHONY: clean FORCE