Makefile 2.5 KB

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