Re: The right way to invoke sh from a freebsd makefile?
On 9/22/2013 6:18 PM, Ian Lepore wrote: What's the right way to launch the bourne shell from a makefile? I had assumed the ${SHELL} variable would be set to the right copy of /bin/sh (like maybe the one in tmp or legacy at various stages). It appears that that's not the case, and ${SHELL} is whatever comes from the environment, which can lead to using csh or bash or whatever. I see some of our makefiles use just a bare sh which seems reasonable to me, but I don't want to glitch this in src/include/Makefile again. The goal is to run a script in src/include/Makefile by launching sh with the script name (as opposed to launching the script and letting the #! do its thing, which doesn't work if the source dir is mounted noexec). -- Ian Grepping the Makefiles in the tree, 'sh' is the very common. I see around 157 users of this pattern. 13 use /bin/sh directly. Also consider that it is highly likely, if not required, that a /bin/sh will exist. Calling 'sh' specifically is definitely more proper than ${SHELL} since it is an sh script. -- Regards, Bryan Drewery signature.asc Description: OpenPGP digital signature
Re: The right way to invoke sh from a freebsd makefile?
On Sun, Sep 22, 2013 at 05:18:25PM -0600, Ian Lepore wrote: What's the right way to launch the bourne shell from a makefile? I had assumed the ${SHELL} variable would be set to the right copy of /bin/sh (like maybe the one in tmp or legacy at various stages). It appears that that's not the case, and ${SHELL} is whatever comes from the environment, which can lead to using csh or bash or whatever. I see some of our makefiles use just a bare sh which seems reasonable to me, but I don't want to glitch this in src/include/Makefile again. The goal is to run a script in src/include/Makefile by launching sh with the script name (as opposed to launching the script and letting the #! do its thing, which doesn't work if the source dir is mounted noexec). I think BUILDENV_SHELL is what you are looking for. For this specific case, I think instead of '#!/bin/sh', maybe '#!/usr/bin/env sh' may be preferable. Glen pgp779XJY5Eid.pgp Description: PGP signature
Re: The right way to invoke sh from a freebsd makefile?
On Sun, 2013-09-22 at 19:27 -0400, Glen Barber wrote: On Sun, Sep 22, 2013 at 05:18:25PM -0600, Ian Lepore wrote: What's the right way to launch the bourne shell from a makefile? I had assumed the ${SHELL} variable would be set to the right copy of /bin/sh (like maybe the one in tmp or legacy at various stages). It appears that that's not the case, and ${SHELL} is whatever comes from the environment, which can lead to using csh or bash or whatever. I see some of our makefiles use just a bare sh which seems reasonable to me, but I don't want to glitch this in src/include/Makefile again. The goal is to run a script in src/include/Makefile by launching sh with the script name (as opposed to launching the script and letting the #! do its thing, which doesn't work if the source dir is mounted noexec). I think BUILDENV_SHELL is what you are looking for. For this specific case, I think instead of '#!/bin/sh', maybe '#!/usr/bin/env sh' may be preferable. Glen No, BUILDENV_SHELL is a special thing... it's used when you make buildenv to chroot into a cross-build environment to work interactively. I added that long ago because I can't live in a csh shell (I mean, I can't do anything, I'm totally lost), and I wanted a way to have make buildenv put me right into bash (of course, you have to have bash in the chroot). The flavor of hashbang to use shouldn't matter, since what I'm after here is launching the shell to run the script without using the hashbang mechanism. -- Ian ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
Re: The right way to invoke sh from a freebsd makefile?
On Sun, Sep 22, 2013 at 05:37:51PM -0600, Ian Lepore wrote: On Sun, 2013-09-22 at 19:27 -0400, Glen Barber wrote: On Sun, Sep 22, 2013 at 05:18:25PM -0600, Ian Lepore wrote: What's the right way to launch the bourne shell from a makefile? I had assumed the ${SHELL} variable would be set to the right copy of /bin/sh (like maybe the one in tmp or legacy at various stages). It appears that that's not the case, and ${SHELL} is whatever comes from the environment, which can lead to using csh or bash or whatever. I see some of our makefiles use just a bare sh which seems reasonable to me, but I don't want to glitch this in src/include/Makefile again. The goal is to run a script in src/include/Makefile by launching sh with the script name (as opposed to launching the script and letting the #! do its thing, which doesn't work if the source dir is mounted noexec). I think BUILDENV_SHELL is what you are looking for. For this specific case, I think instead of '#!/bin/sh', maybe '#!/usr/bin/env sh' may be preferable. Glen No, BUILDENV_SHELL is a special thing... it's used when you make buildenv to chroot into a cross-build environment to work interactively. I added that long ago because I can't live in a csh shell (I mean, I can't do anything, I'm totally lost), and I wanted a way to have make buildenv put me right into bash (of course, you have to have bash in the chroot). Ah, right. Thanks for the sanity check. The flavor of hashbang to use shouldn't matter, since what I'm after here is launching the shell to run the script without using the hashbang mechanism. You can hard-code /bin/sh directly, but what I was getting at with the '#!/usr/bin/env sh' is that the 'sh' interpreter of the build environment could be used (instead of /bin/sh directly). Then you don't need to worry about the path to sh(1). Glen pgp4Pj5uSDccR.pgp Description: PGP signature
Re: The right way to invoke sh from a freebsd makefile?
On Sun, 2013-09-22 at 19:45 -0400, Glen Barber wrote: On Sun, Sep 22, 2013 at 05:37:51PM -0600, Ian Lepore wrote: On Sun, 2013-09-22 at 19:27 -0400, Glen Barber wrote: On Sun, Sep 22, 2013 at 05:18:25PM -0600, Ian Lepore wrote: What's the right way to launch the bourne shell from a makefile? I had assumed the ${SHELL} variable would be set to the right copy of /bin/sh (like maybe the one in tmp or legacy at various stages). It appears that that's not the case, and ${SHELL} is whatever comes from the environment, which can lead to using csh or bash or whatever. I see some of our makefiles use just a bare sh which seems reasonable to me, but I don't want to glitch this in src/include/Makefile again. The goal is to run a script in src/include/Makefile by launching sh with the script name (as opposed to launching the script and letting the #! do its thing, which doesn't work if the source dir is mounted noexec). I think BUILDENV_SHELL is what you are looking for. For this specific case, I think instead of '#!/bin/sh', maybe '#!/usr/bin/env sh' may be preferable. Glen No, BUILDENV_SHELL is a special thing... it's used when you make buildenv to chroot into a cross-build environment to work interactively. I added that long ago because I can't live in a csh shell (I mean, I can't do anything, I'm totally lost), and I wanted a way to have make buildenv put me right into bash (of course, you have to have bash in the chroot). Ah, right. Thanks for the sanity check. The flavor of hashbang to use shouldn't matter, since what I'm after here is launching the shell to run the script without using the hashbang mechanism. You can hard-code /bin/sh directly, but what I was getting at with the '#!/usr/bin/env sh' is that the 'sh' interpreter of the build environment could be used (instead of /bin/sh directly). Then you don't need to worry about the path to sh(1). Glen My point is that the #! isn't used at all in this case, it doesn't matter what's there. Try this... echo echo foo /tmp/foo sh /tmp/foo Not only does it not need the hashbang, the script doesn't even have to be executable when you launch sh and name a script on the command line, which is just what's needed to run a script from a directory mounted with the noexec flag. -- Ian ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
Re: The right way to invoke sh from a freebsd makefile?
On Sun, Sep 22, 2013 at 05:56:07PM -0600, Ian Lepore wrote: You can hard-code /bin/sh directly, but what I was getting at with the '#!/usr/bin/env sh' is that the 'sh' interpreter of the build environment could be used (instead of /bin/sh directly). Then you don't need to worry about the path to sh(1). My point is that the #! isn't used at all in this case, it doesn't matter what's there. Try this... echo echo foo /tmp/foo sh /tmp/foo Not only does it not need the hashbang, the script doesn't even have to be executable when you launch sh and name a script on the command line, which is just what's needed to run a script from a directory mounted with the noexec flag. Ah - maybe it's just late. I see what you mean now. Thanks. Glen pgpPhTPHL9FbJ.pgp Description: PGP signature