Menu

SHELL Variable in Make

Help
2010-03-07
2012-07-26
  • Blade of Light16

    Hello,

    I'm using the 3.81 version of make provided here. Currently, I don't have any
    of the typical Unix-style shells installed, so when it runs, it's executing
    via cmd.exe. Commands execute just fine with no problem, but I need this
    makefile to be executed on Unix-like systems as well. I also can't just
    install a shell because I'll be sharing this with other Windows users, too,
    who also don't have any such shell.

    I know how to use variables to have different command names, so that's fine.
    The problem I'm having is detecting whether or not I'm using a Unix-style
    shell or if I'm running something DOS-like. The SHELL variable doesn't update
    to match the actual shell in use, sadly. It defaults to sh.exe and stays that
    unless the variable is manually set (which I prefer to avoid requiring).

    As a work around, I'm testing if the ComSpec variable is defined by the
    environment and setting SHELL to its value if so. This really isn't
    satisfactory since, if I understand correctly, a Windows user explicitly
    specifying a non-DOS-like shell or a Unix-like OS user having a ComSpec
    environment variable would break the functionality.

    Is there a better way to deal with this? Thanks.

     
  • Keith Marshall

    Keith Marshall - 2010-03-08

    The usual way to deal with it is to provide two independent Makefiles, one
    specific to Unix and one for MS-Windows, (perhaps called Makefile.msw). Then
    instruct users on MSW, (who don't have a unixy shell environment such as MSYS
    or Cygwin), to run `make -f Makefile.msw ...'

     
  • Blade of Light16

    I was hoping to avoid any users having to do anything special, but I
    appreciate the help. Thank you.

    I did figure out the override directive, so on Windows the shell indicated by
    ComSpec is forcibly used. That should eliminate one problem, even though it's
    in a way I find kind of distasteful.

    I'm kind of curious about something, actually. The GNU make documentation
    specifically says that if SHELL isn't set, the value from ComSpec is used to
    choose a shell. Why doesn't the SHELL variable reflect that instead of just
    defaulting to sh.exe?

     
MongoDB Logo MongoDB