Makefile 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # SPDX-License-Identifier: GPL-2.0
  2. include ../scripts/Makefile.include
  3. include ../scripts/Makefile.arch
  4. ifeq ($(ARCH),x86_64)
  5. ARCH := x86
  6. endif
  7. # always use the host compiler
  8. HOSTAR ?= ar
  9. HOSTCC ?= gcc
  10. HOSTLD ?= ld
  11. AR = $(HOSTAR)
  12. CC = $(HOSTCC)
  13. LD = $(HOSTLD)
  14. ifeq ($(srctree),)
  15. srctree := $(patsubst %/,%,$(dir $(CURDIR)))
  16. srctree := $(patsubst %/,%,$(dir $(srctree)))
  17. endif
  18. SUBCMD_SRCDIR = $(srctree)/tools/lib/subcmd/
  19. LIBSUBCMD_OUTPUT = $(if $(OUTPUT),$(OUTPUT),$(CURDIR)/)
  20. LIBSUBCMD = $(LIBSUBCMD_OUTPUT)libsubcmd.a
  21. OBJTOOL := $(OUTPUT)objtool
  22. OBJTOOL_IN := $(OBJTOOL)-in.o
  23. LIBELF_FLAGS := $(shell pkg-config libelf --cflags 2>/dev/null)
  24. LIBELF_LIBS := $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf)
  25. all: $(OBJTOOL)
  26. INCLUDES := -I$(srctree)/tools/include \
  27. -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
  28. -I$(srctree)/tools/objtool/arch/$(ARCH)/include
  29. WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed
  30. CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
  31. LDFLAGS += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
  32. # Allow old libelf to be used:
  33. elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
  34. CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
  35. AWK = awk
  36. export srctree OUTPUT CFLAGS SRCARCH AWK
  37. include $(srctree)/tools/build/Makefile.include
  38. $(OBJTOOL_IN): fixdep FORCE
  39. @$(MAKE) $(build)=objtool
  40. $(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
  41. @$(CONFIG_SHELL) ./sync-check.sh
  42. $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
  43. $(LIBSUBCMD): fixdep FORCE
  44. $(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT)
  45. clean:
  46. $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
  47. $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
  48. $(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
  49. FORCE:
  50. .PHONY: clean FORCE