help-make
[Top][All Lists]
Advanced

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

Re: How to check if a file exists?


From: David Boyce
Subject: Re: How to check if a file exists?
Date: Wed, 21 May 2008 09:57:47 -0400

On Wed, May 21, 2008 at 5:53 AM, Hongliang Wang <address@hidden> wrote:
>
> Hi David

No need to address me directly - it's an open discusssion.

> =======================================================
> D:\data\dev\jhwcu\src\je\win>gmake
> compiling bitrock/hvr_bitrock.xml ...
> d:/perl/bin/perl "-I../../../src/jp/perl" ../../../src/jp/perl/rm.pl 
> ../../../..
> /distr/win32/*.exe
> 'd:\program files\BitRock InstallBuilder Enterprise 5.4.7\bin\builder.exe' 
> build
>  'bitrock/hvr_bitrock.xml' windows && test -e ../../../../distr/win32/*.exe
> d:\program files\BitRock InstallBuilder Enterprise 5.4.7\bin\builder.exe: no 
> suc
> h device or address
> gmake: *** [kit] Error 127
> ========================================================
>
> I guess the reason is that gmake on Windows is wrongly invoking the compiling 
> process and was asking builder.exe to take parameter && test.

I can't say what's wrong, but it's absolutely critical to understand
that "gmake" is not involved at this point. The #1 most important
thing to understand about make is that it has no idea what the
commands do - it takes the strings of text that you supply in the
makefile, does some variable substitution, throws them over to the
shell, and checks the exit status when the shell returns. So this is
not a make issue, it's a shell issue. The corollary of this is that
you can and should test these commands outside of make and only drive
them via make once they're known to be correct.

> However, my code does not work properly either,
> ========================================================
> compiling bitrock/hvr_bitrock.xml ...
> d:/perl/bin/perl "-I../../../src/jp/perl" ../../../src/jp/perl/rm.pl 
> ../../../..
> /distr/win32/*.exe
> 'd:\program files\BitRock InstallBuilder Enterprise 5.4.7\bin\builder.exe' 
> build
>  'bitrock/hvr_bitrock.xml' windows
> if test -e ../../../../distr/win32/*.exe; \
> then echo ' compiling success! ...'; \
> else echo ' compiling failes ...'; \
> fi
>  compiling failes ...
> =========================================================

This is obvious and it's what I alluded to before. Simply printing
"succeeded" or "failed" to standard output can't possibly affect the
exit code. Bottom line, you need a command which will exit with a
nonzero status IFF the specified file does not exist. I can't tell you
what that command is because you have some kind of customized
environment which could be Cygin, MKS, MSys, GNUWin32, U/Win, or some
combination. For me, "test -e *.exe" works fine on Windows XP; I'm
using a GNUWin32 "test" command. Also, "&&" works fine with both Unix
and Windows shells. But in any case this is not a make issue, it's an
issue with shell commands in your environment.

There are many other commands which can return nonzero if a file
doesn't exist. The Windows shell has "if exist ...", or you could make
a one-liner using Perl, or "copy foo.exe NUL" would probably work,
etc. In your logic above you could replace the echo statements with
"exit 0" and "exit 1" respectively and it would probably work.

-David Boyce




reply via email to

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