This patch adds version information

Because 'v' and 'V' are already in use, the patch uses 'R' (for release)
and, of course, '--version'.

Corresponding to flashrom svn r182 and coreboot v2 svn r3067.

Signed-off-by: Bernhard Walle <bernhard.walle@gmx.de>
Acked-by: Ulf Jordan <jordan@chalmers.se>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
diff --git a/Makefile b/Makefile
index 4b2fbbd..708c077 100644
--- a/Makefile
+++ b/Makefile
@@ -28,6 +28,12 @@
 
 all: pciutils dep $(PROGRAM)
 
+# Set the flashrom version string from the highest revision number
+# of the checked out flashrom files.
+SVNDEF := -D'FLASHROM_VERSION="$(shell svnversion -cn . \
+          | sed -e "s/.*://" -e "s/\([0-9]*\).*/\1/")"'
+CFLAGS += $(SVNDEF)
+
 $(PROGRAM): $(OBJS)
 	$(CC) -o $(PROGRAM) $(OBJS) $(LDFLAGS)
 	$(STRIP) $(STRIP_ARGS) $(PROGRAM)
diff --git a/flashrom.8 b/flashrom.8
index 007cd9e..3251738 100644
--- a/flashrom.8
+++ b/flashrom.8
@@ -2,7 +2,7 @@
 .SH NAME
 flashrom \- a universal BIOS/ROM/flash programming utility
 .SH SYNOPSIS
-.B flashrom \fR[\fB\-rwvEVfh\fR] [\fB\-c\fR chipname] [\fB\-s\fR exclude_start] [\fB\-e\fR exclude_end]
+.B flashrom \fR[\fB\-rwvEVfhR\fR] [\fB\-c\fR chipname] [\fB\-s\fR exclude_start] [\fB\-e\fR exclude_end]
          [\fB-m\fR vendor:part] [\fB-l\fR file.layout] [\fB-i\fR image_name] [file]
 .SH DESCRIPTION
 .B flashrom
@@ -63,9 +63,9 @@
 .TP
 .B "\-h, \-\-help"
 Show a help text and exit.
-.\".TP
-.\".B "\-\-version"
-.\"Show version information and exit.
+.TP
+.B "\-R, \-\-version"
+Show version information and exit.
 .SH BUGS
 Please report any bugs at
 .BR http://tracker.coreboot.org/trac/coreboot/newticket ","
diff --git a/flashrom.c b/flashrom.c
index 9fde57d..5446fc5 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -191,7 +191,7 @@
 
 void usage(const char *name)
 {
-	printf("usage: %s [-rwvEVfh] [-c chipname] [-s exclude_start]\n", name);
+	printf("usage: %s [-rwvEVfhR] [-c chipname] [-s exclude_start]\n", name);
 	printf("       [-e exclude_end] [-m vendor:part] [-l file.layout] [-i imagename] [file]\n");
 	printf
 	    ("   -r | --read:                    read flash and save into file\n"
@@ -206,11 +206,17 @@
 	     "   -f | --force:                   force write without checking image\n"
 	     "   -l | --layout <file.layout>:    read rom layout from file\n"
 	     "   -i | --image <name>:            only flash image name from flash layout\n"
+	     "   -R | --version:                 print the version (release)\n"
             "\n" " If no file is specified, then all that happens"
 	     " is that flash info is dumped.\n\n");
 	exit(1);
 }
 
+void print_version(void)
+{
+	printf("flashrom r%s\n", FLASHROM_VERSION);
+}
+
 int main(int argc, char *argv[])
 {
 	uint8_t *buf;
@@ -236,6 +242,7 @@
 		{"layout", 1, 0, 'l'},
 		{"image", 1, 0, 'i'},
 		{"help", 0, 0, 'h'},
+		{"version", 0, 0, 'R'},
 		{0, 0, 0, 0}
 	};
 
@@ -253,7 +260,7 @@
 	}
 
 	setbuf(stdout, NULL);
-	while ((opt = getopt_long(argc, argv, "rwvVEfc:s:e:m:l:i:h",
+	while ((opt = getopt_long(argc, argv, "rRwvVEfc:s:e:m:l:i:h",
 				  long_options, &option_index)) != EOF) {
 		switch (opt) {
 		case 'r':
@@ -306,6 +313,10 @@
 			tempstr = strdup(optarg);
 			find_romentry(tempstr);
 			break;
+		case 'R':
+			print_version();
+			exit(0);
+			break;
 		case 'h':
 		default:
 			usage(argv[0]);