how to programmatically generate makefile variable | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

how to programmatically generate makefile variable

Shell Programming and Scripting


Tags
build, makefile

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-03-2011
benkial benkial is offline
Registered User
 
Join Date: Jul 2011
Last Activity: 4 July 2011, 12:43 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
how to programmatically generate makefile variable

I make to parse the release version from a text file and set the release version label into a Makefile variable. I tried:

Code:
VERSION := `grep vsn s1db.app|sed -e s/[^\"]*\"// -e s/\"[^\"]*//`

but looks like make, unlike shell, literally just take the entire `grep ...` as the variable value.

Then I tried to put the shell command in:

release: forced

Code:
    export VERSION=`grep vsn s1db.app|sed -e s/[^\"]*\"// -e s/\"[^\"]*//`
    echo $(VERSION)

but it seems that the "export" command does not set the $VERSION value.

How can I programmatically parse and set a makefile variable?

Thanks in advance,

Benk

Last edited by Franklin52; 07-04-2011 at 02:21 AM.. Reason: Please use code tags for code and data samples, thank you
Sponsored Links
    #2  
Old 07-03-2011
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 31 August 2014, 3:15 PM EDT
Location: Saskatchewan
Posts: 19,271
Thanks: 774
Thanked 3,237 Times in 3,035 Posts
Quote:
but looks like make, unlike shell, literally just take the entire `grep ...` as the variable value.
It does, but will evaluate the backticks when you use it.

Quote:
but it seems that the "export" command does not set the $VERSION value.
Shell lines in a makefile are executed individually and separately. exporting something won't do a thing to any other line.
Sponsored Links
    #3  
Old 07-04-2011
benkial benkial is offline
Registered User
 
Join Date: Jul 2011
Last Activity: 4 July 2011, 12:43 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Corona688, thanks for you reply. I'm kind of new to the makefile business...

You are right, if I use "echo $VERSION" under any of the rules, the "`" expression will be evaluated, and the correct version string will be printed. So, is this the correct way people do to get some contents into the makefile?

This seems kind of odd to me, because each occurrence of $VERSION will cause an evaluation of the "`" expression. This is not what I would expect the behavior for the "variable" be. Or is there a better way to do this in make?
    #4  
Old 07-04-2011
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 31 August 2014, 3:15 PM EDT
Location: Saskatchewan
Posts: 19,271
Thanks: 774
Thanked 3,237 Times in 3,035 Posts
There's supposed to be a better way in GNU make, a 'simple variable', done with VAR:=`something` but it doesn't do what it says it's supposed to, and just evaluates every time.

Short of creating a makefile from template or something, I don't think so.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Makefile doesn't update $< variable Kodreanu Shell Programming and Scripting 1 04-01-2011 11:58 AM
Setting/Modifying variable specific to target in Makefile nsriram Solaris 5 02-01-2011 03:01 AM
Makefile: multiple target variable substitution Harlinator Programming 0 09-24-2009 07:20 PM
alternative for recursive variable in Makefile? prits31 Shell Programming and Scripting 2 02-05-2009 07:54 AM
Is there any way to set env variable in top level Makefile and unset when done umen Shell Programming and Scripting 0 10-23-2005 08:15 AM



All times are GMT -4. The time now is 09:51 PM.