bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detecting parallel builds


From: David Boyce
Subject: Re: Detecting parallel builds
Date: Sat, 9 Apr 2011 20:48:02 -0400

On Sat, Apr 9, 2011 at 2:32 PM, Philip Prindeville
<address@hidden> wrote:
> address@hidden ~/openwrt2]$ make -j5 -f /tmp/Makefile
> MAKEFLAGS=
> MFLAGS=
> MAKE=make
> PBUILD=
> MAKEFLAGS=w
> MFLAGS=-w
> MAKE=make
> make[1]: Entering directory `/home/philipp/openwrt2'
> make[1]: Nothing to be done for `stop'.
> make[1]: Leaving directory `/home/philipp/openwrt2'
> address@hidden ~/openwrt2]$
>
> Not sure what I'm missing...

Unfortunately it appears that MAKEFLAGS is composed on the fly when
forking a command (aka job). See the following makefile:

% cat /tmp/Makefile
$(info MAKEFLAGS='$(MAKEFLAGS)')

.PHONY: all
all:
        @echo "MAKEFLAGS='$(MAKEFLAGS)' (recipe)"

% make -f /tmp/Makefile -j2
MAKEFLAGS=''
MAKEFLAGS=' --jobserver-fds=3,4 -j' (recipe)

So it's not available to $(info) and other functions outside of a
recipe. There's probably a way to trick make into doing a simple
recursion to harvest the data. Or if you're dealing with an
automated/nightly build you could set MAKEFLAGS yourself to turn on
parallelism:

    MAKEFLAGS=-j8 make ...

but at that point you might as well just take control yourself

PARALLEL=YES make -j8 ...

Here's a hack which will work by calling make recursively once, but
note that it will only work when no explicit target is mentioned:

% cat Makefile
.PHONY: all
all:

ifndef PARALLEL
.PHONY: _is_parallel
.DEFAULT_GOAL := _is_parallel
_is_parallel:
        address@hidden $(MAKE) -s -f $(MAKEFILE_LIST)
_is_parallel2` &&\
        PARALLEL=$$PARALLEL $(MAKE) --no-print-directory -f
$(MAKEFILE_LIST) $(MAKECMDGOALS)
else
.PHONY: _is_parallel2
_is_parallel2: ; @echo "$(if $(findstring -j,$(MAKEFLAGS)),YES,NO)"
endif

all:
        @echo "We $(if $(findstring YES,$(PARALLEL)),ARE,ARE NOT)
building in parallel"


David Boyce



reply via email to

[Prev in Thread] Current Thread [Next in Thread]