[Midnightbsd-cvs] src: usr.sbin/config: Merge changes in config(8) with FreeBSD

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Mon Sep 29 22:20:58 EDT 2008


Log Message:
-----------
Merge changes in config(8) with FreeBSD

Modified Files:
--------------
    src/usr.sbin/config:
        Makefile (r1.1.1.1 -> r1.2)
        config.8 (r1.1.1.1 -> r1.2)
        config.h (r1.1.1.1 -> r1.2)
        config.y (r1.1.1.1 -> r1.2)
        configvers.h (r1.1.1.1 -> r1.2)
        lang.l (r1.1.1.1 -> r1.2)
        main.c (r1.1.1.1 -> r1.2)
        mkheaders.c (r1.1.1.1 -> r1.2)
        mkmakefile.c (r1.1.1.1 -> r1.2)
        mkoptions.c (r1.1.1.1 -> r1.2)

-------------- next part --------------
Index: config.8
===================================================================
RCS file: /home/cvs/src/usr.sbin/config/config.8,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/config/config.8 -L usr.sbin/config/config.8 -u -r1.1.1.1 -r1.2
--- usr.sbin/config/config.8
+++ usr.sbin/config/config.8
@@ -26,9 +26,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)config.8	8.2 (Berkeley) 4/19/94
-.\" $FreeBSD: src/usr.sbin/config/config.8,v 1.43.2.1 2005/10/28 19:04:03 jhb Exp $
+.\" $FreeBSD: src/usr.sbin/config/config.8,v 1.46 2007/05/12 19:38:18 wkoszek Exp $
 .\"
-.Dd December 16, 2004
+.Dd May 8, 2007
 .Dt CONFIG 8
 .Os
 .Sh NAME
@@ -36,24 +36,26 @@
 .Nd build system configuration files
 .Sh SYNOPSIS
 .Nm
-.Op Fl Vgp
+.Op Fl CVgp
 .Op Fl d Ar destdir
 .Ar SYSTEM_NAME
-.Sh DESCRIPTION
-This is the old version of the
-.Nm
-utility.
-It understands the old autoconfiguration scheme
-used on the HP300, i386, DECstation, and derivative platforms.
-The new version of
-.Nm
-is used with the
-SPARC platform.
-Only the version of
 .Nm
-applicable to the architecture that you are running
-will be installed on your machine.
-.Pp
+.Op Fl x Ar kernel
+.Sh DESCRIPTION
+.\" This is the old version of the
+.\" .Nm
+.\" utility.
+.\" It understands the old autoconfiguration scheme
+.\" used on the HP300, i386, DECstation, and derivative platforms.
+.\" The new version of
+.\" .Nm
+.\" is used with the
+.\" SPARC platform.
+.\" Only the version of
+.\" .Nm
+.\" applicable to the architecture that you are running
+.\" will be installed on your machine.
+.\" .Pp
 The
 .Nm
 utility builds a set of system configuration files from the file
@@ -76,6 +78,11 @@
 Print the
 .Nm
 version number.
+.It Fl C
+If the INCLUDE_CONFIG_FILE is present in a configuration file,
+kernel image will contain full configuration files included
+literally (preserving comments).
+This flag is kept for backward compatibility.
 .It Fl d Ar destdir
 Use
 .Ar destdir
@@ -87,6 +94,12 @@
 to the directory given.
 .It Fl g
 Configure a system for debugging.
+.It Fl x Ar kernel
+Print kernel configuration file embedded into a kernel
+file.
+This option makes sense only if 
+.Cd "options INCLUDE_CONFIG_FILE"
+entry was present in your configuration file.
 .It Fl p
 Configure a system for profiling; for example,
 .Xr kgmon 8
@@ -151,17 +164,6 @@
 should be run again.
 Attempts to compile a system that had configuration errors
 are likely to fail.
-.Pp
-If the
-.Cd "options INCLUDE_CONFIG_FILE"
-is used in the configuration file the
-entire input file is embedded in the new kernel.
-This means that
-.Xr strings 1
-can be used to extract it from a kernel:
-to extract the configuration information, use the command
-.Pp
-.Dl "strings -n 3 kernel | sed -n 's/^___//p'"
 .Sh DEBUG KERNELS
 Traditional
 .Bx
@@ -254,5 +256,19 @@
 .Nm
 utility appeared in
 .Bx 4.1 .
+.Pp
+Before support for 
+.Fl x
+was introduced,
+.Cd "options INCLUDE_CONFIG_FILE"
+included entire configuration file that used to be embedded in
+the new kernel.
+This meant that
+.Xr strings 1
+could be used to extract it from a kernel:
+to extract the configuration information, you had to use 
+the command:
+.Pp
+.Dl "strings -n 3 kernel | sed -n 's/^___//p'"
 .Sh BUGS
 The line numbers reported in error messages are usually off by one.
Index: configvers.h
===================================================================
RCS file: /home/cvs/src/usr.sbin/config/configvers.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/config/configvers.h -L usr.sbin/config/configvers.h -u -r1.1.1.1 -r1.2
--- usr.sbin/config/configvers.h
+++ usr.sbin/config/configvers.h
@@ -1,11 +1,53 @@
+/*-
+ * This file is in the public domain
+ *
+ * $FreeBSD: src/usr.sbin/config/configvers.h,v 1.45 2007/05/13 02:36:41 wkoszek Exp $
+ */
+
 /*
- * 6 digits of version.  The most significant are branch indicators
- * (eg: RELENG_2_2 = 22, -current presently = 60 etc). The least
- * significant digits are incremented for each incompatible change.
+ * 6 digits of version.  The most significant are branch indicators at the
+ * time when the last incompatible change was made (which is why it is
+ * presently 6 on 7-current).  The least significant digits are incremented
+ * as described below.  The format is similar to the __FreeBSD_version, but
+ * not tied to it.
+ *
+ * DO NOT CASUALLY BUMP THIS NUMBER!  The rules are not the same as shared
+ * libs or param.h/osreldate.
+ *
+ * It is the version number of the protocol between config(8) and the
+ * sys/conf/ Makefiles (the kernel build system).
+ *
+ * It is now also used to trap certain problems that the syntax parser cannot
+ * detect.
+ *
+ * Unfortunately, there is no version number for user supplied config files.
+ *
+ * Once, config(8) used to silently report errors and continue anyway.  This
+ * was a huge problem for 'make buildkernel' which was run with the installed
+ * /usr/sbin/config, not a cross built one.  We started bumping the version
+ * number as a way to trap cases where the previous installworld was not
+ * compatable with the new buildkernel.  The buildtools phase and much more
+ * comprehensive error code returns solved this original problem.
+ *
+ * Most end-users will use buildkernel and the build tools from buildworld.
+ * The people that are inconvenienced by gratuitous bumps are developers
+ * who run config by hand.  However, developers shouldn't gratuitously be
+ * inconvenienced.
+ *
+ * One should bump the CONFIGVERS in the following ways:
  *
- * The numbering scheme is inspired by the sys/conf/newvers.sh RELDATE
- * and <osreldate.h> system.
+ * (1) If you change config such that it won't read old config files,
+ *     then bump the major number.  You shouldn't be doing this unless
+ *     you are overhauling config.  Do not casually bump this number
+ *     and by implication do not make changes that would force a bump
+ *     of this number casually.  You should limit major bumps to once
+ *     per branch.
+ * (2) For each new feature added, bump the minor version of this file.
+ *     When a new feature is actually used by the build system, update the
+ *     %VERSREQ field in the Makefile.$ARCH of all the affected makefiles
+ *     (typically all of them).
  *
- * $FreeBSD: src/usr.sbin/config/configvers.h,v 1.35.2.1 2005/10/28 19:04:03 jhb Exp $
+ * $FreeBSD: src/usr.sbin/config/configvers.h,v 1.45 2007/05/13 02:36:41 wkoszek Exp $
  */
