0

I have a very simple makefile that I'm trying to execute in git-bash on a Windows 10 machine.

The contents of the makefile are:

start:
    source env.sh

Where env.sh is a local file that exists.

If I execute the command make start I receive the following error:

process_begin: CreateProcess(NULL, source env.sh, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [Makefile:2: start] Error 2

However, if I execute source env.sh at the command prompt all is well and I receive no error at all.

I've seen other posts like this Windows 10 Makefile error make (e=2): The system cannot find the file specified which report a similar error, but the linked question is to do with docker being on the path which I don't think applies here.

Is there any reason why the makefile errors but typing the command does not?

t_warsop
  • 1,170
  • 2
  • 24
  • 38
  • Is that really the complete recipe? Just `source env.sh` and nothing else? Because that won't actually do anything. – MadScientist Sep 16 '21 at 13:01

1 Answers1

0

On Windows by default, GNU make always runs the Windows cmd.exe shell. The recipe that you're running here is a bash command.

You say it works at the command prompt but that's because the command prompt you're using is from Git bash; if you opened a Windows terminal and typed that command it wouldn't work.

If you want to use a different shell than the default you need to set the SHELL make variable in your makefile:

SHELL := <path to git bash>
MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • Using `echo $(SHELL)` in my makefile outputs `C:/Program Files/Git/usr/bin/sh.exe`, so I don't think cmd is being used here. – t_warsop Sep 15 '21 at 17:06
  • Well, I don't know what to tell you, but that error message is what you get when make thinks it's running `cmd.exe`, where `source` is not a shell built-in. I recommend you explicitly set SHELL as I mentioned above and see if it works. Or, if you have that `bin` directory in your `PATH` you could just use `SHELL := sh.exe` and see if that works. – MadScientist Sep 15 '21 at 17:51
  • I've done that, still get the same error as in the original question – t_warsop Sep 16 '21 at 09:30
  • OK, try this: change your `source env.sh` to `. env.sh` which is the POSIX compliant way to write this (`source` is a bash extension to the POSIX standard). Do you have a `bash.exe` in your Git bin directory? If you set `SHELL` to the `bash.exe` does that failure go away when you use `source env.sh`? – MadScientist Sep 16 '21 at 13:03