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