Handling of shell builtins in make(1)

Harti Brandt hartmut.brandt at dlr.de
Tue May 24 05:19:18 PDT 2005


On Tue, 24 May 2005, Sergey Babkin wrote:

SB>>From: Harti Brandt <hartmut.brandt at dlr.de>
SB>
SB>>On Mon, 23 May 2005, Scott Long wrote:
SB>>
SB>
SB>>SL>> Opinions?
SB>>SL>> 
SB>>SL>> harti
SB>>SL>
SB>>SL>4. Separate /bin/sh into a front end and back end (libsh) and include libsh
SB>>SL>into make.
SB>>SL>
SB>>SL>(running and hiding as I hit the 'send' key)
SB>>
SB>>Would there be other uses for this?
SB>
SB>Yes, I think it could be useful for many programs.

Hmm. What program is executing shell lines?

SB>Or one more option: add a flag to shell that
SB>will make it exit after any command returning non-0
SB>status (at the ";" point, as opposed to "&&", 
SB>"||" and such). Then make could just pass all 
SB>the commands to the shell in one go. And it would 

There is the -e flag which does exactly this. Well, the description in the 
Posix page is a little bit convoluted, but basically it exits when a 
program whose exit status is not expclicitely tested exits with a non-zero
status (this is not entirely correct, but almost).

And currently we actually use sh -ec to execute commands. The problem with 
this is, that Posix wants sh -c. No -e! I think NetBSD has changed this 
(and there is a PR with a patch), but I'm somewhat reluctant to do it, 
because it may break things in unexpected ways. My current plan is to make 
the default -e normally and without -e in Posix mode.


SB>be very useful for all kinds of sysadmin scripts
SB>as well where explicitly checking for the results
SB>of every command is a pain. Even with make it
SB>would be a big improvement, since in the current
SB>format a command failing inside a "for" loop
SB>won't cause make to stop unless explicitly programmed
SB>so, like:
SB>
SB>target: dependencies
SB>   for ... ;\
SB>   do \
SB>     cmd || exit 1; \
SB>   done

This is the canonical way to write this. Our make, however doesn't need 
it.

harti


More information about the freebsd-arch mailing list