Author Topic: How to use custom build feature with flex/bison?  (Read 6848 times)

jahurtado

  • Guest
How to use custom build feature with flex/bison?
« on: November 28, 2005, 06:03:10 pm »
Hi,

  I have a program that use flex++/bison++ to generate a parser and I don't know how to use the custom build settings in order to generate c++ output files inside my codeblocks project.

  I have these rules into my hand-made Makefile:

Code
scanner.cpp: scanner.l
$(FLEX) -hscanner.h -oscanner.cpp scanner.l

parser.cpp: parser.y scanner.cpp
$(BISON) -d -v -hparser.h -oparser.cpp parser.y

Output files are scanner.h/.cpp and parser.h/.cpp. I have tried to create a custom build with:

Code
$FLEX -h$DIR\scanner.h -o$DIR\scanner.cpp $FILENAME

but it doesn't work, this hang up the compilation process.

Any idea?

Regards,

  José Antonio.

Offline Urxae

  • Regular
  • ***
  • Posts: 376
Re: How to use custom build feature with flex/bison?
« Reply #1 on: November 28, 2005, 06:14:02 pm »
If you want to enter things like $FLEX into C::B options, you'll have to either define a custom variable or an environment variable of that name for it to be substituted automatically. Another option is doing it manually, ie using flex (or whatever) instead of $FLEX. C::B doesn't know what $FLEX is unless you tell it.
Or, since you already have a working custom makefile, you can always just check 'Custom makefile' in your project properties and use that. This does have the disadvantage that you have to keep it up-to-date manually, of course.

jahurtado

  • Guest
Re: How to use custom build feature with flex/bison?
« Reply #2 on: November 28, 2005, 07:00:03 pm »
If you want to enter things like $FLEX into C::B options, you'll have to either define a custom variable or an environment variable of that name for it to be substituted automatically. Another option is doing it manually, ie using flex (or whatever) instead of $FLEX. C::B doesn't know what $FLEX is unless you tell it.
I have solved the problem (I have already defined custom variables $FLEX and $BISON on codeblocks, so this was not the problem).
It seems that variables like $FILENAME or $DIR don't work and they are replaced by an empty string. I have made the folowing test, I put inside custom build command this text:

echo "testing $FLEX $DIR $NAME $BASE $FILENAME variables"

and when I build the project I get:

testing C:\FLEX\flex++    variables.

So, it seems that those variables are not defined
Is it a bug?


Offline Urxae

  • Regular
  • ***
  • Posts: 376
Re: How to use custom build feature with flex/bison?
« Reply #3 on: November 28, 2005, 09:53:47 pm »
From src/sdk/macrosmanager.cpp :
Code
/*
    standard macros are:

    ${PROJECT_FILENAME} ${PROJECT_FILE} ${PROJECTFILE}
    ${PROJECT_NAME}
    ${PROJECT_DIR} ${PROJECTDIR} ${PROJECT_DIRECTORY}
    ${CODEBLOCKS} ${APP_PATH}  ${APPPATH}
    ${DATA_PATH} ${DATAPATH}
    ${PLUGINS}
    ${ACTIVE_EDITOR_FILENAME}
    ${ALL_PROJECT_FILES}
    ${MAKEFILE}
    ${FOO_OUTPUT_FILE} // per target
    ${BAR_OUTPUT_DIR} // per target
    $(TARGET_OUTPUT_DIR) // the current target's out dir
    $(TARGET_NAME)       // the current target's name (title)

    ${AMP} TODO: implement AddMacro() for custom macros (like this)
*/

So it's not a bug: those aren't predefined macros. If you could explain what exactly you're trying to achieve maybe someone can help you. Or maybe the above list was enough?

jahurtado

  • Guest
Re: How to use custom build feature with flex/bison?
« Reply #4 on: November 28, 2005, 10:47:30 pm »
So it's not a bug: those aren't predefined macros. If you could explain what exactly you're trying to achieve maybe someone can help you. Or maybe the above list was enough?
When you open the options (click on properties with right button) of a file and go to "build" tab, dialog show a message that says:


You can use the following variables:
$DIR: returns the directory where the file resides
$NAME: returns just the filename
$BASE: returns...


but when you use these variables into the custom build command, they aren't replaced with the description showed above.
It means that these variables are predefined, and available for your custom command but it isn't.

If this set of variables are not predefined I find the text showed on file options dialog a little bit confusing. Anyway, I solved the initial problem.

Thanks.