Discussion:
Shell commands in makefile not working (running Windows XP)
Scott Merz
2003-08-12 19:33:29 UTC
Permalink
Hello everyone



This is my first post here, so if this issue has already been addressed, I
am apologizing ahead of time.



I was tasked to get all of our console C code to compile under Microsoft
Visual Studio. The code is compiled using a GCC cross compiler, so I created
a console makefile that will handle it all from the command line. The next
task was interfacing visual studio with it. This was actually fairly
straightforward, and I created a wrapper visual C++ makefile project with
custom build commands. I overrode each command with calls to a batch file
(NMAKE-BuildUtilityScript.bat) that would, in turn, invoke a Jscript file to
extract the list of source files from the Visual Studio XML based project
file (.vcproj), and write them into a text file. Now this is where the
problems arise.



The console makefile simply has to parse the text file of line delimited
source file names into a variable, so it knows what files to "build". This
should be VERY straightforward using the shell command.



srcFiles = $(shell type srcFiles.txt)



that command should populate srcFiles with a series of space delimited
filenames (since the description of shell in GNU make says that when using
shell, all carriage returns and end of line characters are converted to
spaces). However, subsequent echo calls show that srcFiles remains EMPTY,
thus the shell call is not working. Another thing, even though there is no
SHELL environment variable, 'make' sets it to sh.exe. Even if I call make
with the "-e" argument (which ignores environmental variables) and override
SHELL=%SystemRoot%\system32\cmd.exe, echoing $(SHELL) still brings up
sh.exe. This is very confusing, and I have tried everything I can think of,
and am stuck at the following avenues to place blame:



1. SHELL=sh.exe
2. Windows XP Command Shell
3. MS-DOS in General



I am wondering if when Microsoft implemented their newer XP command shell if
it doesn't support the shell function. Some pertinent information:



Running GNU Make version 3.77

Running GCC version 2.95.2

Running Windows XP version 2002 Service Pack 1



Thanks to any who help.



-Scott Merz



Scott Merz

Software Intern

The InsituGroup

www.insitugroup.net <http://www.insitugroup.net/>
Earnie Boyd
2003-08-12 20:35:50 UTC
Permalink
Make sure that sh.exe isn't in your PATH. The Win32 version will use it
regardless if it finds it.

Earnie.
Post by Scott Merz
Hello everyone
-8<-
Post by Scott Merz
that command should populate srcFiles with a series of space delimited
filenames (since the description of shell in GNU make says that when using
shell, all carriage returns and end of line characters are converted to
spaces). However, subsequent echo calls show that srcFiles remains EMPTY,
thus the shell call is not working. Another thing, even though there is no
SHELL environment variable, 'make' sets it to sh.exe. Even if I call make
with the "-e" argument (which ignores environmental variables) and override
SHELL=%SystemRoot%\system32\cmd.exe, echoing $(SHELL) still brings up
sh.exe. This is very confusing, and I have tried everything I can think of,
1. SHELL=sh.exe
2. Windows XP Command Shell
3. MS-DOS in General
Eli Zaretskii
2003-08-13 06:04:51 UTC
Permalink
Date: Tue, 12 Aug 2003 12:33:29 -0700
The console makefile simply has to parse the text file of line delimited
source file names into a variable, so it knows what files to "build". This
should be VERY straightforward using the shell command.
srcFiles = $(shell type srcFiles.txt)
that command should populate srcFiles with a series of space delimited
filenames (since the description of shell in GNU make says that when using
shell, all carriage returns and end of line characters are converted to
spaces). However, subsequent echo calls show that srcFiles remains EMPTY,
thus the shell call is not working. Another thing, even though there is no
SHELL environment variable, 'make' sets it to sh.exe. Even if I call make
with the "-e" argument (which ignores environmental variables) and override
SHELL=%SystemRoot%\system32\cmd.exe, echoing $(SHELL) still brings up
sh.exe. This is very confusing, and I have tried everything I can think of,
You probably have a sh.exe somewhere on your PATH. Try this:

srcFiles = $(shell cmd.exe /c type srcFiles.txt)

Morale: on a DOS/Windows system, never assume that commands that are
built into the Windows shell can be run without invoking that shell
explicitly.

Btw, if your batch file produces the list of file names, why do you
need to go thru a temporary file srcFiles.txt instead of catching the
output of the batch file directly. E.g., doesn't the following work
for you:

srcFiles = $(shell cmd.exe /c NMAKE-BuildUtilityScript.bat)

? (I'm assuming that the batch file can be modified to print the
list of file names to the standard output instead of a file.)
Scott Merz
2003-08-13 15:53:09 UTC
Permalink
Invoking the shell command the way you suggested causes the following error
to be generated by the makefile:



