OK, I figured this one out. The problem is that the ‘files’ variable is global and not local and that obviously causes bad results. Solution is to do the following for the gen_lib rule:
rule gen_lib ( main-target-name : sources + : requirements * : default-build * : usage-requirements * )
{
local files ;
for local file in $(sources)
{
gen-c $(file:B) : $(file) ;
files += $( file:B) ;
}
lib $(main-target-name) : $(files) : $(requirements) <implicit-dependency>$(files:B) : $(default-build) : $(usage-requirements) ;
}
Thanks,
Chris
From: Nogradi, Chris
Sent: Thursday, February 24, 2011 4:40 PM
To: 'Boost.Build developer's and user's list'
Subject: Generating C file from C file
I am attempting to generate a C file from another C file and then create a library from the generated sources (~2000 files). I tried this and it causes bjam to use massive amounts of memory and time:
type.register GEN_C : : C ;
generators.register-standard gen.generate : C : GEN_C(GEN_%) ;
rule generate ( targets * : sources * : properties * )
{
}
actions generate
{
“gen_c.py" -f $(>) -o $(<)
}
rule gen_lib ( main-target-name : sources + : requirements * : default-build * : usage-requirements * )
{
for local file in $(sources)
{
gen-c $(file:B) : $(file) ;
files += $( file:B) ;
}
lib $(main-target-name) : $(files) : $(requirements) <implicit-dependency>$(files:B) : $(default-build) : $(usage-requirements) ;
}
gen_lib lib : [ glob *.c ] ;
There is obviously a better solution. Can someone suggest what to do here? I looked at the custom generator example in the manual and I am not sure it will do what I want. Can someone confirm that custom generators are the right choice
here? Will this solve the memory and time problem?
Thanks,
Chris