Subject: Re: Format of "files" file ?
To: None <ender@macbsd.com, wrstuden@nas.nasa.gov>
From: Chris Torek <torek@BSDI.COM>
List: tech-kern
Date: 02/16/1999 01:38:05
>> #define N<DEVICE>     <num>

>I think that's what needs-count does. needs-flag [just produces 0 or 1]

Yes.  BSD/OS and NetBSD have probably diverged here, but
the current BSD/OS definition should be pretty close to the
current NetBSD definition.  The former is, syntactically:

	file	<pathname>	<expr>  <flags>  <rule>

where "file" is a keyword, <pathname> is something like kern/kern_foo.c;
<expr> is an optional expression; "flags" is any collection of
the five keywords "always-source", "config-dependent", "device-driver",
"needs-count", or "needs-flag"; and <rule> is an optional compilation
rule word, prefixed by the keyword "compile-with".  Thus:

	file	kern/kern_foo.c				# pathname
			(this | !that) & theother	# expr
			config-dependent needs-flag	# flags
			compile-with "${CRAZY_C}"	# "make" rule

If "needs-count" or "needs-flag" is given, there must be a non-
empty "expr".  The bottom level words in this expression are "atoms",
and in this case, those atoms are entered into a table of things
"needing to be counted" or "things needing to be flagged".

The atoms that make up the expression can be either device names
or options selected by "options" keywords (e.g., "options INET").
Only devices can be "counted", but anything can be "flagged".
Any device that is "counted" is not cloneable, so if you say:

	file	junk.c		sd&never	needs-count

that renders "sd* at <anything>" an invalid config line.  (It also
means that "never*" is invalid, but presumably no one ever specifies
a "never".)  The "needs-count" form is thus strongly discouraged.

Now, given a counted or flagged "file" with an expression of the
form "(this | !that) & theother", "config" will:

	- Open or create the file "this.h".
	- If the file exists, read it, expecting to see a
	  sequence of lines of the form:
		#define	NTHIS %d
		#define	NTHAT %d
		#define	NTHEOTHER %d
	  If the file does not match this form, or the numbers
	  that go in the "%d"s do not match the counts or flags
	  associated with the atoms, config will replace the
	  file.
	- If the file does not exist or needs replacing, config
	  will write the same sequence of lines, with appropriate
	  values for the "%d"s.

The interesting (and somewhat peculiar) thing here is that the file
name comes from the first atom, with ".h" appended, while the list
comes from all the atoms, converted to uppercase and with N prepended
to the #define.  The order of atoms in the file matches the order
of the atoms in the expression.  (You can thus get an always-rewritten
header by having one "file junk1.c never|never|definethese needs-flag"
and then one "file junk2.c never|definethese|never needs-flag".
Pointless, but it follows from the rules.)

(This is not really how I would have designed it all, but I had to
have something that was backwards-compatible with the old config,
and I wanted to keep things simple.  The old config had, as far as
I could tell, totally magical rules for putting NHK and NRK both
into rk.h, or whatever.)

Chris