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