0

I am trying to automatically set the version in a makefile from the CVS tag. Here is relvant the part of the makefile:

VERSION =$Name:  $

That works ok when I checkout the project. The keyword is replaced by the tag. The problem is that as it is the Makefile does not work unless the keyword is substituted (i.e. the $ signs are gone), so I con not for example compile check the code before committing. If I escape the $ using $$Name $$, then the checked out version would not compile as it would become $$.

Is there a way to workaround this?

B-K
  • 359
  • 1
  • 2
  • 9

1 Answers1

0

In GNU make, this kind of construct works:

COMMAV  := ,v
CVSFILE := $(patsubst %:,,$$RCSfile: Makefile,v $$)
CVSVERS := $(patsubst %:,,$$Revision: 1.130 $$)
CVSDATE := $(patsubst %:,,$$Date: 2012/10/09 22:02:16 $$)
CVSINFO := $(subst $$,,$(subst $(COMMAV),,$(CVSFILE))$(CVSVERS)$(CVSDATE))

In your case, you are looking for the revision, so I believe the direct solution is:

VERSION := $(subst $$,,$(patsubst %:,,$$Revision: 1.130 $$))
kbulgrien
  • 4,384
  • 2
  • 26
  • 43
  • I'm not exactly sure this solves the problem. Perhaps some clarification on the question is in order if it does not? – kbulgrien Oct 26 '12 at 19:29
  • I'm completely puzled with that sintax, I'll just try it out and let you know!:) . Note: I'm intrested in the "tag" i.e. -r argument when doing checkout rather than the individual file revision, that is why I'm using $Name$ – B-K Oct 26 '12 at 20:28
  • I tried this: VERSION :=$(subst $$,,$(patsubst %:,,$$Name: $$)) After checking out with -r TEST-VERSION it got substituted to: VERSION :=$(subst $$,,$(patsubst %:,,$TEST-VERSION$)) But the VERSION VARIABLE ended up in \"EST-VERSION\". It seems something is eating up the first char.. wait may be i'm missing the COMMAV thing.. – B-K Oct 26 '12 at 20:34
  • Finally the last construct worked. I only added a strip, to avoid blanks: `VERSION :=$(strip $(subst $$,,$(patsubst %:,,$$Name: TEST-VERSION $$)))` – B-K Dec 04 '12 at 13:52