-#define	CONFIGVERS	600003
+#define	CONFIGVERS	600006
+#define	MAJOR_VERS(x)	((x) / 100000)
Index: mkheaders.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/config/mkheaders.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/config/mkheaders.c -L usr.sbin/config/mkheaders.c -u -r1.1.1.1 -r1.2
--- usr.sbin/config/mkheaders.c
+++ usr.sbin/config/mkheaders.c
@@ -32,7 +32,7 @@
 static char sccsid[] = "@(#)mkheaders.c	8.1 (Berkeley) 6/6/93";
 #endif
 static const char rcsid[] =
-  "$FreeBSD: src/usr.sbin/config/mkheaders.c,v 1.30 2004/08/30 23:03:56 peter Exp $";
+  "$FreeBSD: src/usr.sbin/config/mkheaders.c,v 1.31 2005/11/25 22:25:34 ru Exp $";
 #endif /* not lint */
 
 /*
@@ -50,23 +50,10 @@
 void
 headers(void)
 {
-	struct file_list *fl;
 	struct device *dp;
-	int match;
 	int errors;
 
 	errors = 0;
-	STAILQ_FOREACH(fl, &ftab, f_next) {
-		if (fl->f_needs != 0) {
-			match = 0;
-			STAILQ_FOREACH(dp, &dtab, d_next) {
-				if (eq(dp->d_name, fl->f_needs)) {
-					match++;
-					dp->d_done |= DEVDONE;
-				}
-			}
-		}
-	}
 	STAILQ_FOREACH(dp, &dtab, d_next) {
 		if (!(dp->d_done & DEVDONE)) {
 			warnx("Error: device \"%s\" is unknown",
Index: config.h
===================================================================
RCS file: /home/cvs/src/usr.sbin/config/config.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/config/config.h -L usr.sbin/config/config.h -u -r1.1.1.1 -r1.2
--- usr.sbin/config/config.h
+++ usr.sbin/config/config.h
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)config.h	8.1 (Berkeley) 6/6/93
- * $FreeBSD: src/usr.sbin/config/config.h,v 1.56.2.1 2005/10/28 19:04:03 jhb Exp $
+ * $FreeBSD: src/usr.sbin/config/config.h,v 1.62 2007/05/17 04:53:52 imp Exp $
  */
 
 /*
@@ -38,6 +38,12 @@
 #include <stdlib.h>
 #include <string.h>
 
+struct cfgfile {
+	STAILQ_ENTRY(cfgfile)	cfg_next;
+	char	*cfg_path;
+};
+STAILQ_HEAD(, cfgfile) cfgfiles;
+
 struct file_list {
 	STAILQ_ENTRY(file_list) f_next;
 	char	*f_fn;			/* the name */
@@ -46,7 +52,6 @@
 	char	*f_compilewith;		/* special make rule if present */
 	char	*f_depends;		/* additional dependancies */
 	char	*f_clean;		/* File list to add to clean rule */
-	char	*f_needs;
 	char	*f_warn;		/* warning message */
 };
 
@@ -59,7 +64,6 @@
  * Types.
  */
 #define NORMAL		1
-#define	INVISIBLE	2
 #define	PROFILING	3
 #define NODEPEND	4
 #define LOCAL		5
@@ -72,7 +76,6 @@
 #define NO_IMPLCT_RULE	1
 #define NO_OBJ		2
 #define BEFORE_DEPEND	4
-#define ISDUP		8
 #define NOWERROR	16
 
 struct device {
@@ -120,7 +123,7 @@
 	SLIST_ENTRY(opt) op_next;
 };
 
