[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Adding current svn revision to source automatically

From: Kenneth Goldman <kgoldman_at_us.ibm.com>
Date: Fri, 19 Dec 2008 09:19:57 -0500

Thanks to all who got me clues. In return, I offer my 'solution'.
However, it convinces me that the $GlobalRev$ that the manual admits
doesn't exist should be implemented.

1 - The hacks using svnversion are just that - hacks. $GlobalRev$
would be much cleaner.

2 - My solution is Unix only. Windows doesn't have svnversion,
doesn't have sed, and might not even have make.

My solution:

1 - Create a .h file with this:

extern const unsigned short svn_revision;

      I thought of using a .h with #define, but it would have to
      depend on all the other .h and .c files, and some other .h or
      .c files would depend on this file. The circular dependency
      doesn't work well with make.

      I didn't see any advantage of the FAQ approach, using a
      function call rather than a global constant.

2 - Get the svn version in the makefile

SVNVERSION := $(shell svnversion | sed s/\[0-9\]\*:// |sed s/M//)

      The FAQ implies that svnversion returns a number, but it could
      worst case return a value of the form nnnn:nnnnM. The first
      nnnn evidently refers to the version in other parts of the
      project. The M indicates that files aren't committed yet,
      common during development. sed filters these out.

2 - Create the .c file in the makefile like this

.c: $(everything)
            echo -n 'const unsigned short svn_revision = ' > .c
            echo -n $(SVNVERSION) >> .c
            echo ';' >> .c

      The .c file has to depend on everything else, so the
      everything variable has to be created manually and kept up to
      date. I didn't like the force option in the FAQ, because it
      forces a link even when nothing changes.

3 - Create the export target

export:
      rm -rf /tmp/src
      svn export ../src /tmp/src
      cp .c /tmp/src
      touch /tmp/src/.c

      Since the .c file isn't committed, it has to copied
      separately. I touch it to force it to be compiled when
      testing the release before creating the tarball.

4 - Add the .o file to the make target.

5 - Add the .c file to the clean target

--
Ken Goldman   kgold_at_watson.ibm.com
914-784-7646 (863-7646)
------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=987467
To unsubscribe from this discussion, e-mail: [users-unsubscribe_at_subversion.tigris.org].
Received on 2008-12-19 16:52:23 CET

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.