1753693 Members
6322 Online
108799 Solutions
New Discussion юеВ

Makefile , Variable

 
SOLVED
Go to solution
Billa-User
Regular Advisor

Makefile , Variable

hello,

i have a question about Makefile:

i have to change a Makefile, is it possible to store a value in a Makefile ? in my example it doesn't work.

first i want to store the value 2.
second, i want to get the return value of an command from the remote-host, in my example the file can't be created.

Makefile example:
RET = 0

all:
@RET=2
@echo "RET: $(RET)"
@RET=`remsh otherhost -n "touch /tmpxx/test 2>/dev/null >/dev/null;echo " '$$?'`
@echo "RET: $(RET)"
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor
Solution

Re: Makefile , Variable

Hi:

First, the shell variable '$$' isn't the return code, it's the PID of the current process. For a return code, you want '$?'

Yes, you can store variables and their values in a makefile.

Shell commands are also allowed but have rules too.

The 'make' manpages should be helpful; consult them!

From the snippet you posted, the logic would appear to be more suitable for a *shell* script and not a makefile.

Regards!

...JRF...

Sh
Peter Nikitka
Honored Contributor

Re: Makefile , Variable

Hi,

there are multiple errors at a time, you managed to put in such a small Makefile.
Sorry, but you better read something about Makefiles first - even a 'man make' will lead you further.
I comment only some if them ...

1 RET = 0
2
3 all:
4 @RET=2
5 @echo "RET: $(RET)"
6 @RET=`remsh otherhost -n "touch /tmpxx/test 2>/dev/null >/dev/null;echo "'$$?'`
7 @echo "RET: $(RET)"

You define a makro RET in line1.
In line 4-7 you use four distinct lines as a makerule for target 'all'. Distinct means here, that these are independent shell processes and no following line will know anything about the previous one. Your assignment to the shell variable RET in line 4 is a no-op therefore and has - N.B. - nothing to do with your makro definition in line 1.
Your line5 will use the makro of line1 and lead to an output
RET: 0
It will NOT use the assignment to the shell variable in line4, even when changing this line to
5 @echo "RET: $$RET"
as already mentioned.

The same mistake is done in lines 6 and 7:
Assigning a shell variable in a different process and querying a make makro. Line7 will always produce
RET: 0

Your line6 itself will set/show the return value of the remote command - but only if you really can reach 'otherhost' and get a passwordless login.

Try something like this:
1 all:
2 @RET=`remsh otherhost -n "touch /tmpxx/test 2>/dev/null >/dev/null;echo "'$$?'`; \
3 echo RET=$$RET

OK - it's your turn!

mfG Peter


The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Dennis Handly
Acclaimed Contributor

Re: Makefile , Variable

You can set a macro to a value but you can't change it unless using gmake.
If you want to change it you must use a shell variable and one big long command that Peter mentions.

>JRF: the shell variable '$$' isn't the return code,

In makefiles, you must use $$ for shell variables.
Billa-User
Regular Advisor

Re: Makefile , Variable

Hello Dennis, hello Peter,

Thank you for your useful information. i made in the meantime some tests and with your informations i unterstand Makefiles better and integrate in my work.

kind regards,tom