1
0

Makefile 3.0 KB

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