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