Unhandled exception filter called from program make

ExceptionCode = c0000005

ExceptionFlags = 0

ExceptionAddress = 41c15a

Access violation: read operation at address 13a825ff



This implies to me that the reason shell is failing could be dependent upon
the cmd.exe windows XP shell interpreter. There is no sh.exe anywhere on my
computer, or anywhere in the path name.



--------------------------------

Eli wrote:



You probably have a sh.exe somewhere on your PATH. Try this:



srcFiles = $(shell cmd.exe /c type srcFiles.txt)



Morale: on a DOS/Windows system, never assume that commands that are

built into the Windows shell can be run without invoking that shell

explicitly.



Btw, if your batch file produces the list of file names, why do you

need to go thru a temporary file srcFiles.txt instead of catching the

output of the batch file directly. E.g., doesn't the following work

for you:



srcFiles = $(shell cmd.exe /c NMAKE-BuildUtilityScript.bat)



? (I'm assuming that the batch file can be modified to print the

list of file names to the standard output instead of a file.)
Scott Merz
2003-08-13 16:39:25 UTC
Permalink
That is what I was thinking. However, I think that since Windows XP doesn't
use a SHELL environment variable, make is setting it as if it was in its
natural environment (hence the sh.exe). I have tried overriding it by
setting SHELL=cmd.exe, yet when I echoed it the value displayed was still
'sh.exe'. Furthermore, I even called make with the -e option to suppress
environment variables and let the user override them, and it still didn't
work.



It's extremely frustrating to have such a small issue hold me up so much. It
seems like if this was an issue between make and command line interpreters,
it would have came up before now with other people. At this point, I'm
considering redesigning how my system is going to do this, probably use a
scripting language to implement parts of this, because cryptic unheard of
issues like this take way too much time to debug/debunk. However anyone else
w/ suggestions is welcome, there has to be some cause for shell throwing
that exception. Thanks a bunch.



-Scott



The Insitu Group

***@insitugroup.net





-----Original Message-----
From: Matt Lavoie [mailto:***@nvidia.com]
Sent: Wednesday, August 13, 2003 9:31 AM
To: 'Scott Merz'
Subject: RE: Shell commands in makefile not working (running Windows XP)



You might try putting the command:

echo SHELL=$(SHELL)

so you can see what make is using for a shell.



You can put SHELL=xxx in the makefile to point it to a given shell.
Scott Merz
2003-08-13 17:03:59 UTC
Permalink
Did you invoke make with the -e option to get that to work?



So by fully qualified you mean no Environment variables in the file path?

i.e.

SHELL=%SystemRoot%\win32\cmd.exe would be WRONG



And

SHELL=C:\Windows\win32\cmd.exe would be CORRECT??



I'm going to try that now.thanks a bunch



-Scott

The Insitu Group

***@insitugroup.net



-----Original Message-----
From: Matt Lavoie [mailto:***@nvidia.com]
Sent: Wednesday, August 13, 2003 9:59 AM
To: 'Scott Merz'
Subject: RE: Shell commands in makefile not working (running Windows XP)



I found that putting a fully qualified path into SHELL= did get make to use
cmd.exe again.
Matt Lavoie
2003-08-13 17:17:53 UTC
Permalink
I'm actually working on a related problem at the moment. I haven't tried to
get it to expand an environment variable in the SHELL command -- I just put
in the full path.

MAKESHELL = C:\windows\SYSTEM32\cmd.exe
SHELL = C:\windows\SYSTEM32\cmd.exe

I first tried setting MAKESHELL (as per docs) but it did not override?

[I'm trying to run gnumake under cygwin with makefiles that work if you
invoke things from a cmd.exe shell, or from a cygwin shell.]

The issue I'm encountering at the moment is that gnumake is creating a
process in this way:

