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