help-make
[Top][All Lists]
Advanced

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

how to (correctly) modify GNU Make so that separate shell is always spaw


From: Mark Galeck
Subject: how to (correctly) modify GNU Make so that separate shell is always spawned for each command
Date: Sat, 16 Apr 2016 03:51:58 +0000 (UTC)

Hello,
the GNU Make manual says 
(...)executed by invoking a new sub-shell for each line of the recipe, unless 
the .ONESHELL special target is in effect (In practice, make may take shortcuts 
that do not affect the results.)


Some time ago I was asking here for help in modifying the source of Make 4.1 so 
that the above "shortcuts" are not taken, and in fact, Make would _always_ 
spawn a new shell.

Paul Smith and others graciously helped me and I was able to modify the file 
job.c in two places, to achieve this effect.  One of these places is:
else //if (strcmp (shell, default_shell))     goto slow;
where I comment out the if statement and so always the "slow" path is taken.  
(The other place where I modified does not matter for the purpose of the 
present question).  

This worked very well until I found a strange case yesterday where it does not 
work.  

The source fragment above seems to imply that we are going to a "slow" 
execution path, but "slowness" implies equivalence.  Well, it would seem than 
in the case below, where a different behaviour is observed with the above 
modification and without, then that cannot be the case, and perhaps even Make 
does not in fact behave equivalently to where a new shell were always spawned.

The failure case is:
Makefile:
export VAR-Y := val
.PHONY: allall:        $(MAKE) -f Makefile1

Makefile1:
$(warning VAR-Y $(VAR-Y))
all:


Here, if I call 
>make
the original Make works correctly, the value is printed in Makefile1, but after 
the above modification, no value is printed (the value is empty).
It is important that the variable name contains a dash, without that, the 
example works fine.  
The strange thing is that the "export" statement is of course not a shell 
command, but a Make construct.  Yet somehow it is affected by the above code 
modification.   

Please tell me if there is a way to enforce the behaviour of GNU Make that it 
always spawns a shell and if so, how.  
Thank you very much for any help and insight,
Mark





reply via email to

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