Makefile 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 || grep -E -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. ifeq ($(JOBS),1)
  49. BUILD_TYPE := sequential
  50. else
  51. BUILD_TYPE := parallel
  52. endif
  53. define print_msg
  54. @printf ' BUILD: Doing '\''make \033[33m-j'$(JOBS)'\033[m'\'' $(BUILD_TYPE) build\n'
  55. endef
  56. define make
  57. @$(MAKE) -f Makefile.perf --no-print-directory -j$(JOBS) O=$(FULL_O) $(SET_DEBUG) $@
  58. endef
  59. #
  60. # Needed if no target specified:
  61. # (Except for tags and TAGS targets. The reason is that the
  62. # Makefile does not treat tags/TAGS as targets but as files
  63. # and thus won't rebuilt them once they are in place.)
  64. #
  65. all tags TAGS:
  66. $(print_msg)
  67. $(make)
  68. ifdef MAKECMDGOALS
  69. has_clean := 0
  70. ifneq ($(filter clean,$(MAKECMDGOALS)),)
  71. has_clean := 1
  72. endif # clean
  73. ifeq ($(has_clean),1)
  74. rest := $(filter-out clean,$(MAKECMDGOALS))
  75. ifneq ($(rest),)
  76. $(rest): clean
  77. endif # rest
  78. endif # has_clean
  79. endif # MAKECMDGOALS
  80. #
  81. # Explicitly disable parallelism for the clean target.
  82. #
  83. clean:
  84. $(make) -j1
  85. #
  86. # The build-test target is not really parallel, don't print the jobs info,
  87. # it also uses only the tests/make targets that don't pollute the source
  88. # repository, i.e. that uses O= or builds the tarpkg outside the source
  89. # repo directories.
  90. #
  91. # For a full test, use:
  92. #
  93. # make -C tools/perf -f tests/make
  94. #
  95. build-test:
  96. @$(MAKE) SHUF=1 -f tests/make REUSE_FEATURES_DUMP=1 MK=Makefile SET_PARALLEL=1 --no-print-directory tarpkg make_static make_with_gtk2 out
  97. build-test-tarball:
  98. @$(MAKE) -f tests/make REUSE_FEATURES_DUMP=1 MK=Makefile SET_PARALLEL=1 --no-print-directory out
  99. #
  100. # All other targets get passed through:
  101. #
  102. %: FORCE
  103. $(print_msg)
  104. $(make)
  105. .PHONY: tags TAGS FORCE Makefile