Sun 06 Mar 2005 12:25:48 PM UTC, original submission:
Consider the following makefile
.PHONY: all
ifndef stop
export MAKE
all:
./stop.sh
else
all:
@echo stop
endif
And the stop.sh shell script:
#! /bin/bash
echo MAKE: $MAKE
echo MAKEFLAGS: $MAKEFLAGS
$MAKE --no-print-directory -f makefile stop=1
When executed with -j option it prints the following:
$ make -j 2
./stop.sh
MAKE: make
MAKEFLAGS: --jobserver-fds=3,5 -j
make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent make rule.
stop
Adding '+' in front of ./stop.sh indeed helps but it also has side effects which may be undesirable (e.g., the script could create files, etc).
Some further investigation revieled why the warning is the on the first place. There is a piece of code in job.c around line 1260 that looks like this:
/* If we aren't running a recursive command and we have
a jobserver pipe, close it before exec'ing. */
if (!(flags & COMMANDS_RECURSE) && job_fds[0] >= 0)
{
CLOSE_ON_EXEC (job_fds[0]);
CLOSE_ON_EXEC (job_fds[1]);
}
So what appers to be happening is that the "parent" make closes jobserver's pipes before executing ./stop.sh but
leaves the jobserver-related info in MAKEFLAGS which leads "child" make invocation to belive there is a parent's jobserver. In fact cleaning MAKEFLAGS (using sed) out of --jobserver-fds and -j gets rid of the warning.
It seems to me that the fix should have two parts to it. First, the MAKEFLAGS should be cleaned of any jobserver info when the pipes are closed. Second, it would be nice to have a command prefix like (+) that didn't have any effects other than allowing to use parent's jobserver.
Alternatively, we could simply leave pipes open all the time since it doesn't make much sense to start a separate jobserver from a script.
|