Alter config so that it emits a config_time.src file (the source file

for config_time.h) that contains, for example:

/* Sun Nov 17 05:37:51 2002 GMT */
#define CONFIG_TIME     1037511471
#define CONFIG_YEAR     2002
#define CONFIG_MONTH    11
#define CONFIG_DATE     17
#define CONFIG_HOUR      5
#define CONFIG_MINS     37
#define CONFIG_SECS     51

These values represent the current time as of when config was last
run, so that functions (eg, inittodr()) can use these values instead
of being updated once every year or so with the "current" time.

The associated modification to Makefile.kern.inc makes config_time.h
depend on this depend on this and the kernel Makefile, so that
granularity of kernel builds is not reduced.
This commit is contained in:
atatat 2002-11-19 04:29:19 +00:00
parent 399c5e40ce
commit 15d85dcb14
2 changed files with 54 additions and 3 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.kern.inc,v 1.28 2002/11/03 21:12:27 chris Exp $
# $NetBSD: Makefile.kern.inc,v 1.29 2002/11/19 04:29:19 atatat Exp $
#
# This file contains common `MI' targets and definitions and it is included
# at the bottom of each `MD' ${MACHINE}/conf/Makefile.${MACHINE}. There are
@ -189,6 +189,12 @@ vers.o: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP} $S/conf/newvers.sh $S/conf/osrelease.sh
${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
.endif
.if !target(config_time.h)
EXTRA_CLEAN+= config_time.h
config_time.h: Makefile
cp config_time.src config_time.h
.endif
# depend on root or device configuration
autoconf.o conf.o: Makefile

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkheaders.c,v 1.32 2002/06/05 10:56:18 lukem Exp $ */
/* $NetBSD: mkheaders.c,v 1.33 2002/11/19 04:29:19 atatat Exp $ */
/*
* Copyright (c) 1992, 1993
@ -50,12 +50,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "defs.h"
static int emitcnt(struct nvlist *);
static int emitlocs(void);
static int emitopts(void);
static int emitioconfh(void);
static int emittime(void);
static int herr(const char *, const char *, FILE *);
static int locators_print(const char *, void *, void *);
static int defopts_print(const char *, void *, void *);
@ -82,7 +84,7 @@ mkheaders(void)
return (1);
}
if (emitopts() || emitlocs() || emitioconfh())
if (emitopts() || emitlocs() || emitioconfh() || emittime())
return (1);
return (0);
@ -315,6 +317,49 @@ emitioconfh(void)
return (moveifchanged(tfname, "ioconf.h"));
}
/*
* Make a file that config_time.h can use as a source, if required.
*/
static int
emittime(void)
{
FILE *fp;
time_t t;
struct tm *tm;
char buf[128];
t = time(NULL);
tm = gmtime(&t);
if ((fp = fopen("config_time.src", "w")) == NULL)
return (herr("open", "config_time.src", NULL));
if (strftime(buf, sizeof(buf), "%c %Z", tm) == 0)
return (herr("strftime", "config_time.src", NULL));
if (fprintf(fp, "/* %s */\n"
"#define CONFIG_TIME\t%2lld\n"
"#define CONFIG_YEAR\t%2d\n"
"#define CONFIG_MONTH\t%2d\n"
"#define CONFIG_DATE\t%2d\n"
"#define CONFIG_HOUR\t%2d\n"
"#define CONFIG_MINS\t%2d\n"
"#define CONFIG_SECS\t%2d\n",
buf, (long long)t,
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec) < 0)
return (herr("fprintf", "config_time.src", NULL));
if (fclose(fp) != 0)
return (herr("close", "config_time.src", NULL));
/*
* *Don't* moveifchanged this file. Makefile.kern.inc will
* handle that if it determines such a move is necessary.
*/
return (0);
}
/*
* Compare two files. If nfname doesn't exist, or is different from
* tfname, move tfname to nfname. Otherwise, delete tfname.