Sign in to follow this  

makefile question

This topic is 4354 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

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
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
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
Not going to work; it's the wrong way around. The preprocessor can't invoke programs.

Is there a reason you can't just do it at runtime? What *exactly* are you trying to do? I really can't think of why you would want to produce a different "randomized" executable each time you compile the same code o_O

Share this post


Link to post
Share on other sites
I want a program to solve for different things of course it shouldn't run at runtime, but if the parameter is constant wouldn't it be possible to run the program with the specified parameter and let a variable be equal to the output? depeding of the parameter

Share this post


Link to post
Share on other sites

This topic is 4354 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this