1
0

Makefile 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. SHELL := /usr/bin/env bash
  2. ifeq ($(wildcard config.mak),)
  3. $(error run ./configure first. See ./configure -h)
  4. endif
  5. include config.mak
  6. # Set search path for all sources
  7. VPATH = $(SRCDIR)
  8. libdirs-get = $(shell [ -d "lib/$(1)" ] && echo "lib/$(1) lib/$(1)/asm")
  9. ARCH_LIBDIRS := $(call libdirs-get,$(ARCH)) $(call libdirs-get,$(TEST_DIR))
  10. OBJDIRS := $(ARCH_LIBDIRS)
  11. DESTDIR := $(PREFIX)/share/kvm-unit-tests/
  12. .PHONY: arch_clean clean distclean cscope
  13. #make sure env CFLAGS variable is not used
  14. CFLAGS =
  15. libgcc := $(shell $(CC) --print-libgcc-file-name)
  16. libcflat := lib/libcflat.a
  17. cflatobjs := \
  18. lib/argv.o \
  19. lib/printf.o \
  20. lib/string.o \
  21. lib/abort.o \
  22. lib/report.o \
  23. lib/stack.o
  24. # libfdt paths
  25. LIBFDT_objdir = lib/libfdt
  26. LIBFDT_srcdir = $(SRCDIR)/lib/libfdt
  27. LIBFDT_archive = $(LIBFDT_objdir)/libfdt.a
  28. LIBFDT_include = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_INCLUDES))
  29. LIBFDT_version = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_VERSION))
  30. OBJDIRS += $(LIBFDT_objdir)
  31. #include architecture specific make rules
  32. include $(SRCDIR)/$(TEST_DIR)/Makefile
  33. # cc-option
  34. # Usage: OP_CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
  35. cc-option = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \
  36. > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
  37. COMMON_CFLAGS += -g $(autodepend-flags)
  38. COMMON_CFLAGS += -Wall -Wwrite-strings -Wclobbered -Wempty-body -Wuninitialized
  39. COMMON_CFLAGS += -Wignored-qualifiers -Wunused-but-set-parameter
  40. COMMON_CFLAGS += -Werror
  41. frame-pointer-flag=-f$(if $(KEEP_FRAME_POINTER),no-,)omit-frame-pointer
  42. fomit_frame_pointer := $(call cc-option, $(frame-pointer-flag), "")
  43. fnostack_protector := $(call cc-option, -fno-stack-protector, "")
  44. fnostack_protector_all := $(call cc-option, -fno-stack-protector-all, "")
  45. wno_frame_address := $(call cc-option, -Wno-frame-address, "")
  46. fno_pic := $(call cc-option, -fno-pic, "")
  47. no_pie := $(call cc-option, -no-pie, "")
  48. COMMON_CFLAGS += $(fomit_frame_pointer)
  49. COMMON_CFLAGS += $(fno_stack_protector)
  50. COMMON_CFLAGS += $(fno_stack_protector_all)
  51. COMMON_CFLAGS += $(wno_frame_address)
  52. COMMON_CFLAGS += $(if $(U32_LONG_FMT),-D__U32_LONG_FMT__,)
  53. COMMON_CFLAGS += $(fno_pic) $(no_pie)
  54. CFLAGS += $(COMMON_CFLAGS)
  55. CFLAGS += -Wmissing-parameter-type -Wold-style-declaration -Woverride-init
  56. CXXFLAGS += $(COMMON_CFLAGS)
  57. autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d
  58. LDFLAGS += $(CFLAGS)
  59. $(libcflat): $(cflatobjs)
  60. $(AR) rcs $@ $^
  61. include $(LIBFDT_srcdir)/Makefile.libfdt
  62. $(LIBFDT_archive): CFLAGS += -ffreestanding -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -Wno-sign-compare
  63. $(LIBFDT_archive): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS))
  64. $(AR) rcs $@ $^
  65. # Build directory target
  66. .PHONY: directories
  67. directories:
  68. @mkdir -p $(OBJDIRS)
  69. %.o: %.S
  70. $(CC) $(CFLAGS) -c -nostdlib -o $@ $<
  71. -include */.*.d */*/.*.d
  72. all: directories $(shell cd $(SRCDIR) && git rev-parse --verify --short=8 HEAD >$(PWD)/build-head 2>/dev/null)
  73. standalone: all
  74. @scripts/mkstandalone.sh
  75. install: standalone
  76. mkdir -p $(DESTDIR)
  77. install tests/* $(DESTDIR)
  78. clean: arch_clean
  79. $(RM) lib/.*.d $(libcflat) $(cflatobjs)
  80. libfdt_clean:
  81. $(RM) $(LIBFDT_archive) \
  82. $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS)) \
  83. $(LIBFDT_objdir)/.*.d
  84. distclean: clean libfdt_clean
  85. $(RM) lib/asm config.mak $(TEST_DIR)-run msr.out cscope.* build-head
  86. $(RM) -r tests logs logs.old
  87. cscope: cscope_dirs = lib lib/libfdt lib/linux $(TEST_DIR) $(ARCH_LIBDIRS) lib/asm-generic
  88. cscope:
  89. $(RM) ./cscope.*
  90. find -L $(cscope_dirs) -maxdepth 1 \
  91. -name '*.[chsS]' -print | sed 's,^\./,,' | sort -u > ./cscope.files
  92. cscope -bk