Makefile 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #
  2. # This is a simple wrapper Makefile that calls the main Makefile.perf
  3. # with a -j option to do parallel builds
  4. #
  5. # If you want to invoke the perf build in some non-standard way then
  6. # you can use the 'make -f Makefile.perf' method to invoke it.
  7. #
  8. #
  9. # Clear out the built-in rules GNU make defines by default (such as .o targets),
  10. # so that we pass through all targets to Makefile.perf:
  11. #
  12. .SUFFIXES:
  13. #
  14. # We don't want to pass along options like -j:
  15. #
  16. unexport MAKEFLAGS
  17. #
  18. # Do a parallel build with multiple jobs, based on the number of CPUs online
  19. # in this system: 'make -j8' on a 8-CPU system, etc.
  20. #
  21. # (To override it, run 'make JOBS=1' and similar.)
  22. #
  23. ifeq ($(JOBS),)
  24. JOBS := $(shell (getconf _NPROCESSORS_ONLN || egrep -c '^processor|^CPU[0-9]' /proc/cpuinfo) 2>/dev/null)
  25. ifeq ($(JOBS),0)
  26. JOBS := 1
  27. endif
  28. endif
  29. #
  30. # Only pass canonical directory names as the output directory:
  31. #
  32. ifneq ($(O),)
  33. FULL_O := $(shell readlink -f $(O) || echo $(O))
  34. endif
  35. #
  36. # Only accept the 'DEBUG' variable from the command line:
  37. #
  38. ifeq ("$(origin DEBUG)", "command line")
  39. ifeq ($(DEBUG),)
  40. override DEBUG = 0
  41. else
  42. SET_DEBUG = "DEBUG=$(DEBUG)"
  43. endif
  44. else
  45. override DEBUG = 0
  46. endif
  47. define print_msg
  48. @printf ' BUILD: Doing '\''make \033[33m-j'$(JOBS)'\033[m'\'' parallel build\n'
  49. endef
  50. define make
  51. @$(MAKE) -f Makefile.perf --no-print-directory -j$(JOBS) O=$(FULL_O) $(SET_DEBUG) $@
  52. endef
  53. #
  54. # Needed if no target specified:
  55. # (Except for tags and TAGS targets. The reason is that the
  56. # Makefile does not treat tags/TAGS as targets but as files
  57. # and thus won't rebuilt them once they are in place.)
  58. #
  59. all tags TAGS:
  60. $(print_msg)
  61. $(make)
  62. ifdef MAKECMDGOALS
  63. has_clean := 0
  64. ifneq ($(filter clean,$(MAKECMDGOALS)),)
  65. has_clean := 1
  66. endif # clean
  67. ifeq ($(has_clean),1)
  68. rest := $(filter-out clean,$(MAKECMDGOALS))
  69. ifneq ($(rest),)
  70. $(rest): clean
  71. endif # rest
  72. endif # has_clean
  73. endif # MAKECMDGOALS
  74. #
  75. # The clean target is not really parallel, don't print the jobs info:
  76. #
  77. clean:
  78. $(make)
  79. #
  80. # The build-test target is not really parallel, don't print the jobs info,
  81. # it also uses only the tests/make targets that don't pollute the source
  82. # repository, i.e. that uses O= or builds the tarpkg outside the source
  83. # repo directories.
  84. #
  85. # For a full test, use:
  86. #
  87. # make -C tools/perf -f tests/make
  88. #
  89. build-test:
  90. @$(MAKE) SHUF=1 -f tests/make REUSE_FEATURES_DUMP=1 MK=Makefile SET_PARALLEL=1 --no-print-directory tarpkg out
  91. #
  92. # All other targets get passed through:
  93. #
  94. %: FORCE
  95. $(print_msg)
  96. $(make)
  97. .PHONY: tags TAGS FORCE Makefile