Subject: RCS ID in kernel version
To: None <tech-kern@netbsd.org>
From: Hubert Feyrer <feyrer@rfhs8012.fh-regensburg.de>
List: tech-kern
Date: 01/20/2000 02:24:56
Keeping my kernel config files under RCS control, I always wished to
have a way to embed the revision number into the kernel's "uname -v"
output. The patch below does this, by generating a new keyword "ident"
that can be followed by any string, e.g.

	ident	"NOON-$Revision$"

will lead to
                                           vvvvvvvvvvvvvvvvvvvvvv
	char version[] =     "NetBSD 1.4P (NOON-$Revision: 1.21 $) #37: Thu Jan 20 02:01:23 MET 2000\n    feyrer@noon:/usr/cvs.local/src-current/sys/arch/i386/compile/NOON\n";

This will lead to a version of "MYMACHINE-$Revision$" instead of the
kernel config file name. If "ident" is not present, the current behaviour
of using the kernel config file's name as identifier is used. 

I'd like to commit this, if nobody objects. Any comments?


 - Hubert



Index: sys/conf/newvers.sh
===================================================================
RCS file: /cvsroot/syssrc/sys/conf/newvers.sh,v
retrieving revision 1.29
diff -u -r1.29 newvers.sh
--- newvers.sh	1999/02/17 08:13:12	1.29
+++ newvers.sh	2000/01/20 01:07:39
@@ -42,7 +42,11 @@
 
 touch version
 v=`cat version` u=${USER-root} d=`pwd` h=`hostname` t=`date`
-id=`basename ${d}`
+if [ -f ident ]; then
+	id="`cat ident`"
+else
+	id=`basename ${d}`
+fi
 osrelcmd=`dirname $0`/osrelease.sh
 
 ost="NetBSD"
Index: usr.sbin/config/config.h
===================================================================
RCS file: /cvsroot/syssrc/usr.sbin/config/config.h,v
retrieving revision 1.46
diff -u -r1.46 config.h
--- config.h	1999/09/22 14:23:03	1.46
+++ config.h	2000/01/20 01:07:59
@@ -316,6 +316,7 @@
 const char *srcdir;		/* path to source directory (rel. to build) */
 const char *builddir;		/* path to build directory */
 const char *defbuilddir;	/* default build directory */
+char *ident=NULL;		/* kernel "ident"ification string */
 int	errors;			/* counts calls to error() */
 int	minmaxusers;		/* minimum "maxusers" parameter */
 int	defmaxusers;		/* default "maxusers" parameter */
Index: usr.sbin/config/gram.y
===================================================================
RCS file: /cvsroot/syssrc/usr.sbin/config/gram.y,v
retrieving revision 1.27
diff -u -r1.27 gram.y
--- gram.y	1999/07/09 06:44:58	1.27
+++ gram.y	2000/01/20 01:08:02
@@ -103,7 +103,7 @@
 
 %token	AND AT ATTACH BUILD CINCLUDE COMPILE_WITH CONFIG DEFFS DEFINE DEFOPT 
 %token	DEFPARAM DEFFLAG DEFPSEUDO DEVICE DEVCLASS DUMPS ENDFILE XFILE XOBJECT
-%token	FILE_SYSTEM FLAGS INCLUDE XMACHINE MAJOR MAKEOPTIONS
+%token	FILE_SYSTEM FLAGS IDENT INCLUDE XMACHINE MAJOR MAKEOPTIONS
 %token	MAXUSERS MAXPARTITIONS MINOR ON OPTIONS PREFIX PSEUDO_DEVICE ROOT
 %token	SOURCE TYPE WITH NEEDS_COUNT NEEDS_FLAG
 %token	<val> NUMBER
@@ -386,6 +386,7 @@
 	OPTIONS opt_list |
 	MAKEOPTIONS mkopt_list |
 	MAXUSERS NUMBER			{ setmaxusers($2); } |
