List Info

Thread: Re: Pre-parsing source files before building




Re: Pre-parsing source files before building
country flaguser name
United States
2007-08-24 10:03:47
Part of the problem is that I am limited to an 8.3 DOS name. So, it's really hard to come up with a different name that is legal for the compiler.

However, I did not think of putting the parsed files into a separate directory. That could work. Since I only need to run the script once (it automatically parses all the files in directory), I would need a custom rule. I guess I could set it up so that the targets of the rule were the source files in the parsed directory, and the dependencies were the original source files. The rule to build the library would then depend on the files in the parsed directory.

I'll have to give that some more thought, and experiment a bit, but that seems like it might be a good way to go.

Thanks for all of your help!

Chris


Craig Allsop <cjamallsopgmail.com&gt; wrote:
Hi Chris,

Ok, order matters for in-place parsing but I wouldn't recommend
parsing them in-place because it adds unnecessary complexity. How will
jam know the difference between a converted file and one which is not
each time your run it? What is wrong with the intermediate files as
many tools use them e.g. yacc? The nice thing about GenFile is you can
build your pre-parsing tool before pre-parsing. You can tell jam to
output them to an intermediate directory if you don't like them in the
source folder ... anyway ...

Ok, assuming you *really* want to do this, I would set a variable on
your obj targets and use this variable to construct the pre-parsing
action of the source file when Cc action runs. So here we go...

1. Create a rule to set a variable on your objs, we'll set it's value
to the name of your tool that pre-parses the files... you can hide
this in your jamrules.

rule PreParse
{
PP on [ FGristFiles $(<:S=$(SUFOBJ)) ] = yourpptool.exe ;
}

2. Call this rule on your genfile sources in your jamfile:

PreParse $(AUXSRC) ;

3. Copy and modify the Cc actions so that when PP is set, it will be
called to preparse your source file before it is compiled. Hide this
in your jamrules as well.

actions Cc
{
$(PP)$(SPACE)$(>)
$(CC) /c /Fo$(<) $(CCFLAGS) $(CCDEFS) $(CCHDRS) /I$(STDHDRS) $(>)
}


4. Add the definition of SPACE to your jamrules as well..

SPACE = " " ;

Explanation: For the files with PP set, jam will expand the initial
line and call your tool to do the in-place conversion (which it will
have to do always since you don't know if it needs doing or not -
which is my problem with this - but anyway it will work for you) and
thus running your tool prior to compiling it to an obj. For those
files which do not have PP set, jam will expand the line to blank by
multiplication (see docs) not executing anything at all, then compile
the file to obj.

If you have C++ sources you'll need the same mod on it's actions.

Hope it helps, let me know how you go.

Cheers,
Craig.


"Gee, Thanks. You made me appreciate life by showing me how badly my funeral will suck." - Bender, Futurama

&#32;


Be a better Globetrotter. Get better travel answers from someone who knows.
Yahoo! Answers - Check it out.
Re: Pre-parsing source files before building
user name
2007-08-24 21:04:01
Hi Chris,

OMG DOS now that brings back memories, what is this compiler
you're using? ;)

It would be good if this preprocessing tool only did the
files you
give it, if it updates all the sources you'll be building
all the time
as jam will think they are all newer.

To use a temp directory, in the example I suggestion add a
LOCATE_SOURCE to set the output directory of GenFile, jam
will create
the directory and 'clean' target will also be aware of
it...

LOCATE_SOURCE = [ FDirName $(SUBDIR) parsed ] ;
GenFile <parsed>genfile1.c : tool genfile1.c ;
Main target : <parsed>genfile1.c ;

FDirName is a built-in rule to form a path. SUBDIR is this
jamfile's
directory which is set by the SubDir rule you have at the
top of each
jamfile. The <parsed> prefix lets you create a new
name for your file
without changing the on-disk name. Jam will replace the
appropriate
full path of this "name" in actions.

You can scan for all your sources with Glob if you don't
want to
remember to update your jamfile so it might look like...

AUXSRC = [ Glob $(SUBDIR) : gen*.c ] ;
AUXSRC = $(AUXSRC:BS) ; # remove paths

for i in $(AUXSRC)
{
   # $(i:G=temp) will prefix names with <temp>
   GenFile $(i:G=parsed) : tool $(i) ;
}

Main target : $(AUXSRC:G=parsed) ;

Craig.

On 8/25/07, Chris <syndicate_dragonyahoo.com> wrote:
> Part of the problem is that I am limited to an 8.3 DOS
name. So, it's really
> hard to come up with a different name that is legal for
the compiler.
>
> However, I did not think of putting the parsed files
into a separate
> directory. That could work. Since I only need to run
the script once (it
> automatically parses all the files in directory), I
would need a custom
> rule. I guess I could set it up so that the targets of
the rule were the
> source files in the parsed directory, and the
dependencies were the original
> source files. The rule to build the library would then
depend on the files
> in the parsed directory.
>
> I'll have to give that some more thought, and
experiment a bit, but that
> seems like it might be a good way to go.
>
> Thanks for all of your help!
_______________________________________________
jamming mailing list  -  jammingperforce.com
http://maillist.perforce.com/mailman/listinfo/jamming

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )