162306a36Sopenharmony_ci#!/bin/sh
262306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0+
362306a36Sopenharmony_ci#
462306a36Sopenharmony_ci# Figure out if we should follow a specific parallelism from the make
562306a36Sopenharmony_ci# environment (as exported by scripts/jobserver-exec), or fall back to
662306a36Sopenharmony_ci# the "auto" parallelism when "-jN" is not specified at the top-level
762306a36Sopenharmony_ci# "make" invocation.
862306a36Sopenharmony_ci
962306a36Sopenharmony_cisphinx="$1"
1062306a36Sopenharmony_cishift || true
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ciparallel="$PARALLELISM"
1362306a36Sopenharmony_ciif [ -z "$parallel" ] ; then
1462306a36Sopenharmony_ci	# If no parallelism is specified at the top-level make, then
1562306a36Sopenharmony_ci	# fall back to the expected "-jauto" mode that the "htmldocs"
1662306a36Sopenharmony_ci	# target has had.
1762306a36Sopenharmony_ci	auto=$(perl -e 'open IN,"'"$sphinx"' --version 2>&1 |";
1862306a36Sopenharmony_ci			while (<IN>) {
1962306a36Sopenharmony_ci				if (m/([\d\.]+)/) {
2062306a36Sopenharmony_ci					print "auto" if ($1 >= "1.7")
2162306a36Sopenharmony_ci				}
2262306a36Sopenharmony_ci			}
2362306a36Sopenharmony_ci			close IN')
2462306a36Sopenharmony_ci	if [ -n "$auto" ] ; then
2562306a36Sopenharmony_ci		parallel="$auto"
2662306a36Sopenharmony_ci	fi
2762306a36Sopenharmony_cifi
2862306a36Sopenharmony_ci# Only if some parallelism has been determined do we add the -jN option.
2962306a36Sopenharmony_ciif [ -n "$parallel" ] ; then
3062306a36Sopenharmony_ci	parallel="-j$parallel"
3162306a36Sopenharmony_cifi
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ciexec "$sphinx" $parallel "$@"
34