Search code examples
c++windowscross-platformbjamjam

Change of file extension in jam script


How can i change extension from an input files in jam script. On linux box i have following working code -

for local var in $(objFiles)
{
    local objName = [ SHELL "var1=$(var); echo ${var1%.cpp}.obj" ] ;
    obj $(objName) : $(var) : $(properties) ;
}

1st line within for loop picks cpp file name and change its extention from <File>.cpp to <File>.obj. I need to covert these changes compatible to windows platform. I think some module in boost build process would have provided some way to do this but google search in this didnt helped much.

What changes should i do in above code so that objName would contain obj file extension and these changes remains compatible across platform (specially win/ linux).


Solution

  • I'm not familiar with Boost.Jam, but I suspect it just works the same way as in the regular Jam. There are several selector/replacement operators you can apply on variables. In this case you want to use S= for changing the file name suffix:

    local objName = $(var:S=.obj) ;
    

    In the regular Jam there is a pre-defined OS-dependent variable SUFOBJ which should be used instead of hard-coding ".obj". Not sure, if it is available in Boost.Jam as well. If so, you can use:

    local objName = $(var:S=$(SUFOBJ)) ;