-SLIST_HEAD(opt_head, opt) opt, mkopt;
+SLIST_HEAD(opt_head, opt) opt, mkopt, rmopts;
 
 struct opt_list {
 	char *o_name;
@@ -130,12 +133,33 @@
 
 SLIST_HEAD(, opt_list) otab;
 
+struct hint {
+	char	*hint_name;
+	STAILQ_ENTRY(hint) hint_next;
+};
+
+STAILQ_HEAD(hint_head, hint) hints;
+
+/*
+ * Tag present in the kernelconf.tmlp template file. It's mandatory for those
+ * two strings to be the same. Otherwise you'll get into trouble.
+ */
+#define	KERNCONFTAG	"%%KERNCONFFILE%%"
+
+/*
+ * Faked option to note, that the configuration file has been taken from the
+ * kernel file and inclusion of DEFAULTS etc.. isn't nessesery, because we
+ * already have a list of all required devices.
+ */
+#define OPT_AUTOGEN	"CONFIG_AUTOGENERATED"
+
 extern char	*ident;
 extern char	*env;
-extern char	*hints;
+extern char	kernconfstr[];
 extern int	do_trace;
 extern int	envmode;
 extern int	hintmode;
+extern int	incignore;
 
 char	*get_word(FILE *);
 char	*get_quoted_word(FILE *);
@@ -147,7 +171,11 @@
 int	yylex(void);
 void	options(void);
 void	makefile(void);
+void	makeenv(void);
+void	makehints(void);
 void	headers(void);
+void	cfgfile_add(const char *);
+void	cfgfile_removeall(void);
 
 extern STAILQ_HEAD(device_head, device) dtab;
 
Index: main.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/config/main.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/config/main.c -L usr.sbin/config/main.c -u -r1.1.1.1 -r1.2
--- usr.sbin/config/main.c
+++ usr.sbin/config/main.c
@@ -38,17 +38,21 @@
 static char sccsid[] = "@(#)main.c	8.1 (Berkeley) 6/6/93";
 #endif
 static const char rcsid[] =
-  "$FreeBSD: src/usr.sbin/config/main.c,v 1.64.2.1 2005/10/28 19:04:03 jhb Exp $";
+  "$FreeBSD: src/usr.sbin/config/main.c,v 1.76 2007/05/17 04:53:52 imp Exp $";
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/sbuf.h>
 #include <sys/file.h>
 #include <sys/mman.h>
 #include <sys/param.h>
+
+#include <assert.h>
 #include <ctype.h>
 #include <err.h>
 #include <stdio.h>
+#include <string.h>
 #include <sysexits.h>
 #include <unistd.h>
 #include <dirent.h>
@@ -73,11 +77,19 @@
 int	debugging;
 int	profiling;
 int	found_defaults;
+int	incignore;
+
+/*
+ * Preserve old behaviour in INCLUDE_CONFIG_FILE handling (files are included
+ * literally).
+ */
+int	filebased = 0;
 
 static void configfile(void);
 static void get_srcdir(void);
 static void usage(void);
 static void cleanheaders(char *);
+static void kernconfdump(const char *);
 
 struct hdr_list {
 	char *h_name;
@@ -96,12 +108,14 @@
 	int ch, len;
 	char *p;
 	char xxx[MAXPATHLEN];
+	char *kernfile;
 
-	while ((ch = getopt(argc, argv, "d:gpV")) != -1)
+	kernfile = NULL;
+	while ((ch = getopt(argc, argv, "Cd:gpVx:")) != -1)
 		switch (ch) {
-		case 'V':
-			printf("%d\n", CONFIGVERS);
-			exit(0);
+		case 'C':
+			filebased = 1;
+			break;
 		case 'd':
 			if (*destdir == '\0')
 				strlcpy(destdir, optarg, sizeof(destdir));
@@ -114,6 +128,12 @@
 		case 'p':
 			profiling++;
 			break;
+		case 'V':
+			printf("%d\n", CONFIGVERS);
+			exit(0);
+		case 'x':
+			kernfile = optarg;
+			break;
 		case '?':
 		default:
 			usage();
@@ -121,6 +141,11 @@
 	argc -= optind;
 	argv += optind;
 
+	if (kernfile != NULL) {
+		kernconfdump(kernfile);
+		exit(EXIT_SUCCESS);
+	}
+
 	if (argc != 1)
 		usage();
 
@@ -133,7 +158,6 @@
 			err(2, "%s", PREFIX);
 		yyfile = PREFIX;
 	}
-
 	if (*destdir != '\0') {
 		len = strlen(destdir);
 		while (len > 1 && destdir[len - 1] == '/')
@@ -148,20 +172,37 @@
 	if (stat(p, &buf)) {
 		if (mkdir(p, 0777))
 			err(2, "%s", p);
-	}
-	else if ((buf.st_mode & S_IFMT) != S_IFDIR)
+	} else if (!S_ISDIR(buf.st_mode))
 		errx(2, "%s isn't a directory", p);
 
+	SLIST_INIT(&cputype);
+	SLIST_INIT(&mkopt);
+	SLIST_INIT(&opt);
+	SLIST_INIT(&rmopts);
+	STAILQ_INIT(&cfgfiles);
 	STAILQ_INIT(&dtab);
 	STAILQ_INIT(&fntab);
-	SLIST_INIT(&cputype);
 	STAILQ_INIT(&ftab);
+	STAILQ_INIT(&hints);
 	if (yyparse())
 		exit(3);
+
+	/*
+	 * Ensure that required elements (machine, cpu, ident) are present.
+	 */
 	if (machinename == NULL) {
 		printf("Specify machine type, e.g. ``machine i386''\n");
 		exit(1);
 	}
+	if (ident == NULL) {
+		printf("no ident line specified\n");
+		exit(1);
+	}
+	if (SLIST_EMPTY(&cputype)) {
+		printf("cpu type must be specified\n");
+		exit(1);
+	}
+
 	/*
 	 * make symbolic links in compilation directory
 	 * for "sys" (to make genassym.c work along with #include <sys/xxx>)
@@ -188,13 +229,15 @@
 		(void) unlink(path(machinearch));
 		(void) symlink(xxx, path(machinearch));
 	}
+	configfile();			/* put config file into kernel*/
 	options();			/* make options .h files */
 	makefile();			/* build Makefile */
+	makeenv();			/* build env.c */
+	makehints();			/* build hints.c */
 	headers();			/* make a lot of .h files */
-	configfile();			/* put config file into kernel*/
 	cleanheaders(p);
 	printf("Kernel build directory is %s\n", p);
-	printf("Don't forget to do ``make cleandepend; make depend''\n");
+	printf("Don't forget to do ``make cleandepend && make depend''\n");
 	exit(0);
 }
 
@@ -215,8 +258,9 @@
 usage(void)
 {
 
-	fprintf(stderr, "usage: config [-Vgp] [-d destdir] sysname\n");
-	exit(1);
+	fprintf(stderr, "usage: config [-CgpV] [-d destdir] sysname\n");
+	fprintf(stderr, "       config -x kernel\n");
+	exit(EX_USAGE);
 }
 
 /*
@@ -342,40 +386,129 @@
 	return (cp);
 }
 
+/*
+ * Generate configuration file based on actual settings. With this mode, user
+ * will be able to obtain and build conifguration file with one command.
+ */
+static void
+configfile_dynamic(struct sbuf *sb)
+{
+	struct cputype *cput;
+	struct device *d;
+	struct opt *ol;
+	char *lend;
+	unsigned int i;
+
+	asprintf(&lend, "\\n\\\n");
+	assert(lend != NULL);
+	sbuf_printf(sb, "options\t%s%s", OPT_AUTOGEN, lend);
+	sbuf_printf(sb, "ident\t%s%s", ident, lend);
+	sbuf_printf(sb, "machine\t%s%s", machinename, lend);
+	SLIST_FOREACH(cput, &cputype, cpu_next)
+		sbuf_printf(sb, "cpu\t%s%s", cput->cpu_name, lend);
+	SLIST_FOREACH(ol, &mkopt, op_next)
+		sbuf_printf(sb, "makeoptions\t%s=%s%s", ol->op_name,
+		    ol->op_value, lend);
+	SLIST_FOREACH(ol, &opt, op_next) {
+		if (strncmp(ol->op_name, "DEV_", 4) == 0)
+			continue;
+		sbuf_printf(sb, "options\t%s", ol->op_name);
+		if (ol->op_value != NULL) {
+			sbuf_putc(sb, '=');
+			for (i = 0; i < strlen(ol->op_value); i++) {
+				if (ol->op_value[i] == '"')
+					sbuf_printf(sb, "\\%c",
+					    ol->op_value[i]);
+				else
+					sbuf_printf(sb, "%c",
+					    ol->op_value[i]);
+			}
+			sbuf_printf(sb, "%s", lend);
+		} else {
+			sbuf_printf(sb, "%s", lend);
+		}
+	}
+	/*
+	 * Mark this file as containing everything we need.
+	 */
+	STAILQ_FOREACH(d, &dtab, d_next)
+		sbuf_printf(sb, "device\t%s%s", d->d_name, lend);
+	free(lend);
+}
+
+/*
+ * Generate file from the configuration files.
+ */
+static void
+configfile_filebased(struct sbuf *sb)
+{
+	FILE *cff;
+	struct cfgfile *cf;
+	int i;
+
+	STAILQ_FOREACH(cf, &cfgfiles, cfg_next) {
+		cff = fopen(cf->cfg_path, "r");
+		if (cff == NULL) {
+			warn("Couldn't open file %s", cf->cfg_path);
+			continue;
+		}
+		while ((i = getc(cff)) != EOF) {
+			if (i == '\n')
+				sbuf_printf(sb, "\\n\\\n");
+			else if (i == '"' || i == '\'')
+				sbuf_printf(sb, "\\%c", i);
+			else
+				sbuf_putc(sb, i);
+		}
+		fclose(cff);
+	}
+}
+
 static void
 configfile(void)
 {
-	FILE *fi, *fo;
+	FILE *fo;
+	struct sbuf *sb;
 	char *p;
-	int i;
-	
-	fi = fopen(PREFIX, "r");
-	if (!fi)
-		err(2, "%s", PREFIX);
-	fo = fopen(p=path("config.c.new"), "w");
+
+	/* Add main configuration file to the list of files to be included */
+	cfgfile_add(PREFIX);
+	p = path("config.c.new");
+	fo = fopen(p, "w");
 	if (!fo)
 		err(2, "%s", p);
-	fprintf(fo, "#include \"opt_config.h\"\n");
-	fprintf(fo, "#ifdef INCLUDE_CONFIG_FILE \n");
-	fprintf(fo, "const char config[] = \"\\\n");
-	fprintf(fo, "START CONFIG FILE %s\\n\\\n___", PREFIX);
-	while (EOF != (i=getc(fi))) {
-		if (i == '\n') {
-			fprintf(fo, "\\n\\\n___");
-		} else if (i == '\"') {
-			fprintf(fo, "\\\"");
-		} else if (i == '\\') {
-			fprintf(fo, "\\\\");
-		} else {
-			putc(i, fo);
-		}
+	sb = sbuf_new(NULL, NULL, 2048, SBUF_AUTOEXTEND);
+	assert(sb != NULL);
+	sbuf_clear(sb);
+	/*
+	 * Try to read all configuration files. Since those will be present as
+	 * C string in the macro, we have to slash their ends then the line
+	 * wraps.
+	 */
+	if (filebased) {
+		/* Is needed, can be used for backward compatibility. */
+		configfile_filebased(sb);
+	} else {
+		configfile_dynamic(sb);
 	}
-	fprintf(fo, "\\n\\\nEND CONFIG FILE %s\\n\\\n", PREFIX);
-	fprintf(fo, "\";\n");
-	fprintf(fo, "\n#endif /* INCLUDE_CONFIG_FILE */\n");
-	fclose(fi);
+	sbuf_finish(sb);
+	/* 
+	 * We print first part of the tamplate, replace our tag with
+	 * configuration files content and later continue writing our
+	 * template.
+	 */
+	p = strstr(kernconfstr, KERNCONFTAG);
+	if (p == NULL)
+		errx(EXIT_FAILURE, "Something went terribly wrong!");
+	*p = '\0';
+	fprintf(fo, "%s", kernconfstr);
+	fprintf(fo, "%s", sbuf_data(sb));
+	p += strlen(KERNCONFTAG);
+	fprintf(fo, "%s", p);
+	sbuf_delete(sb);
 	fclose(fo);
 	moveifchanged(path("config.c.new"), path("config.c"));
+	cfgfile_removeall();
 }
 
 /*
@@ -465,7 +598,7 @@
 			continue;
 		/* Check if it is a target file */
 		for (hl = htab; hl != NULL; hl = hl->h_next) {
-			if (strcmp(dp->d_name, hl->h_name) == 0) {
+			if (eq(dp->d_name, hl->h_name)) {
 				break;
 			}
 		}
@@ -494,14 +627,67 @@
 		return;
 	}
 	for (hl = htab; hl != NULL; hl = hl->h_next) {
-		if (strcmp(s, hl->h_name) == 0) {
+		if (eq(s, hl->h_name)) {
 			free(s);
 			return;
 		}
 	}
-	hl = malloc(sizeof(*hl));
-	bzero(hl, sizeof(*hl));
+	hl = calloc(1, sizeof(*hl));
 	hl->h_name = s;
 	hl->h_next = htab;
 	htab = hl;
 }
+
+/*
+ * This one is quick hack. Will be probably moved to elf(3) interface.
+ * It takes kernel configuration file name, passes it as an argument to
+ * elfdump -a, which output is parsed by some UNIX tools...
+ */
+static void
+kernconfdump(const char *file)
+{
+	struct stat st;
+	FILE *fp, *pp;
+	int error, len, osz, r;
+	unsigned int off, size;
+	char *cmd, *o;
+
+	r = open(file, O_RDONLY);
+	if (r == -1)
+		errx(EXIT_FAILURE, "Couldn't open file '%s'", file);
+	error = fstat(r, &st);
+	if (error == -1)
+		errx(EXIT_FAILURE, "fstat() failed");
+	if (S_ISDIR(st.st_mode))
+		errx(EXIT_FAILURE, "'%s' is a directory", file);
+	fp = fdopen(r, "r");
+	if (fp == NULL)
+		errx(EXIT_FAILURE, "fdopen() failed");
+	osz = 1024;
+	o = calloc(1, osz);
+	if (o == NULL)
+		errx(EXIT_FAILURE, "Couldn't allocate memory");
+	/* ELF note section header. */
+	asprintf(&cmd, "/usr/bin/elfdump -c %s | grep -A 5 kern_conf"
+	    "| tail -2 | cut -d ' ' -f 2 | paste - - -", file);
+	if (cmd == NULL)
+		errx(EXIT_FAILURE, "asprintf() failed");
+	pp = popen(cmd, "r");
+	if (pp == NULL)
+		errx(EXIT_FAILURE, "popen() failed");
+	free(cmd);
+	len = fread(o, osz, 1, pp);
+	pclose(pp);
+	r = sscanf(o, "%d\t%d", &off, &size);
+	free(o);
+	if (r != 2)
+		errx(EXIT_FAILURE, "File %s doesn't contain configuration "
+		    "file. Either unsupported, or not compiled with "
+		    "INCLUDE_CONFIG_FILE", file);
+	r = fseek(fp, off, SEEK_CUR);
+	if (r != 0)
+		errx(EXIT_FAILURE, "fseek() failed");
+	while ((r = fgetc(fp)) != EOF && size-- > 0)
+		fputc(r, stdout);
+	fclose(fp);
+}
Index: mkoptions.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/config/mkoptions.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/config/mkoptions.c -L usr.sbin/config/mkoptions.c -u -r1.1.1.1 -r1.2
--- usr.sbin/config/mkoptions.c
+++ usr.sbin/config/mkoptions.c
@@ -33,7 +33,7 @@
 static char sccsid[] = "@(#)mkheaders.c	8.1 (Berkeley) 6/6/93";
 #endif
 static const char rcsid[] =
-  "$FreeBSD: src/usr.sbin/config/mkoptions.c,v 1.32 2004/08/07 04:19:37 imp Exp $";
+  "$FreeBSD: src/usr.sbin/config/mkoptions.c,v 1.34 2006/06/07 01:43:26 delphij Exp $";
 #endif /* not lint */
 
 /*
@@ -69,8 +69,7 @@
 
 	/* Fake the cpu types as options. */
 	SLIST_FOREACH(cp, &cputype, cpu_next) {
-		op = (struct opt *)malloc(sizeof(*op));
-		memset(op, 0, sizeof(*op));
+		op = (struct opt *)calloc(1, sizeof(*op));
 		op->op_name = ns(cp->cpu_name);
 		SLIST_INSERT_HEAD(&opt, op, op_next);
 	}	
@@ -84,8 +83,7 @@
 		printf("warning: maxusers > %d (%d)\n", users.u_max, maxusers);
 
 	/* Fake MAXUSERS as an option. */
-	op = (struct opt *)malloc(sizeof(*op));
-	memset(op, 0, sizeof(*op));
+	op = (struct opt *)calloc(1, sizeof(*op));
 	op->op_name = ns("MAXUSERS");
 	snprintf(buf, sizeof(buf), "%d", maxusers);
 	op->op_value = ns(buf);
@@ -200,8 +198,7 @@
 				inw, basefile, ol->o_file);
 			tidy++;
 		} else {
-			op = (struct opt *) malloc(sizeof *op);
-			bzero(op, sizeof(*op));
+			op = (struct opt *) calloc(1, sizeof *op);
 			op->op_name = inw;
 			op->op_value = invalue;
 			SLIST_INSERT_HEAD(&op_head, op, op_next);
@@ -227,8 +224,7 @@
 
 	if (value && !seen) {
 		/* New option appears */
-		op = (struct opt *) malloc(sizeof *op);
-		bzero(op, sizeof(*op));
+		op = (struct opt *) calloc(1, sizeof *op);
 		op->op_name = ns(name);
 		op->op_value = value ? ns(value) : NULL;
 		SLIST_INSERT_HEAD(&op_head, op, op_next);
@@ -290,10 +286,6 @@
 	char genopt[MAXPATHLEN];
 
 	SLIST_INIT(&otab);
-	if (ident == NULL) {
-		printf("no ident line specified\n");
-		exit(1);
-	}
 	(void) snprintf(fname, sizeof(fname), "../../conf/options");
 openit:
 	fp = fopen(fname, "r");
@@ -343,8 +335,7 @@
 		}
 	}
 	