gmake.exe: Entering directory `c:/sw/nvr50/drivers/ddraw'
CreateProcess(C:\windows\SYSTEM32\cmd.exe,C:/windows/SYSTEM32/cmd.exe -c
"c:/sw/tools/win32/MiscBuildTools/nvutil-101 -echo
\"====================\"",...)

Issuing this from the command line directly I find that cmd.exe (on winxp)
is senstive to /C versus -c (*sigh*). Anyone know if there is a way to get
gmake to change that option via some var?

-----Original Message-----
From: Scott Merz [mailto:***@insitugroup.net]
Sent: Wednesday, August 13, 2003 1:04 PM
To: make-***@gnu.org
Subject: RE: Shell commands in makefile not working (running Windows XP)



Did you invoke make with the -e option to get that to work?



So by fully qualified you mean no Environment variables in the file path?

i.e.

SHELL=%SystemRoot%\win32\cmd.exe would be WRONG



And

SHELL=C:\Windows\win32\cmd.exe would be CORRECT??



I'm going to try that now...thanks a bunch



-Scott

The Insitu Group

***@insitugroup.net



-----Original Message-----
From: Matt Lavoie [mailto:***@nvidia.com]
Sent: Wednesday, August 13, 2003 9:59 AM
To: 'Scott Merz'
Subject: RE: Shell commands in makefile not working (running Windows XP)



I found that putting a fully qualified path into SHELL= did get make to use
cmd.exe again.
Scott Merz
2003-08-13 17:21:40 UTC
Permalink
Hmmmm.



invoked make:

make -e -w debug



set SHELL:

SHELL=C:\Windows\Win32\cmd.exe



displayed SHELL:

echo ( $(SHELL) )



Output:

( sh.exe )



SHELL is still set to sh.exe! Must be some sort of incompatibility between
make and the interpreter (looks even more like it the longer I mess with
this thing).



-----Original Message-----
From: make-w32-bounces+scott.merz=***@gnu.org
[mailto:make-w32-bounces+scott.merz=***@gnu.org] On Behalf Of
Scott Merz
Sent: Wednesday, August 13, 2003 10:04 AM
To: make-***@gnu.org
Subject: RE: Shell commands in makefile not working (running Windows XP)



Did you invoke make with the -e option to get that to work?



So by fully qualified you mean no Environment variables in the file path?

i.e.

SHELL=%SystemRoot%\win32\cmd.exe would be WRONG



And

SHELL=C:\Windows\win32\cmd.exe would be CORRECT??



I'm going to try that now.thanks a bunch



-Scott

The Insitu Group

***@insitugroup.net



-----Original Message-----
From: Matt Lavoie [mailto:***@nvidia.com]
Sent: Wednesday, August 13, 2003 9:59 AM
To: 'Scott Merz'
Subject: RE: Shell commands in makefile not working (running Windows XP)



I found that putting a fully qualified path into SHELL= did get make to use
cmd.exe again.
Scott Merz
2003-08-13 17:39:02 UTC
Permalink
Right. And I finally got it to work this time.

So SHELL=C:\Windows\System32\cmd.exe

However, when I go to use the shell command, it still gives me the exception
error.

So back to ground zero.



-Scott

-----Original Message-----
From: Matt Lavoie [mailto:***@nvidia.com]
Sent: Wednesday, August 13, 2003 10:28 AM
To: 'Scott Merz'
Subject: RE: Shell commands in makefile not working (running Windows XP)



I'm overriding SHELL in the MAKEFILE, not in the environment.

-----Original Message-----
From: Scott Merz [mailto:***@insitugroup.net]
Sent: Wednesday, August 13, 2003 1:22 PM
To: make-***@gnu.org
Subject: RE: Shell commands in makefile not working (running Windows XP)

Hmmmm...



invoked make:

make -e -w debug



set SHELL:

SHELL=C:\Windows\Win32\cmd.exe



displayed SHELL:

echo ( $(SHELL) )



Output:

( sh.exe )



SHELL is still set to sh.exe! Must be some sort of incompatibility between
make and the interpreter (looks even more like it the longer I mess with
this thing).



-----Original Message-----
From: make-w32-bounces+scott.merz=***@gnu.org
[mailto:make-w32-bounces+scott.merz=***@gnu.org] On Behalf Of
Scott Merz
Sent: Wednesday, August 13, 2003 10:04 AM
To: make-***@gnu.org
Subject: RE: Shell commands in makefile not working (running Windows XP)



Did you invoke make with the -e option to get that to work?



So by fully qualified you mean no Environment variables in the file path?

i.e.

SHELL=%SystemRoot%\win32\cmd.exe would be WRONG



And

SHELL=C:\Windows\win32\cmd.exe would be CORRECT??



I'm going to try that now...thanks a bunch



-Scott

The Insitu Group

***@insitugroup.net



-----Original Message-----
From: Matt Lavoie [mailto:***@nvidia.com]
Sent: Wednesday, August 13, 2003 9:59 AM
To: 'Scott Merz'
Subject: RE: Shell commands in makefile not working (running Windows XP)



I found that putting a fully qualified path into SHELL= did get make to use
cmd.exe again.
Scott Merz
2003-08-13 18:03:58 UTC
Permalink
Hmmmm

Looks like gmake calls any command line interpreter with -c probably because
of its original days when it was developed on Unix. Thus, to change how
gmake specifies that parameter, you would either have to (as far as I know)
change the source code, which you obviously aren't going to want to do.
Maybe there is a more windows friendly version of gmake available to you
which would recognize the difference in command line switches between Unix
and Win32 systems?? Other than that I don't think there is any way to change
the way that CreateProcess() is invoked inernally. Sorry man.



Scott Merz

Software Intern

The Insitu Group

Web: <http://www.insitugroup.net> www.insitugroup.net

Email: <mailto:***@insitugroup.net> ***@insitugroup.net



-----Original Message-----
From: Matt Lavoie [mailto:***@nvidia.com]
Sent: Wednesday, August 13, 2003 10:18 AM
To: 'Scott Merz'; make-***@gnu.org
Subject: RE: Shell commands in makefile not working (running Windows XP)



I'm actually working on a related problem at the moment. I haven't tried to
get it to expand an environment variable in the SHELL command -- I just put
in the full path.



MAKESHELL = C:\windows\SYSTEM32\cmd.exe
SHELL = C:\windows\SYSTEM32\cmd.exe

I first tried setting MAKESHELL (as per docs) but it did not override?



[I'm trying to run gnumake under cygwin with makefiles that work if you
invoke things from a cmd.exe shell, or from a cygwin shell.]



The issue I'm encountering at the moment is that gnumake is creating a
process in this way:



gmake.exe: Entering directory `c:/sw/nvr50/drivers/ddraw'
CreateProcess(C:\windows\SYSTEM32\cmd.exe,C:/windows/SYSTEM32/cmd.exe -c
"c:/sw/tools/win32/MiscBuildTools/nvutil-101 -echo
\"====================\"",...)



