162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci#
362306a36Sopenharmony_ci# This is a simple wrapper Makefile that calls the main Makefile.perf
462306a36Sopenharmony_ci# with a -j option to do parallel builds
562306a36Sopenharmony_ci#
662306a36Sopenharmony_ci# If you want to invoke the perf build in some non-standard way then
762306a36Sopenharmony_ci# you can use the 'make -f Makefile.perf' method to invoke it.
862306a36Sopenharmony_ci#
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#
1162306a36Sopenharmony_ci# Clear out the built-in rules GNU make defines by default (such as .o targets),
1262306a36Sopenharmony_ci# so that we pass through all targets to Makefile.perf:
1362306a36Sopenharmony_ci#
1462306a36Sopenharmony_ci.SUFFIXES:
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#
1762306a36Sopenharmony_ci# We don't want to pass along options like -j:
1862306a36Sopenharmony_ci#
1962306a36Sopenharmony_ciunexport MAKEFLAGS
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci#
2262306a36Sopenharmony_ci# Do a parallel build with multiple jobs, based on the number of CPUs online
2362306a36Sopenharmony_ci# in this system: 'make -j8' on a 8-CPU system, etc.
2462306a36Sopenharmony_ci#
2562306a36Sopenharmony_ci# (To override it, run 'make JOBS=1' and similar.)
2662306a36Sopenharmony_ci#
2762306a36Sopenharmony_ciifeq ($(JOBS),)
2862306a36Sopenharmony_ci  JOBS := $(shell (getconf _NPROCESSORS_ONLN || grep -E -c '^processor|^CPU[0-9]' /proc/cpuinfo) 2>/dev/null)
2962306a36Sopenharmony_ci  ifeq ($(JOBS),0)
3062306a36Sopenharmony_ci    JOBS := 1
3162306a36Sopenharmony_ci  endif
3262306a36Sopenharmony_ciendif
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci#
3562306a36Sopenharmony_ci# Only pass canonical directory names as the output directory:
3662306a36Sopenharmony_ci#
3762306a36Sopenharmony_ciifneq ($(O),)
3862306a36Sopenharmony_ci  FULL_O := $(shell cd $(PWD); readlink -f $(O) || echo $(O))
3962306a36Sopenharmony_ciendif
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci#
4262306a36Sopenharmony_ci# Only accept the 'DEBUG' variable from the command line:
4362306a36Sopenharmony_ci#
4462306a36Sopenharmony_ciifeq ("$(origin DEBUG)", "command line")
4562306a36Sopenharmony_ci  ifeq ($(DEBUG),)
4662306a36Sopenharmony_ci    override DEBUG = 0
4762306a36Sopenharmony_ci  else
4862306a36Sopenharmony_ci    SET_DEBUG = "DEBUG=$(DEBUG)"
4962306a36Sopenharmony_ci  endif
5062306a36Sopenharmony_cielse
5162306a36Sopenharmony_ci  override DEBUG = 0
5262306a36Sopenharmony_ciendif
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cidefine print_msg
5562306a36Sopenharmony_ci  @printf '  BUILD:   Doing '\''make \033[33m-j'$(JOBS)'\033[m'\'' parallel build\n'
5662306a36Sopenharmony_ciendef
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_cidefine make
5962306a36Sopenharmony_ci  @$(MAKE) -f Makefile.perf --no-print-directory -j$(JOBS) O=$(FULL_O) $(SET_DEBUG) $@
6062306a36Sopenharmony_ciendef
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci#
6362306a36Sopenharmony_ci# Needed if no target specified:
6462306a36Sopenharmony_ci# (Except for tags and TAGS targets. The reason is that the
6562306a36Sopenharmony_ci# Makefile does not treat tags/TAGS as targets but as files
6662306a36Sopenharmony_ci# and thus won't rebuilt them once they are in place.)
6762306a36Sopenharmony_ci#
6862306a36Sopenharmony_ciall tags TAGS:
6962306a36Sopenharmony_ci	$(print_msg)
7062306a36Sopenharmony_ci	$(make)
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ciifdef MAKECMDGOALS
7362306a36Sopenharmony_cihas_clean := 0
7462306a36Sopenharmony_ciifneq ($(filter clean,$(MAKECMDGOALS)),)
7562306a36Sopenharmony_ci  has_clean := 1
7662306a36Sopenharmony_ciendif # clean
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ciifeq ($(has_clean),1)
7962306a36Sopenharmony_ci  rest := $(filter-out clean,$(MAKECMDGOALS))
8062306a36Sopenharmony_ci  ifneq ($(rest),)
8162306a36Sopenharmony_ci$(rest): clean
8262306a36Sopenharmony_ci  endif # rest
8362306a36Sopenharmony_ciendif # has_clean
8462306a36Sopenharmony_ciendif # MAKECMDGOALS
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci#
8762306a36Sopenharmony_ci# Explicitly disable parallelism for the clean target.
8862306a36Sopenharmony_ci#
8962306a36Sopenharmony_ciclean:
9062306a36Sopenharmony_ci	$(make) -j1
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci#
9362306a36Sopenharmony_ci# The build-test target is not really parallel, don't print the jobs info,
9462306a36Sopenharmony_ci# it also uses only the tests/make targets that don't pollute the source
9562306a36Sopenharmony_ci# repository, i.e. that uses O= or builds the tarpkg outside the source
9662306a36Sopenharmony_ci# repo directories.
9762306a36Sopenharmony_ci#
9862306a36Sopenharmony_ci# For a full test, use:
9962306a36Sopenharmony_ci#
10062306a36Sopenharmony_ci# make -C tools/perf -f tests/make
10162306a36Sopenharmony_ci#
10262306a36Sopenharmony_cibuild-test:
10362306a36Sopenharmony_ci	@$(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
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_cibuild-test-tarball:
10662306a36Sopenharmony_ci	@$(MAKE) -f tests/make REUSE_FEATURES_DUMP=1 MK=Makefile SET_PARALLEL=1 --no-print-directory out
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci#
10962306a36Sopenharmony_ci# All other targets get passed through:
11062306a36Sopenharmony_ci#
11162306a36Sopenharmony_ci%: FORCE
11262306a36Sopenharmony_ci	$(print_msg)
11362306a36Sopenharmony_ci	$(make)
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci.PHONY: tags TAGS FORCE Makefile
116