[jamming] Checking variable on a target

Dean Ashton dean.ashton at ntlworld.com
Mon Nov 22 03:23:49 PST 2004


Hi Alen,

You're right, of course, that 'if' can work in an action - as it's the name of an executable. I tried your example line on a command prompt, and - unsurprisingly - it worked exactly as you described. However, I put it into my action as follows:

	actions together piecemeal quietly WriteNeedLibs bind NEEDLIBS
	{
		if not "$(NEEDLIBS)" == "" echo $(NEEDLIBS) >> $(<:S=.rsp)	
	}

..only to find that Jam expands "$(NEEDLIBS)" (note the quotation marks) to an empty string. In order to get the comparison to work from a jamfile I have to use " $(NEEDLIBS) " and compare against "  ".. which is a bit of a hack, but which works well.

Another hack that we've found is to call a different echo function that doesn't output rubbish when passed a null string.. 

Thanks again for the help!

Dean

 
> From: "Alen Ladavac" <alenl-ml at croteam.com>
> Date: 2004/11/22 Mon AM 11:58:41 GMT
> To: <jamming at perforce.com>
> Subject: Re: Re: [jamming] Checking variable on a target
> 
> > For the first point, inside an action I'm limited to external commands
> only.
> 
> Hm... I was looking at this piece in the original Jamfile:
> 
> <snip>
> if $(NT) && $(MSVCNT)
> {
>  actions updated together piecemeal Archive
>  {
>  if exist $(<) set _$(<:B)_=$(<)
>  $(AR) /out:$(<) %_$(<:B)_% $(>)
>  }
> 
> </snip>
> 
> Judging that "if" is ok to use.
> 
> Btw, with CMD.exe, del and mkdir are internal commands as well, aren't they?
> Perhaps you are looking at the wrong problem.
> 
> > 'If', in the context in your example, can't work as you describe.
> $(NEEDLIBS) has already been expanded, causing the call to DOS 'if' to fail.
> 
> Sorry, my bad. It should have been this:
> 
> if not "$(LINKLIBS)"=="" echo $(LINKLIBS) >> $(<:S=.rsp)
> 
> Notice the quotes around the left side of comparison operator. This is the
> standard trick for testing for empty string in an envvar.
> 
> > Also, having to have the 'if' and the command on a single line tends to
> screw up the redirect to my linker response file.
> 
> Strange:
> 
> if not "foo bar"=="" echo something >>test.txt
> 
> works ok for me.
> 
> Cheers,
> Alen


-----------------------------------------
Email provided by http://www.ntlhome.com/





More information about the jamming mailing list