On Sat, 6 Oct 2007, Robinson Tryon wrote:

On 10/5/07, Ward Vandewege <[EMAIL PROTECTED]> wrote:
On Sat, Oct 06, 2007 at 12:30:06AM +0200, Uwe Hermann wrote:
etc.) or at least ask some svn experts whether there is an easier and
cleaner way to include a revision number?

Yeah, that would surely be great. Do you know any method or whom to ask?
I browsed the svn code and manuals but didn't find anything better
than $Rev$.

Can't we do this with a commit hook that would update the version number
(which is in 1 place only) automatically to the SVN revision number?

I was going to suggest that the buildscript pull the current revision
# out of SVN, but the idea of a commit hook sounds like it could be
cleaner.  Would the hook apply whenever any file is committed to the
repository, or just to files in the superiotool directory?

NACK. svn commit hooks should not change the contents of the commit, at least not according to the svn book (client side caching problems might occur).

I've attached a patch that during build time extracts the svn revision from $Rev$ comments in each source file, and keeps the extracted value up to date using make.

Direct application of the patch might give one failure on superiotool.h (it has the expanded $Rev$ in your working directory), and compilation failure on superiotool.c, since the new $Rev$'s haven't yet been expanded (these two issues should not appear when receiving the patch through 'svn update'). For testing I expanded the $Rev$ by hand to the corresponding svn revisions, and then it worked like a charme:

$ make
sed -ne 's/.*Rev: \([0-9]*\) .*/\1/p' ali.c fintek.c ite.c nsc.c smsc.c superiotool.c winbond.c superiotool.h \
        | sort -n \
        | tail -1 \
        | sed 's/.*/#define SUPERIOTOOL_VERSION "&"/' >version.h
gcc -O2 -Wall -Werror -Wstrict-prototypes -Wundef -Wstrict-aliasing -Werror-implicit-function-declaration -ansi -c -o superiotool.o superiotool.c gcc -O2 -Wall -Werror -Wstrict-prototypes -Wundef -Wstrict-aliasing -Werror-implicit-function-declaration -ansi -c -o ali.o ali.c gcc -O2 -Wall -Werror -Wstrict-prototypes -Wundef -Wstrict-aliasing -Werror-implicit-function-declaration -ansi -c -o fintek.o fintek.c gcc -O2 -Wall -Werror -Wstrict-prototypes -Wundef -Wstrict-aliasing -Werror-implicit-function-declaration -ansi -c -o ite.o ite.c gcc -O2 -Wall -Werror -Wstrict-prototypes -Wundef -Wstrict-aliasing -Werror-implicit-function-declaration -ansi -c -o nsc.o nsc.c gcc -O2 -Wall -Werror -Wstrict-prototypes -Wundef -Wstrict-aliasing -Werror-implicit-function-declaration -ansi -c -o smsc.o smsc.c gcc -O2 -Wall -Werror -Wstrict-prototypes -Wundef -Wstrict-aliasing -Werror-implicit-function-declaration -ansi -c -o winbond.o winbond.c gcc -O2 -Wall -Werror -Wstrict-prototypes -Wundef -Wstrict-aliasing -Werror-implicit-function-declaration -ansi -o superiotool superiotool.o ali.o fintek.o ite.o nsc.o smsc.o winbond.o
$ ./superiotool --version
superiotool r2828


/ulf
Extract superiotool version number from the svn revision numbers of the
*.c and superiotool.h files.

Signed-off-by: Ulf Jordan <[EMAIL PROTECTED]>

Index: fintek.c
===================================================================
--- fintek.c    (revision 2828)
+++ fintek.c    (arbetskopia)
@@ -19,6 +19,13 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+/*
+ * Each superiotool source file should have a revision comment for
+ * version tracking. The largest revision is extracted by the build
+ * system into version.h
+ * $Rev$
+ */
+
 #include "superiotool.h"
 
 #define DEVICE_ID_BYTE1_REG    0x20
Index: winbond.c
===================================================================
--- winbond.c   (revision 2828)
+++ winbond.c   (arbetskopia)
@@ -19,6 +19,13 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+/*
+ * Each superiotool source file should have a revision comment for
+ * version tracking. The largest revision is extracted by the build
+ * system into version.h
+ * $Rev$
+ */
+
 #include "superiotool.h"
 
 #define DEVICE_ID_REG_OLD      0x09
