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