1 1.4 sjg # $NetBSD: varname-dot-make-jobs.mk,v 1.4 2023/09/09 01:30:59 sjg Exp $ 2 1.1 rillig # 3 1.3 rillig # Tests for the special .MAKE.JOBS variable, which is defined in jobs mode 4 1.3 rillig # only. There it contains the number of jobs that may run in parallel. 5 1.1 rillig 6 1.3 rillig .MAIN: all 7 1.3 rillig 8 1.3 rillig echo: .PHONY 9 1.3 rillig @echo ${.MAKE.JOBS:Uundefined} 10 1.1 rillig 11 1.1 rillig all: 12 1.3 rillig @${MAKE} -r -f ${MAKEFILE} echo 13 1.3 rillig @${MAKE} -r -f ${MAKEFILE} echo -j1 14 1.3 rillig @${MAKE} -r -f ${MAKEFILE} echo -j5 15 1.3 rillig @${MAKE} -r -f ${MAKEFILE} echo -j20 16 1.3 rillig @${MAKE} -r -f ${MAKEFILE} echo -j00000000000000000000000000000001 17 1.3 rillig 18 1.4 sjg .if !make(echo) 19 1.4 sjg # These results will not be static, we need NCPU 20 1.4 sjg # to compute expected results. 21 1.4 sjg # We only support -jC if _SC_NPROCESSORS_ONLN is defined, 22 1.4 sjg # otherwise we will get NCPU=0 23 1.4 sjg NCPU!= ${MAKE} -r -f /dev/null -jC -V .MAKE.JOBS 2> /dev/null || echo 0 24 1.4 sjg 25 1.4 sjg .if ${NCPU} > 0 26 1.4 sjg all: jC 27 1.4 sjg 28 1.4 sjg # If -j arg is floating point or ends in C; 29 1.4 sjg # .MAKE.JOBS is a multiple of _SC_NPROCESSORS_ONLN 30 1.4 sjg # No news is good news here. 31 1.4 sjg jCvals ?= 1 1.2 2 32 1.4 sjg 33 1.4 sjg jC: 34 1.4 sjg @for j in ${jCvals}; do \ 35 1.4 sjg e=`echo "${NCPU} * $$j" | bc | sed 's/\.[0-9]*//'`; \ 36 1.4 sjg g=`${MAKE} -r -f /dev/null -V .MAKE.JOBS -j$${j}C`; \ 37 1.4 sjg test $$g = $$e || echo "$$g != $$e"; \ 38 1.4 sjg done 39 1.4 sjg 40 1.4 sjg .endif 41 1.4 sjg .endif 42 1.4 sjg 43 1.3 rillig # expect: undefined 44 1.3 rillig # expect: 1 45 1.3 rillig # expect: 5 46 1.3 rillig # expect: 20 47 1.4 sjg # expect: 1 48