help-make
[Top][All Lists]
Advanced

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

Re: Why does the shell I invoke Make with have an effect on its output?


From: Eli Zaretskii
Subject: Re: Why does the shell I invoke Make with have an effect on its output?
Date: Tue, 08 Mar 2022 14:06:11 +0200

> Date: Tue, 08 Mar 2022 05:06:41 +0000
> From: "Peter0x44" <peter0x44@snopyta.org>
> 
> SHELLTYPE := posix
> ifeq (.exe, $(findstring .exe,$(ComSpec)))
>       SHELLTYPE := msdos
> endif
> 
> default:
>       $(info SHELLTYPE is $(SHELLTYPE))
>       del
> 
> I am running it under Windows, using GNU Make 4.2
> 
> Note that in all cases, I have the executable `sh.exe` present in the PATH.
> It is busybox-w32, renamed to sh.exe.
> https://frippery.org/busybox
> 
> `del` is only present in the Makefile because it is a cmd.exe builtin command,
> so if the build rules are being executed using cmd.exe, it should show "The
> syntax of the command is incorrect.", while if it is a UNIX shell, it should
> show an error relating to CreateProcess failing.
> 
> If I invoke this Makefile from cmd.exe, I get this output:
> 
> SHELLTYPE is msdos
> del
> process_begin: CreateProcess(NULL, del, ...) failed.
> make (e=2): The system cannot find the file specified.
> make: *** [Makefile:8: default] Error 2
> 
> If I invoke it from sh.exe, I get this different output:
> make
> SHELLTYPE is posix
> del
> process_begin: CreateProcess(NULL, del, ...) failed.
> make (e=2): The system cannot find the file specified.
> make: *** [Makefile:8: default] Error 2
> 
> Does anyone know why does the shell I invoke the Makefile with determines
> whether it outputs "msdos" or "posix"?

Are you sure your sh.exe lets Make see the ComSpec environment
variable as it is defined by Windows?  Maybe it's COMSPEC instead, or
maybe sh.exe removes that variable entirely from the environment
passed to Make?

> The built rules for both are *not* being
> executed using cmd.exe, as you can tell by the error when trying to invoke
> `del`, and the build rules of both Makefiles are being executed with the same
> shell.

As a special "feature", the MS-Windows port of GNU Make uses sh.exe as
its shell if it finds it on PATH.  If you want to countermand that,
you need to say explicitly

  SHELL = cmd.exe

in your Makefile.



reply via email to

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