Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: willkn on December 16, 2005, 07:58:08 am

Title: Setting a variable to be used in Makefile
Post by: willkn on December 16, 2005, 07:58:08 am
I'm using an external makefile in my project and I'd like to be able to specify the value of variables that can be used in the Makefile, such as with an 'ifeq "$(BLD)" "dbg"    statement. Under 'Build options', I've tried setting the variable in the 'Compiler', 'Other Options' box, the 'Compiler', '#defines' box, and even the 'Custom variables' box, but it looks like none of these values are ever passed to the make program, it seems that they are only given to the compiler (and even there, I wonder).

Any way to specify a variable setting in the build options so that the Makefile can use it?
Title: Re: Setting a variable to be used in Makefile
Post by: yop on December 16, 2005, 09:11:53 am
How can this happen with an external makefile? Using an external makefile means that you "disable" the cb building functionality and you  use your own...
Title: Re: Setting a variable to be used in Makefile
Post by: tiwag on December 16, 2005, 10:37:33 am
How can this happen with an external makefile? Using an external makefile means that you "disable" the cb building functionality and you  use your own...
when i was young, this was done by commandline-parameters to make
Title: Re: Setting a variable to be used in Makefile
Post by: yop on December 16, 2005, 01:13:32 pm
when i was young, this was done by commandline-parameters to make
Using cb? You mean by changing the build commands (Compilers->Advanced Options etc.)? I don't get it  :oops:
Title: Re: Setting a variable to be used in Makefile
Post by: tiwag on December 16, 2005, 01:43:52 pm
...Using cb? You mean by changing the build commands (Compilers->Advanced Options etc.)? I don't get it  :oops:

(i don't know if CodeBlocks RC2 had already this feature, i use a recent SVN version)
When you use a custom makefile, you can specifiy for each target the make-commands, see Project->Build-options->"Make" commands

maybe you have two targets in your project, Release and Debug and you use the same makefile, just give it the necessary variable on the commandline. (as willkn described in his post)

you change the "Build project/target" value from $make -f $makefile $target (which is set as default) to whatever you need for your custom makefile.

for example
target  : "Build project/target"
-----------------------
Release :  make BLD=rel
Debug   :  make BLD=dbg


did you get it now?
Title: Re: Setting a variable to be used in Makefile
Post by: yop on December 16, 2005, 01:58:26 pm
Yes thanks. I also use the SVN head version, but apparently I didn't notice this functionality
Title: Re: Setting a variable to be used in Makefile
Post by: willkn on December 16, 2005, 03:01:15 pm
Quote
(i don't know if CodeBlocks RC2 had already this feature, i use a recent SVN version)
When you use a custom makefile, you can specifiy for each target the make-commands, see Project->Build-options->"Make" commands

I'm using RC2 and don't see this feature. I'll be checking out svn head soon.  When I do, 'Project->Build-options, I get the dialog with 'compiler options', 'linker options', 'directories', 'commands', 'custom variables', but I don't see any place to put a command-line variable definition in front of the 'make' command.