-	po = (struct opt_list *) malloc(sizeof *po);
-	bzero(po, sizeof(*po));
+	po = (struct opt_list *) calloc(1, sizeof *po);
 	po->o_name = this;
 	po->o_file = val;
 	SLIST_INSERT_HEAD(&otab, po, o_next);
Index: config.y
===================================================================
RCS file: /home/cvs/src/usr.sbin/config/config.y,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/config/config.y -L usr.sbin/config/config.y -u -r1.1.1.1 -r1.2
--- usr.sbin/config/config.y
+++ usr.sbin/config/config.y
@@ -67,9 +67,10 @@
  * SUCH DAMAGE.
  *
  *	@(#)config.y	8.1 (Berkeley) 6/6/93
- * $FreeBSD: src/usr.sbin/config/config.y,v 1.66.2.2 2005/12/01 17:43:09 ru Exp $
+ * $FreeBSD: src/usr.sbin/config/config.y,v 1.78 2007/05/17 04:53:52 imp Exp $
  */
 
+#include <assert.h>
 #include <ctype.h>
 #include <err.h>
 #include <stdio.h>
@@ -81,7 +82,6 @@
 char	*ident;
 char	*env;
 int	envmode;
-char	*hints;
 int	hintmode;
 int	yyline;
 const	char *yyfile;
@@ -123,7 +123,10 @@
 	Config_spec SEMICOLON
 		|
 	INCLUDE ID SEMICOLON
-	      = { include($2, 0); };
+	      = {
+	          if (incignore == 0)
+		  	include($2, 0);
+		};
 		|
 	FILES ID SEMICOLON
 	      = { newfile($2); };
@@ -136,7 +139,7 @@
 Config_spec:
 	ARCH Save_id
 	    = {
-		if (machinename != NULL)
+		if (machinename != NULL && !eq($2, machinename))
 		    errx(1, "%s:%d: only one machine directive is allowed",
 			yyfile, yyline);
 		machinename = $2;
@@ -144,7 +147,8 @@
 	      } |
 	ARCH Save_id Save_id
 	    = {
-		if (machinename != NULL)
+		if (machinename != NULL &&
+		    !(eq($2, machinename) && eq($3, machinearch)))
 		    errx(1, "%s:%d: only one machine directive is allowed",
 			yyfile, yyline);
 		machinename = $2;
@@ -153,8 +157,7 @@
 	CPU Save_id
 	      = {
 		struct cputype *cp =
-		    (struct cputype *)malloc(sizeof (struct cputype));
-		memset(cp, 0, sizeof(*cp));
+		    (struct cputype *)calloc(1, sizeof (struct cputype));
 		cp->cpu_name = $2;
 		SLIST_INSERT_HEAD(&cputype, cp, cpu_next);
 	      } |
@@ -162,21 +165,20 @@
 	      = {
 		struct cputype *cp, *cp2;
 		SLIST_FOREACH_SAFE(cp, &cputype, cpu_next, cp2) {
-			if (strcmp(cp->cpu_name, $2) != 0)
-				continue;
-			SLIST_REMOVE(&cputype, cp, cputype, cpu_next);
-			free(cp);
-			break;
+			if (eq(cp->cpu_name, $2)) {
+				SLIST_REMOVE(&cputype, cp, cputype, cpu_next);
+				free(cp);
+			}
 		}
 	      } |
 	OPTIONS Opt_list
 		|
 	NOOPTION Save_id
-	      = { rmopt(&opt, $2); } |
+	      = { rmopt_schedule(&opt, $2); } |
 	MAKEOPTIONS Mkopt_list
 		|
 	NOMAKEOPTION Save_id
-	      = { rmopt(&mkopt, $2); } |
+	      = { rmopt_schedule(&mkopt, $2); } |
 	IDENT ID
 	      = { ident = $2; } |
 	System_spec
@@ -187,13 +189,17 @@
 	      = { profiling = $2; } |
 	ENV ID
 	      = {
-		      env = $2;
-		      envmode = 1;
+		env = $2;
+		envmode = 1;
 		} |
 	HINTS ID
 	      = {
-		      hints = $2;
-		      hintmode = 1;
+		struct hint *hint;
+
+		hint = (struct hint *)calloc(1, sizeof (struct hint));
+		hint->hint_name = $2;
+		STAILQ_INSERT_TAIL(&hints, hint, hint_next);
+		hintmode = 1;
 	        }
 
 System_spec:
@@ -222,10 +228,8 @@
 Option:
 	Save_id
 	      = {
-		char *s;
-
 		newopt(&opt, $1, NULL);
-		if ((s = strchr($1, '=')))
+		if (strchr($1, '=') != NULL)
 			errx(1, "%s:%d: The `=' in options should not be "
 			    "quoted", yyfile, yyline);
 	      } |
@@ -298,10 +302,10 @@
 	      = {
 		char *s = devopt($1);
 
-		rmopt(&opt, s);
+		rmopt_schedule(&opt, s);
 		free(s);
 		/* and the device part */
-		rmdev($1);
+		rmdev_schedule(&dtab, $1);
 		} ;
 
 %%
@@ -316,7 +320,6 @@
 int
 yywrap(void)
 {
-
 	if (found_defaults) {
 		if (freopen(PREFIX, "r", stdin) == NULL)
 			err(2, "%s", PREFIX);		
@@ -336,76 +339,115 @@
 {
 	struct files_name *nl;
 	
-	nl = (struct files_name *) malloc(sizeof *nl);
-	bzero(nl, sizeof *nl);
+	nl = (struct files_name *) calloc(1, sizeof *nl);
 	nl->f_name = name;
 	STAILQ_INSERT_TAIL(&fntab, nl, f_next);
 }
 	
 /*
- * add a device to the list of devices
+ * Find a device in the list of devices.
+ */
+static struct device *
+finddev(struct device_head *dlist, char *name)
+{
+	struct device *dp;
+
+	STAILQ_FOREACH(dp, dlist, d_next)
+		if (eq(dp->d_name, name))
+			return (dp);
+
+	return (NULL);
+}
+	
+/*
+ * Add a device to the list of devices.
  */
 static void
 newdev(char *name)
 {
 	struct device *np;
 
-	np = (struct device *) malloc(sizeof *np);
-	memset(np, 0, sizeof(*np));
+	if (finddev(&dtab, name)) {
+		printf("WARNING: duplicate device `%s' encountered.\n", name);
+		return;
+	}
+
+	np = (struct device *) calloc(1, sizeof *np);
 	np->d_name = name;
 	STAILQ_INSERT_TAIL(&dtab, np, d_next);
 }
 
 /*
- * remove a device from the list of devices
+ * Schedule a device to removal.
  */
 static void
-rmdev(char *name)
+rmdev_schedule(struct device_head *dh, char *name)
 {
-	struct device *dp, *rmdp;
+	struct device *dp;
 
-	STAILQ_FOREACH(dp, &dtab, d_next) {
-		if (eq(dp->d_name, name)) {
-			rmdp = dp;
-			dp = STAILQ_NEXT(dp, d_next);
-			STAILQ_REMOVE(&dtab, rmdp, device, d_next);
-			free(rmdp->d_name);
-			free(rmdp);
-			if (dp == NULL)
-				break;
-		}
+	dp = finddev(dh, name);
+	if (dp != NULL) {
+		STAILQ_REMOVE(dh, dp, device, d_next);
+		free(dp->d_name);
+		free(dp);
 	}
 }
 
+/*
+ * Find an option in the list of options.
+ */
+static struct opt *
+findopt(struct opt_head *list, char *name)
+{
+	struct opt *op;
+
+	SLIST_FOREACH(op, list, op_next)
+		if (eq(op->op_name, name))
+			return (op);
+
+	return (NULL);
+}
+
+/*
+ * Add an option to the list of options.
+ */
 static void
 newopt(struct opt_head *list, char *name, char *value)
 {
 	struct opt *op;
 
-	op = (struct opt *)malloc(sizeof (struct opt));
-	memset(op, 0, sizeof(*op));
+	/*
+	 * Ignore inclusions listed explicitly for configuration files.
+	 */
+	if (eq(name, OPT_AUTOGEN)) {
+		incignore = 1;
+		return;
+	}
+
+	if (findopt(list, name)) {
+		printf("WARNING: duplicate option `%s' encountered.\n", name);
+		return;
+	}
+
+	op = (struct opt *)calloc(1, sizeof (struct opt));
 	op->op_name = name;
 	op->op_ownfile = 0;
 	op->op_value = value;
 	SLIST_INSERT_HEAD(list, op, op_next);
 }
 
+/*
+ * Remove an option from the list of options.
+ */
 static void
-rmopt(struct opt_head *list, char *name)
+rmopt_schedule(struct opt_head *list, char *name)
 {
-	struct opt *op, *rmop;
+	struct opt *op;
 
-	SLIST_FOREACH(op, list, op_next) {
-		if (eq(op->op_name, name)) {
-			rmop = op;
-			op = SLIST_NEXT(op, op_next);
-			SLIST_REMOVE(list, rmop, opt, op_next);
-			free(rmop->op_name);
-			if (rmop->op_value != NULL)
-				free(rmop->op_value);
-			free(rmop);
-			if (op == NULL)
-				break;
-		}
+	op = findopt(list, name);
+	if (op != NULL) {
+		SLIST_REMOVE(list, op, opt, op_next);
+		free(op->op_name);
+		free(op);
 	}
 }
Index: mkmakefile.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/config/mkmakefile.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/config/mkmakefile.c -L usr.sbin/config/mkmakefile.c -u -r1.1.1.1 -r1.2
--- usr.sbin/config/mkmakefile.c
+++ usr.sbin/config/mkmakefile.c
@@ -32,7 +32,7 @@
 static char sccsid[] = "@(#)mkmakefile.c	8.1 (Berkeley) 6/6/93";
 #endif
 static const char rcsid[] =
-  "$FreeBSD: src/usr.sbin/config/mkmakefile.c,v 1.81 2004/08/30 23:03:56 peter Exp $";
+  "$FreeBSD: src/usr.sbin/config/mkmakefile.c,v 1.91 2006/10/24 07:12:31 imp Exp $";
 #endif /* not lint */
 
 /*
@@ -97,8 +97,7 @@
 {
 	struct file_list *fp;
 
-	fp = (struct file_list *) malloc(sizeof *fp);
-	bzero(fp, sizeof *fp);
+	fp = (struct file_list *) calloc(1, sizeof *fp);
 	STAILQ_INSERT_TAIL(&ftab, fp, f_next);
 	return (fp);
 }
@@ -113,7 +112,6 @@
 	char line[BUFSIZ];
 	struct opt *op;
 	int versreq;
-	char *s;
 
 	read_files();
 	snprintf(line, sizeof(line), "../../conf/Makefile.%s", machinename);
@@ -125,12 +123,6 @@
 	if (ifp == 0)
 		err(1, "%s", line);
 
-	/* XXX this check seems to be misplaced. */
-	if (SLIST_EMPTY(&cputype)) {
-		printf("cpu type must be specified\n");
-		exit(1);
-	}
-
 	ofp = fopen(path("Makefile.new"), "w");
 	if (ofp == 0)
 		err(1, "%s", path("Makefile.new"));
@@ -160,7 +152,8 @@
 			do_clean(ofp);
 		else if (strncmp(line, "%VERSREQ=", sizeof("%VERSREQ=") - 1) == 0) {
 			versreq = atoi(line + sizeof("%VERSREQ=") - 1);
-			if (versreq != CONFIGVERS) {
+			if (MAJOR_VERS(versreq) != MAJOR_VERS(CONFIGVERS) ||
+			    versreq > CONFIGVERS) {
 				fprintf(stderr, "ERROR: version of config(8) does not match kernel!\n");
 				fprintf(stderr, "config version = %d, ", CONFIGVERS);
 				fprintf(stderr, "version required = %d\n\n", versreq);
@@ -181,15 +174,19 @@
 	(void) fclose(ifp);
 	(void) fclose(ofp);
 	moveifchanged(path("Makefile.new"), path("Makefile"));
+}
+
+/*
+ * Build hints.c from the skeleton
+ */
+void
+makehints(void)
+{
+	FILE *ifp, *ofp;
+	char line[BUFSIZ];
+	char *s;
+	struct hint *hint;
 
-	/* XXX makefile() should make the Makefile, not hints.c. */
-	if (hints) {
-		ifp = fopen(hints, "r");
-		if (ifp == NULL)
-			err(1, "%s", hints);
-	} else {
-		ifp = NULL;
-	}
 	ofp = fopen(path("hints.c.new"), "w");
 	if (ofp == NULL)
 		err(1, "%s", path("hints.c.new"));
@@ -198,7 +195,10 @@
 	fprintf(ofp, "\n");
 	fprintf(ofp, "int hintmode = %d;\n", hintmode);
 	fprintf(ofp, "char static_hints[] = {\n");
-	if (ifp) {
+	STAILQ_FOREACH(hint, &hints, hint_next) {
+		ifp = fopen(hint->hint_name, "r");
+		if (ifp == NULL)
+			err(1, "%s", hint->hint_name);
 		while (fgets(line, BUFSIZ, ifp) != 0) {
 			/* zap trailing CR and/or LF */
 			while ((s = rindex(line, '\n')) != NULL)
@@ -228,14 +228,23 @@
 				continue;
 			fprintf(ofp, "\"%s\\0\"\n", line);
 		}
+		fclose(ifp);
 	}
 	fprintf(ofp, "\"\\0\"\n};\n");
-	if (ifp)
-		fclose(ifp);
 	fclose(ofp);
 	moveifchanged(path("hints.c.new"), path("hints.c"));
+}
+
+/*
+ * Build env.c from the skeleton
+ */
+void
+makeenv(void)
+{
+	FILE *ifp, *ofp;
+	char line[BUFSIZ];
+	char *s;
 
-	/* XXX makefile() should make the Makefile, not env.c. */
 	if (env) {
 		ifp = fopen(env, "r");
 		if (ifp == NULL)
@@ -292,12 +301,13 @@
 static void
 read_file(char *fname)
 {
+	char ifname[MAXPATHLEN];
 	FILE *fp;
-	struct file_list *tp, *pf;
+	struct file_list *tp;
 	struct device *dp;
 	struct opt *op;
-	char *wd, *this, *needs, *compilewith, *depends, *clean, *warning;
-	int nreqs, isdup, std, filetype,
+	char *wd, *this, *compilewith, *depends, *clean, *warning;
+	int compile, match, nreqs, std, filetype,
 	    imp_rule, no_obj, before_depend, mandatory, nowerror;
 
 	fp = fopen(fname, "r");
@@ -305,8 +315,9 @@
 		err(1, "%s", fname);
 next:
 	/*
+	 * include "filename"
 	 * filename    [ standard | mandatory | optional ]
-	 *	[ dev* | profiling-routine ] [ no-obj ]
+	 *	[ dev* [ | dev* ... ] | profiling-routine ] [ no-obj ]
 	 *	[ compile-with "compile rule" [no-implicit-rule] ]
 	 *      [ dependency "dependency-list"] [ before-depend ]
 	 *	[ clean "file-list"] [ warning "text warning" ]
@@ -324,6 +335,18 @@
 			;
 		goto next;
 	}
+	if (eq(wd, "include")) {
+		next_quoted_word(fp, wd);
+		if (wd == 0) {
+			printf("%s: missing include filename.\n", fname);
+			exit(1);
+		}
+		(void) snprintf(ifname, sizeof(ifname), "../../%s", wd);
+		read_file(ifname);
+		while (((wd = get_word(fp)) != (char *)EOF) && wd)
+			;
+		goto next;
+	}
 	this = ns(wd);
 	next_word(fp, wd);
 	if (wd == 0) {
@@ -331,17 +354,14 @@
 		    fname, this);
 		exit(1);
 	}
-	if ((pf = fl_lookup(this)) && (pf->f_type != INVISIBLE || pf->f_flags))
-		isdup = ISDUP;
-	else
-		isdup = 0;
-	tp = 0;
+	tp = fl_lookup(this);
+	compile = 0;
+	match = 1;
 	nreqs = 0;
 	compilewith = 0;
 	depends = 0;
 	clean = 0;
 	warning = 0;
-	needs = 0;
 	std = mandatory = 0;
 	imp_rule = 0;
 	no_obj = 0;
@@ -365,9 +385,21 @@
 nextparam:
 	next_word(fp, wd);
 	if (wd == 0) {
-		if (isdup)
-			goto next;
-		goto doneparam;
+		compile += match;
+		if (compile && tp == NULL)
+			goto doneparam;
+		goto next;
+	}
+	if (eq(wd, "|")) {
+		if (nreqs == 0) {
+			printf("%s: syntax error describing %s\n",
+			    fname, this);
+			exit(1);
+		}
+		compile += match;
+		match = 1;
+		nreqs = 0;
+		goto nextparam;
 	}
 	if (eq(wd, "no-obj")) {
 		no_obj++;
@@ -443,13 +475,11 @@
 		nowerror = 1;
 		goto nextparam;
 	}
-	if (needs == 0 && nreqs == 1)
-		needs = ns(wd);
-	if (isdup)
-		goto invis;
 	STAILQ_FOREACH(dp, &dtab, d_next)
-		if (eq(dp->d_name, wd))
+		if (eq(dp->d_name, wd)) {
+			dp->d_done |= DEVDONE;
 			goto nextparam;
+		}
 	if (mandatory) {
 		printf("%s: mandatory device \"%s\" not found\n",
 		       fname, wd);
@@ -461,27 +491,10 @@
 		exit(1);
 	}
 	SLIST_FOREACH(op, &opt, op_next)
-		if (op->op_value == 0 && opteq(op->op_name, wd)) {
-			if (nreqs == 1) {
-				free(needs);
-				needs = 0;
-			}
+		if (op->op_value == 0 && opteq(op->op_name, wd))
 			goto nextparam;
-		}
-invis:
-	while ((wd = get_word(fp)) != 0)
-		;
-	if (tp == 0)
-		tp = new_fent();
-	tp->f_fn = this;
-	tp->f_type = INVISIBLE;
-	tp->f_needs = needs;
-	tp->f_flags |= isdup;
-	tp->f_compilewith = compilewith;
-	tp->f_depends = depends;
-	tp->f_clean = clean;
-	tp->f_warn = warning;
-	goto next;
+	match = 0;
+	goto nextparam;
 
 doneparam:
 	if (std == 0 && nreqs == 0) {
@@ -497,11 +510,9 @@
 	}
 	if (filetype == PROFILING && profiling == 0)
 		goto next;
-	if (tp == 0)
-		tp = new_fent();
+	tp = new_fent();
 	tp->f_fn = this;
 	tp->f_type = filetype;
-	tp->f_flags &= ~ISDUP;
 	if (imp_rule)
 		tp->f_flags |= NO_IMPLCT_RULE;
 	if (no_obj)
@@ -510,13 +521,10 @@
 		tp->f_flags |= BEFORE_DEPEND;
 	if (nowerror)
 		tp->f_flags |= NOWERROR;
-	tp->f_needs = needs;
 	tp->f_compilewith = compilewith;
 	tp->f_depends = depends;
 	tp->f_clean = clean;
 	tp->f_warn = warning;
-	if (pf && pf->f_type == INVISIBLE)
-		pf->f_flags |= ISDUP;		/* mark as duplicate */
 	goto next;
 }
 
@@ -530,10 +538,6 @@
 	char fname[MAXPATHLEN];
 	struct files_name *nl, *tnl;
 	
-	if (ident == NULL) {
-		printf("no ident line specified\n");
-		exit(1);
-	}
 	(void) snprintf(fname, sizeof(fname), "../../conf/files");
 	read_file(fname);
 	(void) snprintf(fname, sizeof(fname),
@@ -599,7 +603,7 @@
 	fprintf(fp, "OBJS=");
 	lpos = 6;
 	STAILQ_FOREACH(tp, &ftab, f_next) {
-		if (tp->f_type == INVISIBLE || tp->f_flags & NO_OBJ)
+		if (tp->f_flags & NO_OBJ)
 			continue;
 		sp = tail(tp->f_fn);
 		cp = sp + (len = strlen(sp)) - 1;
@@ -635,7 +639,7 @@
 	fprintf(fp, "%sFILES=", SUFF);
 	lpos = 8;
 	STAILQ_FOREACH(tp, &ftab, f_next)
-		if (tp->f_type != INVISIBLE && tp->f_type != NODEPEND) {
+		if (tp->f_type != NODEPEND) {
 			len = strlen(tp->f_fn);
 			if (tp->f_fn[len - slen - 1] != '.')
 				continue;
@@ -673,13 +677,11 @@
 static void
 do_rules(FILE *f)
 {
-	char *cp, *np, och, *tp;
+	char *cp, *np, och;
 	struct file_list *ftp;
 	char *compilewith;
 
 	STAILQ_FOREACH(ftp, &ftab, f_next) {
-		if (ftp->f_type == INVISIBLE)
-			continue;
 		if (ftp->f_warn)
 			printf("WARNING: %s\n", ftp->f_warn);
 		cp = (np = ftp->f_fn) + strlen(ftp->f_fn) - 1;
@@ -712,7 +714,6 @@
 					np, och);
 			}
 		}
-		tp = tail(np);
 		compilewith = ftp->f_compilewith;
 		if (compilewith == 0) {
 			const char *ftype = NULL;
Index: lang.l
===================================================================
RCS file: /home/cvs/src/usr.sbin/config/lang.l,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/config/lang.l -L usr.sbin/config/lang.l -u -r1.1.1.1 -r1.2
--- usr.sbin/config/lang.l
+++ usr.sbin/config/lang.l
@@ -28,7 +28,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)lang.l	8.1 (Berkeley) 6/6/93
- * $FreeBSD: src/usr.sbin/config/lang.l,v 1.41.2.1 2005/12/01 17:43:09 ru Exp $
+ * $FreeBSD: src/usr.sbin/config/lang.l,v 1.45 2007/05/12 19:38:18 wkoszek Exp $
  */
 
 #include <assert.h>
@@ -71,6 +71,7 @@
 	{ "hints",	HINTS },
 	{ "ident",	IDENT },
 	{ "machine",	ARCH }, /* MACHINE is defined in /sys/param.h */
+	{ "makeoption",	MAKEOPTIONS },
 	{ "makeoptions", MAKEOPTIONS },
 	{ "nomakeoption", NOMAKEOPTION },
 	{ "nomakeoptions", NOMAKEOPTION },
@@ -206,6 +207,30 @@
 	return num;
 }
 
+void
+cfgfile_add(const char *fname)
+{
+	struct cfgfile *cf;
+
+	cf = calloc(1, sizeof(*cf));
+	assert(cf != NULL);
+	asprintf(&cf->cfg_path, "%s", fname);
+	STAILQ_INSERT_TAIL(&cfgfiles, cf, cfg_next);
+}
+
+void
+cfgfile_removeall(void)
+{
+	struct cfgfile *cf;
+
+	while (!STAILQ_EMPTY(&cfgfiles)) {
+		cf = STAILQ_FIRST(&cfgfiles);
+		STAILQ_REMOVE_HEAD(&cfgfiles, cfg_next);
+		if (cf->cfg_path != NULL)
+			free(cf->cfg_path);
+		free(cf);
+	}
+}
 
 /*
  * Open the named file for inclusion at the current point.  Returns 0 on
@@ -221,6 +246,7 @@
 	struct incl *in;
 	char *fnamebuf;
 
+	fnamebuf = NULL;
 	fp = fopen(fname, "r");
 	if (fp == NULL && fname[0] != '.' && fname[0] != '/') {
 		asprintf(&fnamebuf, "../../conf/%s", fname);
@@ -233,6 +259,7 @@
 		yyerror("cannot open included file");
 		return (-1);
 	}
+	cfgfile_add(fnamebuf == NULL ? fname : fnamebuf);
 	in = malloc(sizeof(*in));
 	assert(in != NULL);
 	in->in_prev = inclp;
Index: Makefile
===================================================================
RCS file: /home/cvs/src/usr.sbin/config/Makefile,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/config/Makefile -L usr.sbin/config/Makefile -u -r1.1.1.1 -r1.2
--- usr.sbin/config/Makefile
+++ usr.sbin/config/Makefile
@@ -1,16 +1,21 @@
 # 	@(#)Makefile	8.1 (Berkeley) 6/6/93
-# $FreeBSD: src/usr.sbin/config/Makefile,v 1.34 2004/05/11 15:42:44 cognet Exp $
+# $FreeBSD: src/usr.sbin/config/Makefile,v 1.38 2007/10/01 18:15:11 ru Exp $
 
 PROG=	config
-MAN=	config.8
+MAN=	config.5 config.8
 SRCS=	config.y main.c lang.l mkmakefile.c mkheaders.c \
-	mkoptions.c y.tab.h
+	mkoptions.c y.tab.h kernconf.c
+
+kernconf.c: kernconf.tmpl
+	file2c 'char kernconfstr[] = {' ',0};' < ${.CURDIR}/kernconf.tmpl > kernconf.c
 
 WARNS?=	6
 CFLAGS+= -I. -I${.CURDIR}
 
-DPADD=	${LIBL}
-LDADD=	-ll
+DPADD=	${LIBL} ${LIBSBUF}
+LDADD=	-ll -lsbuf
+
+CLEANFILES+=	kernconf.c
 
 mkmakefile.o: configvers.h
 


More information about the Midnightbsd-cvs mailing list