make-alpha
[Top][All Lists]
Advanced

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

Re: .ONESHELL enhancement?


From: Matt McCutchen
Subject: Re: .ONESHELL enhancement?
Date: Sun, 04 Oct 2009 03:51:25 -0400

On Sat, 2009-10-03 at 10:12 +0000, Ralf Wildenhues wrote:
> First off, the shell carries more state across recipe command lines than
> just the status of the last executed command.  The Posix sh page lists some
> at "Shell Execution Environment".  Specifically, several options that can be
> set with "set", traps, variable settings, and the current directory are
> relevant for makefiles.  Automake used to rely on
>   cd $(subdir) && $(MAKE)
>   $some_other_command
> 
> executing the second line in the current directory, as well as variables
> not being saved across command lines.  File descriptors being redirected
> are another issue.
> 
> Some of the BSD make implementations also had interesting semantics when
> an earlier command line had an "exit 0" statement in it, as in
>   $condition || exit 0; \
>   $expensive_commands
>   $cmds_to_be_run_even_with_false_condition
> 
> where the last commands would not be executed, of course without a diagnosis
> or error exit.
> 
> The portability section of the Autoconf manual documents these quirks now.

The only general fix I can envision for these issues is to wrap every
line (after interpretation of \ continuations) in parentheses.  Compared
to the current approach, this would save execs but not forks.  I did a
little test on my computer and the exec seems to be the expensive part:

$ time bash -c 'for i in {1..1000}; do (true); done'

real    0m0.878s
user    0m0.190s
sys     0m0.813s

$ time bash -c 'for i in {1..1000}; do bash -c true; done'

real    0m3.595s
user    0m1.454s
sys     0m2.132s

> Second, I may remind you that the shell && does not have precedence in the
> way that one expects from C, but operates in left to right fashion and with
> equal precedence to ||.  This means, connecting these two lines
>   false
>   echo nope || echo oops
> 
> in one shell command with && will give a different result from passing it
> to two different shells.

That's why the current proposal is to leave in the newlines and pass -e.

> As another minor point, constructs used to avoid shell command line length
> limitations may break with this optimization.

Is it still a problem to pass the shell a long multiline argument with
-c?  If so, make could use a pipe or a temporary file.

-- 
Matt





reply via email to

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