Jump to content
  • Advertisement
Sign in to follow this  
ProblemBaby

makefile question

This topic is 4521 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

is it possible to have a macro/define in my makefile which I can use in my source files? I want to excute a program for a macro and get the return value. thanks

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by igni ferroque
The -D flag to your compiler allows you to define macros when it is invoked.


To clarify a bit, the syntax is -Dname=value.

Share this post


Link to post
Share on other sites
cool, but is it possible to let value=return value from an application ?
and have a parameter to the application like if I define RANDOM

in my C code:
int t = RANDOM(1000);

and RANDOM executes a program that returns a value

Share this post


Link to post
Share on other sites
Quote:
Original post by ProblemBaby
cool, but is it possible to let value=return value from an application ?


You mean is it possible to set a variable in the Makefile to the text written to standard output from an application? If so, this might work:

VAR=`program`

Share this post


Link to post
Share on other sites
Yes its the exit value I want.
but what should it look like?

RANDOM = `Random.exe`
CFLAGS = -D$?RANDOM

is it possible to send a parameter?

thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by ProblemBaby
Yes its the exit value I want.
but what should it look like?

RANDOM = `Random.exe`
CFLAGS = -D$?RANDOM

is it possible to send a parameter?


I don't think you want the exit value, since you cant use an integer as a preprocessor identifier in any language I know. It's more likely you want to capture stdout and transform it into a macro value.

Something like

CFLAGS = -DRANDOM="`Random`"

WOuld set the C macro RANDOM to be the value fo the output of the "Random" program. This is assuming your Makefile is run from a Bourne-like shell (eg. Cygwin, Msys, Linux).

The trick is the backticks cause substitution of the output of the command for the command in a Bourne-style shell.

Share this post


Link to post
Share on other sites
Yeah nice it works!
now the last problem... if I want a parameter for the Random program
so when I write this in my C-code:
RANDOM("132")

"132" is sent as a parameter to the program.

Share this post


Link to post
Share on other sites
Quote:
Original post by ProblemBaby
Yeah nice it works!
now the last problem... if I want a parameter for the Random program
so when I write this in my C-code:
RANDOM("132")

"132" is sent as a parameter to the program.


I'm not quite sure what you want. If you want to pass a parameter to the program in the makefile, you would say something like this.

CFLAGS = -DRANDOM="`Random 132`"


If it's in the C code that you're trying to pass the parameter (if, say, the Random program chose a function name), you don't have to do anything, since the preprocessor is just text substitution and knows nothing about the C (or C++) language.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!