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