+	IDENT WORD			{ setident($2); } |
 	CONFIG conf root_spec sysparam_list
 					{ addconf(&conf); } |
 	PSEUDO_DEVICE WORD npseudo	{ addpseudo($2, $3); } |
Index: usr.sbin/config/main.c
===================================================================
RCS file: /cvsroot/syssrc/usr.sbin/config/main.c,v
retrieving revision 1.44
diff -u -r1.44 main.c
--- main.c	1999/09/24 04:23:36	1.44
+++ main.c	2000/01/20 01:08:12
@@ -86,6 +86,7 @@
 static	int	badstar __P((void));
 	int	main __P((int, char **));
 static	int	mksymlinks __P((void));
+static	int	mkident __P((void));
 static	int	hasparent __P((struct devi *));
 static	int	cfcrosscheck __P((struct config *, const char *,
 		    struct nvlist *));
@@ -275,7 +276,7 @@
 	 * Ready to go.  Build all the various files.
 	 */
 	if (mksymlinks() || mkmakefile() || mkheaders() || mkswap() ||
-	    mkioconf())
+	    mkioconf() || mkident())
 		stop();
 	(void)printf("Don't forget to run \"make depend\"\n");
 	exit(0);
@@ -958,4 +959,31 @@
 			      srcdir);
 		exit(2);
 	}
+}
+
+/*
+ * Write identifier from "ident" directive into file, for
+ * newvers.sh to pick it up.
+ */
+int
+mkident()
+{
+	FILE *fp;
+
+	(void)unlink("ident");
+
+	if (ident == NULL ||
+	    *ident == '\0')
+		return (0);
+	
+	if ((fp = fopen("ident", "w")) == NULL) {
+		(void)fprintf(stderr, "config: cannot write ident: %s\n",
+		    strerror(errno));
+		return (1);
+	}
+	if (fprintf(fp, "%s\n", ident) < 0)
+		return (1);
+	(void)fclose(fp);
+
+	return (0);
 }
Index: usr.sbin/config/scan.l
===================================================================
RCS file: /cvsroot/syssrc/usr.sbin/config/scan.l,v
retrieving revision 1.26
diff -u -r1.26 scan.l
--- scan.l	2000/01/05 11:24:02	1.26
+++ scan.l	2000/01/20 01:08:19
@@ -101,6 +101,7 @@
 file		return XFILE;
 file-system	return FILE_SYSTEM;
 flags		return FLAGS;
+ident		return IDENT;
 include		return INCLUDE;
 machine		return XMACHINE;
 major		return MAJOR;
Index: usr.sbin/config/sem.c
===================================================================
RCS file: /cvsroot/syssrc/usr.sbin/config/sem.c,v
retrieving revision 1.23
diff -u -r1.23 sem.c
--- sem.c	1999/09/21 15:50:19	1.23
+++ sem.c	2000/01/20 01:08:35
@@ -175,6 +175,14 @@
 	}
 }
 
+void
+setident(i)
+	const char *i;
+{
+	ident=emalloc(strlen(i)+1);
+	strcpy(ident, i);
+}
+
 /*
  * Define an attribute, optionally with an interface (a locator list).
  * Since an empty locator list is logically different from "no interface",
Index: usr.sbin/config/sem.h
===================================================================
RCS file: /cvsroot/syssrc/usr.sbin/config/sem.h,v
retrieving revision 1.11
diff -u -r1.11 sem.h
--- sem.h	1998/02/16 22:05:37	1.11
+++ sem.h	2000/01/20 01:08:35
@@ -48,6 +48,7 @@
 
 void		setdefmaxusers __P((int, int, int));
 void		setmaxusers __P((int));
+void		setident __P((const char *));
 int		defattr __P((const char *, struct nvlist *, int));
 void		defdev __P((struct devbase *, struct nvlist *,
 			struct nvlist *, int));

-- 
NetBSD - Better for your uptime than Viagra