Issuing this from the command line directly I find that cmd.exe (on winxp)
is senstive to /C versus -c (*sigh*). Anyone know if there is a way to get
gmake to change that option via some var?

-----Original Message-----
From: Scott Merz [mailto:***@insitugroup.net]
Sent: Wednesday, August 13, 2003 1:04 PM
To: make-***@gnu.org
Subject: RE: Shell commands in makefile not working (running Windows XP)

Did you invoke make with the -e option to get that to work?



So by fully qualified you mean no Environment variables in the file path?

i.e.

SHELL=%SystemRoot%\win32\cmd.exe would be WRONG



And

SHELL=C:\Windows\win32\cmd.exe would be CORRECT??



I'm going to try that now...thanks a bunch



-Scott

The Insitu Group

***@insitugroup.net



-----Original Message-----
From: Matt Lavoie [mailto:***@nvidia.com]
Sent: Wednesday, August 13, 2003 9:59 AM
To: 'Scott Merz'
Subject: RE: Shell commands in makefile not working (running Windows XP)



I found that putting a fully qualified path into SHELL= did get make to use
cmd.exe again.
Matt Lavoie
2003-08-13 19:37:07 UTC
Permalink
Scott, I don't know if this is useful info for the problem you are
encountering, but the fix for my issue is to delete SHELL from the
environment and make sure that sh.exe is not in my PATH. Then my makes are
working the same when run under a bash shell (cygwin on WinXP) or cmd.exe on
WinXP.

-----Original Message-----
From: Scott Merz [mailto:***@insitugroup.net]
Sent: Wednesday, August 13, 2003 12:39 PM
To: make-***@gnu.org
Subject: RE: Shell commands in makefile not working (running Windows XP)



That is what I was thinking. However, I think that since Windows XP doesn't
use a SHELL environment variable, make is setting it as if it was in its
natural environment (hence the sh.exe). I have tried overriding it by
setting SHELL=cmd.exe, yet when I echoed it the value displayed was still
'sh.exe'. Furthermore, I even called make with the -e option to suppress
environment variables and let the user override them, and it still didn't
work.



It's extremely frustrating to have such a small issue hold me up so much. It
seems like if this was an issue between make and command line interpreters,
it would have came up before now with other people. At this point, I'm
considering redesigning how my system is going to do this, probably use a
scripting language to implement parts of this, because cryptic unheard of
issues like this take way too much time to debug/debunk. However anyone else
w/ suggestions is welcome, there has to be some cause for shell throwing
that exception. Thanks a bunch.



-Scott



The Insitu Group

***@insitugroup.net <mailto:***@insitugroup.net>





-----Original Message-----
From: Matt Lavoie [mailto:***@nvidia.com]
Sent: Wednesday, August 13, 2003 9:31 AM
To: 'Scott Merz'
Subject: RE: Shell commands in makefile not working (running Windows XP)



You might try putting the command:

echo SHELL=$(SHELL)

so you can see what make is using for a shell.



You can put SHELL=xxx in the makefile to point it to a given shell.
Continue reading on narkive:
Search results for 'Shell commands in makefile not working (running Windows XP)' (Questions and Answers)
15
replies
what kind of laptop should i get?
started 2007-11-16 15:09:49 UTC
laptops & notebooks
Loading...