Board index » cppbuilder » Custom Build Steps for Lex and Yacc

Custom Build Steps for Lex and Yacc

What is the best way to add additional custom build steps to my project for
running flex and bison on my .L and .Y files that are translated to .C files
and then subsequently compiled by BCB5?  I assume there is probably some way
to modify the .bpr project file to do this, but have seen little
documentation on the meaning of the fields contained therein.

                Any help would be much appreciated,
                        Nick

 

Re:Custom Build Steps for Lex and Yacc


Quote
Nick Shaffner wrote:

> What is the best way to add additional custom build steps to my project for
> running flex and bison on my .L and .Y files that are translated to .C files
> and then subsequently compiled by BCB5?

I am not sure the IDE can handle your request. I know that Alex Bakaev is always
asking for IDE improvements regarding plugging in extra tools. If the IDE would allow
you do plug in flex and bison, I doubt that Alex would be complaining.

My suggestion to you is to use consider using a makefile. Or you could create a .BAT
file for compiling just the flex and bison files. Then add the resulting C files to
your project. The problem with this approach is that your build dependencies will be
all screwed up.

Harold Howe [TeamB]
http://www.bcbdev.com

Re:Custom Build Steps for Lex and Yacc


Create a project group for your project. Add a batch file first and from within
the batch file add your own make file for running flex and bison against your .L
and .Y files respectively to create your source and header output. Then add your
project which uses the flex and bison output next to the project group. Use Make
All Projects or Build All Projects to create your final output.
Quote
Nick Shaffner wrote:
> What is the best way to add additional custom build steps to my project for
> running flex and bison on my .L and .Y files that are translated to .C files
> and then subsequently compiled by BCB5?  I assume there is probably some way
> to modify the .bpr project file to do this, but have seen little
> documentation on the meaning of the fields contained therein.

>                 Any help would be much appreciated,
>                         Nick

Re:Custom Build Steps for Lex and Yacc


Quote
> My suggestion to you is to use consider using a makefile. Or you could
create a .BAT
> file for compiling just the flex and bison files. Then add the resulting C
files to
> your project. The problem with this approach is that your build

dependencies will be

Quote
> all screwed up.

    Ok, so I've been using a batch file as a seperate project in my project
group to preprocess my lex and yacc files,  but now I also want to run yet
more tools to generate my final executable as well as preprocess the output.
For example, I now run microsoft's RC compiler to generate an additional
.RES file that I need to link to, and I want to feed my final executable
through an executable compressor as well as a utility that recomputes it's
header's checksum.
    I can do all this with batch files, but the amount of redundant work
would become rather excessive.  (ie, that .RES file is quite large, and
rarely needs to be regenerated.)
    Ideally, I'd love to be able to do this with a single makefile, and I
see that tempting 'ExportMakefile' option sitting happilly under the project
menu.  My question is this, how can I export this makefile, and perhaps mod
it up a bit and still stay friendly with the IDE?  I'm guessing that when I
export the makefile and mod it up one of a couple things will happen:

[a] I'll lose use of the project manager menu.
[b] I'll be in danger of exporting another makefile on top of the one I just
modified, thus losing my changes.

Basically, to recap, what I want to do is:

Preprocess a lex file
Preprocess a yacc file
run microsoft's RC.exe on my custom resource script generating a .res file
build the executable including the output of lex and yacc as well as the
generated .res file
Post process the executable with an executable compressor
post process that with a checksum resetting utility.

Right now, I'm thinking my project group is going to look like:

Preprocess.bat - calls a custom makefile to build my lex, yacc and .res file
Project1           - normal project compilation.
Postprocess.bat - compresses my .exe, and resets it's checksum

Is there any way to simplify this process? In VC it's just a matter of
setting up a couple of custom build steps and a post link step.  Is it
possible to get this all working in a single .mak file, and still stay
friendly with the IDE?

            Thanks for the help,
                                                Nick

--
Nick Shaffner
3D Realms

Re:Custom Build Steps for Lex and Yacc


Theoretically you can export makefile from VC, but then you will not be able
to debug in BCB. Next step is to use VC for everything.

Re:Custom Build Steps for Lex and Yacc


Quote
> Preprocess a lex file
> Preprocess a yacc file
> run microsoft's RC.exe on my custom resource script generating a .res file
> build the executable including the output of lex and yacc as well as the
> generated .res file
> Post process the executable with an executable compressor
> post process that with a checksum resetting utility.

I recommend creating a make file that can

1- build the lex C file from the lex input file
2- build the yacc C file from the yacc input file
3- build the RES file from the RC file
4- run the compressor
5- run the checksum resetter.

it would look sort of like this (lots of stuff missing, namely the options for each
tool):

lexer.c : lexer.y
    lex $(LEXOPTIONS) -olexer.c lexer.y

yacc.c : yacc.y
    yacc $(YACCOPTIONS) -oyacc.c yacc.y # not sure if the -o is correct

foo.res: foo.rc
    ms-res-compiler $(RESOPTIONS) foo.rc

final.exe: intermediate.exe
    compressor $(COMPRESSOPTIONS) intermediate.exe final.exe
    checksummer $(CHECKSUMOPTIONS) final.exe

preprocess: yacc.c lexer.c foo.res
postprocess: final.exe

Then, change preprocess.bat to look like this

make preprocess

and change postprocess.bat to look like this:

make postprocess

preprocess.bat and postprocess.bat would be a part of your project group.

I'm not sure why you want to have the RC file external and processed by MSVC. I will
assume that you have good reason. Otherwise, you could just add the RC file to your
project (or the .RES file). You could also uses Borland's resource compiler.

Quote
> Is there any way to simplify this process? In VC it's just a matter of
> setting up a couple of custom build steps and a post link step.

BCB5 doesn't support this. BCB6 will (although that doesn't help you much at the
moment)

Quote
> Is it
> possible to get this all working in a single .mak file, and still stay
> friendly with the IDE?

As I described. The key is not to manage or build your EXE from the make file. Just
manage the pre and post process steps.

Harold Howe [TeamB]
http://www.bcbdev.com

Re:Custom Build Steps for Lex and Yacc


Thanks for the suggestion Harold, putting it in a single makefile will help
keep it a bit easier to maintain.

Quote
> I'm not sure why you want to have the RC file external and processed by
MSVC. I will
> assume that you have good reason. Otherwise, you could just add the RC
file to your
> project (or the .RES file). You could also uses Borland's resource

compiler.

    I'd love to use Borland's RC compiler, but from what I've seen, it can't
handle resource statements like this:

index.html     HTML DISCARDABLE    "res\\index.html"

which makes using the res:// protocol ...muuuuch... easier.  (ie, being able
to have resource names with a '.' in them)
    Is there any way to make borland's resource compiler handle this?
(presently I just get a syntax error)

Quote
> As I described. The key is not to manage or build your EXE from the make
file. Just
> manage the pre and post process steps.

    Thanks for the help Harold, I'll definantly be doing it that way then.

                                    Nick

Other Threads