[jamming] Checking variable on a target

Dean Ashton dean.ashton at ntlworld.com
Mon Nov 22 01:53:11 PST 2004

As part of our link handling (where we may have many items in the NEEDLIBS and LINKLIBS variables), I have a Link rule that looks like this:

rule Link
	MODE on $(<) = $(EXEMODE) ;
	Chmod $(<) ;
	StartLink $(<) : $(>) ;
	WriteLinkObjs $(<) : $(>) ;
	WriteNeedLibs $(<) : $(>) ;
	WriteLinkLibs $(<) : $(>) ;
	FinishLink $(<) : $(>) ;

The actions used above are as follows:

	actions quietly ignore StartLink
		$(RM) $(<:S=.rsp) 2>nul
		echo $(LINKFLAGS) /out:$(<) $(UNDEFS) /pdb:$(<:S=$(SUFPDB)) > $(<:S=.rsp)

	actions together piecemeal quietly WriteLinkObjs
		echo $(>) >> $(<:S=.rsp)
	actions together piecemeal quietly WriteNeedLibs bind NEEDLIBS
		echo $(NEEDLIBS) >> $(<:S=.rsp)
	actions together piecemeal quietly WriteLinkLibs
		echo $(LINKLIBS) >> $(<:S=.rsp)
	actions FinishLink bind NEEDLIBS
		$(LINK) @$(<:S=.rsp)

My problem is that our Jamrules file needs to handle the case where our .exe has NEEDLIBS set (as you get when you use the standard LinkLibraries rule on an executable), and also where the .exe can get away without any additional libraries.

The problem I have (on Windows, naturally), is that if NEEDLIBS is not set (ie: I haven't needed to call LinkLibraries in my Jamfile), then the action 'WriteNeedLibs' fails.. $(NEEDLIBS) expands to an empty string, and Windows/DOS 'echo' just outputs 'ECHO is on'. Which causes my link to fail (as you would expect, I don't have a file called 'ECHO is on.obj' :))

How can I make sure that the action 'WriteNeedLibs' is only called when there's something in $(NEEDLIBS). NEEDLIBS is defined on the .executable (rather than being global), but I can't seem to use 'NEEDLIBS on (my target name)' in a conditional expression in my Link rule.

I've also tried adding an additional latch-style variable to LinkLibraries (formed from the executable name and a suffix eg: 'Main.exe-has-needlibs'), and checking that, but to no avail.

If anyone has any ideas how I can get this conditional behaviour to work, I'd be really happy to hear them!

Many thanks,


Dean Ashton, Senior Programmer
Sony Computer Entertainment Europe (Cambridge)

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

More information about the jamming mailing list