[jamming] Pre-parsing source files before building

Chris syndicate_dragon at yahoo.com
Thu Aug 23 10:34:02 PDT 2007


The order DOES matter for me, because when I parse these generated files, the names of the resulting files are the same. I parse them "in-place" so to speak.

Is the only way to get this to work is to rename them once parsed? Or can I force GenFiles to run before Main?

Thanks
Chris


Craig Allsop <cjamallsop at gmail.com> wrote: Hi Chris,

The GenFile rule is designed to run a tool that can process a source
into another source. You just have to make sure that the output target
is your input target for the Main. Order isn't important because Jam
creates an in-memory dependency tree before it determines what to
update, thus your dependencies must be correct. Try just this:

GenFile out_genfile1.c : tool genfile1.c ;
Main target : out_genfile1.c ;

Here, out_genfile1.c is preprocessed by "tool" from genfile1.c - on
windows it will expect to find tool.exe - so you can replace the name
with your custom tool. Put your tool in the same directory for now and
try the above. Once you have that working, you can move on and process
your list of genfile's by calling GenFile for each one.

Craig.


On 8/23/07, Chris  wrote:
> Maybe I should have been more specific. :)
>
> srcfile1.c and genfile1.c are not related. genfile1.c etc are output by a
> design tool that we use.
>
> Here is another example of something I tried.
>
>
> rule PreParse
> {
> Depends $(1) : $(2) ;
> }
>
> actions PreParse
> {
> #just a place holder for the script I need to run
> echo "Preparsing!"
> }
>
> rule AuxSrc
> {
>    Depends $(1) : $(2) ;
>    PreParse $(1) : $(2) ;
>    Objects $(2) ;
> }
>
> rule BuildLib
> {
>    Depends $(1) : $(2:S=.OBJ) ;
> }
>
> actions BuildLib
> {
> $(AR) r $(AUXLIB) $(AUXOBJ)
> }
>
> AuxSrc $(AUXLIB) : $(AUXSRC) ;
> BuildLib $(AUXLIB) : $(AUXSRC) ;
> Main  $(LINKTARGET) : $(SRC) ;
> Convert $(FINALTARGET) : $(LINKTARGET) ;
>
>
> This didn't work, because the source files were being compiled before the
> PreParse rule was being invoked. No matter what I did, I couldn't get the
> PreParse action to run before the Objects was invoked.
>
> I think the problem is that when the source files are generated, they're
> newer than the target, so the tool assumes they need to built - which is
> true, except that I need to do this other step to them first.
>
> I feel like I'm close, but there is some fundamental idea I'm missing. Any
> more ideas?
>
> Thanks
> Chris
>
>
> Craig Allsop  wrote:
>  Hi Chris,
>
> I'm assuming srcfile1.c is converted to genfile1.c and then linked in
> the final program? So to make it easier to write in jam, can we just
> add a gen prefix for the generated files so that srcfile1.c is
> converted to gensrcfile1.c? Therefore you would do this...
>
> LINKTARGET = flash.hex
> FINALTARGET = app.bin
> MAINSRC = srcfile1.c srcfile2.c ;
> for i in $(MAINSRC)
> {
>  # this will run: yourpreparsetoolhere outfile infile
>  GenFile gen$(i) : yourpreparsetoolhere $(i) ;
> }
> Main $(LINKTARGET) : gen$(MAINSRC) ;
> Convert $(FINALTARGET) : $(LINKTARGET) ;
> Depends all : $(FINALTARGET) ;
>
> Only pass the generated sources to Main, gen$(MAINSRC) will be
> expanded to prefix all source with "gen". If you have others you don't
> then just list with as extras.
>
> Hope that helps.
>
> Craig.
>
> On 8/21/07, Chris wrote:
> > We have a tool which generates some of our source files. Unfortunately,
> the
> > files need to be touched up a bit before our cranky compiler can use them.
> I
> > am trying to make this pre-parsing an automated part of the jam build
> > process, but I'm having some trouble finding the right magic words to make
> > it work. The problem seems to be that the files may already exist and need
> > not be parsed again if they have not changed from the previous build. I'm
> > having a hard time coming up with a rule/dependencies that can detect if
> > generated source files are newer than the final target and run the
> > pre-parsing script on them before compiling them. The script we have
> > automatically fixes all of the generated files, so it only needs to run
> > once.
> >
> > Here's what I have so far, which seems to work except for the pre-parsing
> > step. AUXSRC are the sources generated by the tool. There are custom
> actions
> > for Cc and Link to deal with our stupid compiler. I can detail those if
> > someone thinks it necessary, but for brevity they are omitted here. The
> > "Convert" rule/action handles converting the linker output to our download
> > format.
> >
> > LINKTARGET = flash.hex
> > FINALTARGET = app.bin
> > MAINSRC = srcfile1.c srcfile2.c ;
> > AUXSRC = genfile1.c genfile2.c ;
> > SRC = $(MAINSRC) $(AUXSRC) ;
> >
> > Main $(LINKTARGET) : $(SRC) ;
> > Convert $(FINALTARGET) : $(LINKTARGET) ;
> > Depends all : $(FINALTARGET) ;
> >
> >
> > Thanks,
> > Chris
> >
> > ________________________________
> > Yahoo! oneSearch: Finally, mobile search that gives answers, not web
> links.
> > _______________________________________________
> > jamming mailing list - jamming at perforce.com
> > http://maillist.perforce.com/mailman/listinfo/jamming
> >
> >
>
>
>
>  ________________________________
> Moody friends. Drama queens. Your life? Nope! - their life, your story.
>  Play Sims Stories at Yahoo! Games.
>
>



"Gee, Thanks. You made me appreciate life by showing me how badly my funeral will suck." - Bender, Futurama
       
---------------------------------
Moody friends. Drama queens. Your life? Nope! - their life, your story.
 Play Sims Stories at Yahoo! Games. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://maillist.perforce.com/pipermail/jamming/attachments/20070823/050aabb4/attachment.html


More information about the jamming mailing list