Index: ite.c
===================================================================
--- ite.c       (revision 2828)
+++ ite.c       (arbetskopia)
@@ -19,6 +19,13 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+/*
+ * Each superiotool source file should have a revision comment for
+ * version tracking. The largest revision is extracted by the build
+ * system into version.h
+ * $Rev$
+ */
+
 #include "superiotool.h"
 
 #define CHIP_ID_BYTE1_REG      0x20
Index: nsc.c
===================================================================
--- nsc.c       (revision 2828)
+++ nsc.c       (arbetskopia)
@@ -19,6 +19,13 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+/*
+ * Each superiotool source file should have a revision comment for
+ * version tracking. The largest revision is extracted by the build
+ * system into version.h
+ * $Rev$
+ */
+
 #include "superiotool.h"
 
 #define CHIP_ID_REG    0x20    /* Super I/O ID (SID) / family */
Index: superiotool.c
===================================================================
--- superiotool.c       (revision 2828)
+++ superiotool.c       (arbetskopia)
@@ -20,6 +20,13 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+/*
+ * Each superiotool source file should have a revision comment for
+ * version tracking. The largest revision is extracted by the build
+ * system into version.h
+ * $Rev$
+ */
+
 #include "superiotool.h"
 
 /* Command line options. */
@@ -167,12 +174,7 @@
 
 static void print_version(void)
 {
-       char tmp[80];
-
-       strncpy((char *)&tmp,
-               (const char *)&SUPERIOTOOL_VERSION[6],
-               strlen(SUPERIOTOOL_VERSION) - 8);
-       printf("superiotool r%s\n", (char *)&tmp);
+       printf("superiotool r" SUPERIOTOOL_VERSION "\n");
 }
 
 int main(int argc, char *argv[])
Index: ali.c
===================================================================
--- ali.c       (revision 2828)
+++ ali.c       (arbetskopia)
@@ -18,6 +18,13 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+/*
+ * Each superiotool source file should have a revision comment for
+ * version tracking. The largest revision is extracted by the build
+ * system into version.h
+ * $Rev$
+ */
+
 #include "superiotool.h"
 
 #define DEVICE_ID_BYTE1_REG    0x20
Index: smsc.c
===================================================================
--- smsc.c      (revision 2828)
+++ smsc.c      (arbetskopia)
@@ -18,6 +18,13 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+/*
+ * Each superiotool source file should have a revision comment for
+ * version tracking. The largest revision is extracted by the build
+ * system into version.h
+ * $Rev$
+ */
+
 #include "superiotool.h"
 
 #define DEVICE_ID_REG_OLD      0x0d
Index: superiotool.h
===================================================================
--- superiotool.h       (revision 2828)
+++ superiotool.h       (arbetskopia)
@@ -29,7 +29,13 @@
 #include <getopt.h>
 #include <sys/io.h>
 
-#define SUPERIOTOOL_VERSION "$Rev$"
+/*
+ * Each superiotool source file should have a revision comment for
+ * version tracking. The largest revision is extracted by the build
+ * system into version.h
+ * $Rev$
+ */
+#include "version.h"
 
 #define USAGE "Usage: superiotool [-d] [-D] [-V] [-v] [-h]\n\n\
   -d | --dump            Dump Super I/O registers\n\
Index: Makefile
===================================================================
--- Makefile    (revision 2828)
+++ Makefile    (arbetskopia)
@@ -32,6 +32,14 @@
 
 all: $(PROGRAM)
 
+superiotool.o: version.h
+
+version.h: *.c superiotool.h
+       sed -ne 's/.*Rev: \([0-9]*\) .*/\1/p' $^ \
+       | sort -n \
+       | tail -1 \
+       | sed 's/.*/#define SUPERIOTOOL_VERSION "&"/' >$@
+
 $(PROGRAM): $(OBJS) superiotool.h
        $(CC) $(CFLAGS) -o $(PROGRAM) $(OBJS)
 
@@ -39,7 +47,7 @@
        $(INSTALL) $(PROGRAM) $(PREFIX)/bin
 
 clean:
-       rm -f $(PROGRAM) *.o
+       rm -f $(PROGRAM) *.o version.h
 
 .PHONY: all install clean
 
-- 
linuxbios mailing list
linuxbios@linuxbios.org
http://www.linuxbios.org/mailman/listinfo/linuxbios

Reply via email to