freebsd-dev/usr.sbin/config/main.c

481 lines
10 KiB
C
Raw Normal View History

1994-05-26 05:23:31 +00:00
/*
* Copyright (c) 1980, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
1997-09-15 06:37:10 +00:00
static const char copyright[] =
1994-05-26 05:23:31 +00:00
"@(#) Copyright (c) 1980, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
1997-09-15 06:37:10 +00:00
#if 0
1994-05-26 05:23:31 +00:00
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
1997-09-15 06:37:10 +00:00
#endif
static const char rcsid[] =
1999-08-28 01:35:59 +00:00
"$FreeBSD$";
1994-05-26 05:23:31 +00:00
#endif /* not lint */
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/mman.h>
#include <sys/param.h>
1994-05-26 05:23:31 +00:00
#include <ctype.h>
#include <err.h>
1997-09-15 06:37:10 +00:00
#include <stdio.h>
#include <sysexits.h>
1997-09-15 06:37:10 +00:00
#include <unistd.h>
#include <dirent.h>
1996-06-02 17:22:01 +00:00
#include "y.tab.h"
1994-05-26 05:23:31 +00:00
#include "config.h"
#ifndef TRUE
#define TRUE (1)
#endif
#ifndef FALSE
#define FALSE (0)
#endif
#define CDIR "../compile/"
char * PREFIX;
char destdir[MAXPATHLEN];
char srcdir[MAXPATHLEN];
int debugging;
int profiling;
1994-05-26 05:23:31 +00:00
Borrow phk's axe and apply the next stage of config(8)'s evolution. Use Warner Losh's "hint" driver to decode ascii strings to fill the resource table at boot time. config(8) no longer generates an ioconf.c table - ie: the configuration no longer has to be compiled into the kernel. You can reconfigure your isa devices with the likes of this at loader(8) time: set hint.ed.0.port=0x320 userconfig will be rewritten to use this style interface one day and will move to /boot/userconfig.4th or something like that. It is still possible to statically compile in a set of hints into a kernel if you do not wish to use loader(8). See the "hints" directive in GENERIC as an example. All device wiring has been moved out of config(8). There is a set of helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98) that extract the 'at isa? port foo irq bar' from the old files and produces a hints file. If you install this file as /boot/device.hints (and update /boot/defaults/loader.conf - You can do a build/install in sys/boot) then loader will load it automatically for you. You can also compile in the hints directly with: hints "device.hints" as well. There are a few things that I'm not too happy with yet. Under this scheme, things like LINT would no longer be useful as "documentation" of settings. I have renamed this file to 'NOTES' and stored the example hints strings in it. However... this is not something that config(8) understands, so there is a script that extracts the build-specific data from the documentation file (NOTES) to produce a LINT that can be config'ed and built. A stack of man4 pages will need updating. :-/ Also, since there is no longer a difference between 'device' and 'pseudo-device' I collapsed the two together, and the resulting 'device' takes a 'number of units' for devices that still have it statically allocated. eg: 'device fe 4' will compile the fe driver with NFE set to 4. You can then set hints for 4 units (0 - 3). Also note that 'device fe0' will be interpreted as "zero units of 'fe'" which would be bad, so there is a config warning for this. This is only needed for old drivers that still have static limits on numbers of units. All the statically limited drivers that I could find were marked. Please exercise EXTREME CAUTION when transitioning! Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
static void configfile(void);
static void get_srcdir(void);
static void usage(void);
static void cleanheaders(char *);
struct hdr_list {
char *h_name;
struct hdr_list *h_next;
} *htab;
1997-09-15 06:37:10 +00:00
1994-05-26 05:23:31 +00:00
/*
* Config builds a set of files for building a UNIX
* system given a description of the desired system.
*/
1997-09-15 06:37:10 +00:00
int
Borrow phk's axe and apply the next stage of config(8)'s evolution. Use Warner Losh's "hint" driver to decode ascii strings to fill the resource table at boot time. config(8) no longer generates an ioconf.c table - ie: the configuration no longer has to be compiled into the kernel. You can reconfigure your isa devices with the likes of this at loader(8) time: set hint.ed.0.port=0x320 userconfig will be rewritten to use this style interface one day and will move to /boot/userconfig.4th or something like that. It is still possible to statically compile in a set of hints into a kernel if you do not wish to use loader(8). See the "hints" directive in GENERIC as an example. All device wiring has been moved out of config(8). There is a set of helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98) that extract the 'at isa? port foo irq bar' from the old files and produces a hints file. If you install this file as /boot/device.hints (and update /boot/defaults/loader.conf - You can do a build/install in sys/boot) then loader will load it automatically for you. You can also compile in the hints directly with: hints "device.hints" as well. There are a few things that I'm not too happy with yet. Under this scheme, things like LINT would no longer be useful as "documentation" of settings. I have renamed this file to 'NOTES' and stored the example hints strings in it. However... this is not something that config(8) understands, so there is a script that extracts the build-specific data from the documentation file (NOTES) to produce a LINT that can be config'ed and built. A stack of man4 pages will need updating. :-/ Also, since there is no longer a difference between 'device' and 'pseudo-device' I collapsed the two together, and the resulting 'device' takes a 'number of units' for devices that still have it statically allocated. eg: 'device fe 4' will compile the fe driver with NFE set to 4. You can then set hints for 4 units (0 - 3). Also note that 'device fe0' will be interpreted as "zero units of 'fe'" which would be bad, so there is a config warning for this. This is only needed for old drivers that still have static limits on numbers of units. All the statically limited drivers that I could find were marked. Please exercise EXTREME CAUTION when transitioning! Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
main(int argc, char **argv)
1994-05-26 05:23:31 +00:00
{
struct stat buf;
int ch, len;
1994-05-26 05:23:31 +00:00
char *p;
2001-07-14 00:03:05 +00:00
char xxx[MAXPATHLEN];
1994-05-26 05:23:31 +00:00
while ((ch = getopt(argc, argv, "d:gp")) != -1)
1994-05-26 05:23:31 +00:00
switch (ch) {
case 'd':
if (*destdir == '\0')
strlcpy(destdir, optarg, sizeof(destdir));
else
errx(2, "directory already set");
break;
1994-05-26 05:23:31 +00:00
case 'g':
debugging++;
1994-05-26 05:23:31 +00:00
break;
case 'p':
profiling++;
break;
case '?':
default:
1997-09-15 06:37:10 +00:00
usage();
1994-05-26 05:23:31 +00:00
}
argc -= optind;
argv += optind;
1997-09-15 06:37:10 +00:00
if (argc != 1)
usage();
1994-05-26 05:23:31 +00:00
1997-09-15 06:37:10 +00:00
if (freopen(PREFIX = *argv, "r", stdin) == NULL)
err(2, "%s", PREFIX);
if (*destdir != '\0') {
len = strlen(destdir);
while (len > 1 && destdir[len - 1] == '/')
destdir[--len] = '\0';
get_srcdir();
} else {
strlcpy(destdir, CDIR, sizeof(destdir));
strlcat(destdir, PREFIX, sizeof(destdir));
}
p = path((char *)NULL);
if (stat(p, &buf)) {
1997-09-15 06:37:10 +00:00
if (mkdir(p, 0777))
err(2, "%s", p);
1994-05-26 05:23:31 +00:00
}
else if ((buf.st_mode & S_IFMT) != S_IFDIR)
1997-09-15 06:37:10 +00:00
errx(2, "%s isn't a directory", p);
1994-05-26 05:23:31 +00:00
dtab = NULL;
yyfile = *argv;
1994-05-26 05:23:31 +00:00
if (yyparse())
exit(3);
if (machinename == NULL) {
printf("Specify machine type, e.g. ``machine i386''\n");
1994-05-26 05:23:31 +00:00
exit(1);
}
/*
* make symbolic links in compilation directory
* for "sys" (to make genassym.c work along with #include <sys/xxx>)
* and similarly for "machine".
*/
if (*srcdir == '\0')
(void)snprintf(xxx, sizeof(xxx), "../../include");
else
(void)snprintf(xxx, sizeof(xxx), "%s/%s/include",
srcdir, machinename);
2001-07-14 00:03:05 +00:00
(void) unlink(path("machine"));
1994-05-26 05:23:31 +00:00
(void) symlink(xxx, path("machine"));
options(); /* make options .h files */
1994-05-26 05:23:31 +00:00
makefile(); /* build Makefile */
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 a ``make depend''\n");
1994-05-26 05:23:31 +00:00
exit(0);
}
/*
* get_srcdir
* determine the root of the kernel source tree
* and save that in srcdir.
*/
static void
Borrow phk's axe and apply the next stage of config(8)'s evolution. Use Warner Losh's "hint" driver to decode ascii strings to fill the resource table at boot time. config(8) no longer generates an ioconf.c table - ie: the configuration no longer has to be compiled into the kernel. You can reconfigure your isa devices with the likes of this at loader(8) time: set hint.ed.0.port=0x320 userconfig will be rewritten to use this style interface one day and will move to /boot/userconfig.4th or something like that. It is still possible to statically compile in a set of hints into a kernel if you do not wish to use loader(8). See the "hints" directive in GENERIC as an example. All device wiring has been moved out of config(8). There is a set of helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98) that extract the 'at isa? port foo irq bar' from the old files and produces a hints file. If you install this file as /boot/device.hints (and update /boot/defaults/loader.conf - You can do a build/install in sys/boot) then loader will load it automatically for you. You can also compile in the hints directly with: hints "device.hints" as well. There are a few things that I'm not too happy with yet. Under this scheme, things like LINT would no longer be useful as "documentation" of settings. I have renamed this file to 'NOTES' and stored the example hints strings in it. However... this is not something that config(8) understands, so there is a script that extracts the build-specific data from the documentation file (NOTES) to produce a LINT that can be config'ed and built. A stack of man4 pages will need updating. :-/ Also, since there is no longer a difference between 'device' and 'pseudo-device' I collapsed the two together, and the resulting 'device' takes a 'number of units' for devices that still have it statically allocated. eg: 'device fe 4' will compile the fe driver with NFE set to 4. You can then set hints for 4 units (0 - 3). Also note that 'device fe0' will be interpreted as "zero units of 'fe'" which would be bad, so there is a config warning for this. This is only needed for old drivers that still have static limits on numbers of units. All the statically limited drivers that I could find were marked. Please exercise EXTREME CAUTION when transitioning! Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
get_srcdir(void)
{
if (realpath("../..", srcdir) == NULL)
errx(2, "Unable to find root of source tree");
}
1997-09-15 06:37:10 +00:00
static void
Borrow phk's axe and apply the next stage of config(8)'s evolution. Use Warner Losh's "hint" driver to decode ascii strings to fill the resource table at boot time. config(8) no longer generates an ioconf.c table - ie: the configuration no longer has to be compiled into the kernel. You can reconfigure your isa devices with the likes of this at loader(8) time: set hint.ed.0.port=0x320 userconfig will be rewritten to use this style interface one day and will move to /boot/userconfig.4th or something like that. It is still possible to statically compile in a set of hints into a kernel if you do not wish to use loader(8). See the "hints" directive in GENERIC as an example. All device wiring has been moved out of config(8). There is a set of helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98) that extract the 'at isa? port foo irq bar' from the old files and produces a hints file. If you install this file as /boot/device.hints (and update /boot/defaults/loader.conf - You can do a build/install in sys/boot) then loader will load it automatically for you. You can also compile in the hints directly with: hints "device.hints" as well. There are a few things that I'm not too happy with yet. Under this scheme, things like LINT would no longer be useful as "documentation" of settings. I have renamed this file to 'NOTES' and stored the example hints strings in it. However... this is not something that config(8) understands, so there is a script that extracts the build-specific data from the documentation file (NOTES) to produce a LINT that can be config'ed and built. A stack of man4 pages will need updating. :-/ Also, since there is no longer a difference between 'device' and 'pseudo-device' I collapsed the two together, and the resulting 'device' takes a 'number of units' for devices that still have it statically allocated. eg: 'device fe 4' will compile the fe driver with NFE set to 4. You can then set hints for 4 units (0 - 3). Also note that 'device fe0' will be interpreted as "zero units of 'fe'" which would be bad, so there is a config warning for this. This is only needed for old drivers that still have static limits on numbers of units. All the statically limited drivers that I could find were marked. Please exercise EXTREME CAUTION when transitioning! Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
usage(void)
1997-09-15 06:37:10 +00:00
{
fprintf(stderr, "usage: config [-gp] [-d destdir] sysname\n");
1997-09-15 06:37:10 +00:00
exit(1);
}
1994-05-26 05:23:31 +00:00
/*
* get_word
* returns EOF on end of file
* NULL on end of line
* pointer to the word otherwise
*/
char *
Borrow phk's axe and apply the next stage of config(8)'s evolution. Use Warner Losh's "hint" driver to decode ascii strings to fill the resource table at boot time. config(8) no longer generates an ioconf.c table - ie: the configuration no longer has to be compiled into the kernel. You can reconfigure your isa devices with the likes of this at loader(8) time: set hint.ed.0.port=0x320 userconfig will be rewritten to use this style interface one day and will move to /boot/userconfig.4th or something like that. It is still possible to statically compile in a set of hints into a kernel if you do not wish to use loader(8). See the "hints" directive in GENERIC as an example. All device wiring has been moved out of config(8). There is a set of helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98) that extract the 'at isa? port foo irq bar' from the old files and produces a hints file. If you install this file as /boot/device.hints (and update /boot/defaults/loader.conf - You can do a build/install in sys/boot) then loader will load it automatically for you. You can also compile in the hints directly with: hints "device.hints" as well. There are a few things that I'm not too happy with yet. Under this scheme, things like LINT would no longer be useful as "documentation" of settings. I have renamed this file to 'NOTES' and stored the example hints strings in it. However... this is not something that config(8) understands, so there is a script that extracts the build-specific data from the documentation file (NOTES) to produce a LINT that can be config'ed and built. A stack of man4 pages will need updating. :-/ Also, since there is no longer a difference between 'device' and 'pseudo-device' I collapsed the two together, and the resulting 'device' takes a 'number of units' for devices that still have it statically allocated. eg: 'device fe 4' will compile the fe driver with NFE set to 4. You can then set hints for 4 units (0 - 3). Also note that 'device fe0' will be interpreted as "zero units of 'fe'" which would be bad, so there is a config warning for this. This is only needed for old drivers that still have static limits on numbers of units. All the statically limited drivers that I could find were marked. Please exercise EXTREME CAUTION when transitioning! Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
get_word(FILE *fp)
1994-05-26 05:23:31 +00:00
{
static char line[80];
Borrow phk's axe and apply the next stage of config(8)'s evolution. Use Warner Losh's "hint" driver to decode ascii strings to fill the resource table at boot time. config(8) no longer generates an ioconf.c table - ie: the configuration no longer has to be compiled into the kernel. You can reconfigure your isa devices with the likes of this at loader(8) time: set hint.ed.0.port=0x320 userconfig will be rewritten to use this style interface one day and will move to /boot/userconfig.4th or something like that. It is still possible to statically compile in a set of hints into a kernel if you do not wish to use loader(8). See the "hints" directive in GENERIC as an example. All device wiring has been moved out of config(8). There is a set of helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98) that extract the 'at isa? port foo irq bar' from the old files and produces a hints file. If you install this file as /boot/device.hints (and update /boot/defaults/loader.conf - You can do a build/install in sys/boot) then loader will load it automatically for you. You can also compile in the hints directly with: hints "device.hints" as well. There are a few things that I'm not too happy with yet. Under this scheme, things like LINT would no longer be useful as "documentation" of settings. I have renamed this file to 'NOTES' and stored the example hints strings in it. However... this is not something that config(8) understands, so there is a script that extracts the build-specific data from the documentation file (NOTES) to produce a LINT that can be config'ed and built. A stack of man4 pages will need updating. :-/ Also, since there is no longer a difference between 'device' and 'pseudo-device' I collapsed the two together, and the resulting 'device' takes a 'number of units' for devices that still have it statically allocated. eg: 'device fe 4' will compile the fe driver with NFE set to 4. You can then set hints for 4 units (0 - 3). Also note that 'device fe0' will be interpreted as "zero units of 'fe'" which would be bad, so there is a config warning for this. This is only needed for old drivers that still have static limits on numbers of units. All the statically limited drivers that I could find were marked. Please exercise EXTREME CAUTION when transitioning! Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
int ch;
char *cp;
int escaped_nl = 0;
1994-05-26 05:23:31 +00:00
begin:
1994-05-26 05:23:31 +00:00
while ((ch = getc(fp)) != EOF)
if (ch != ' ' && ch != '\t')
break;
if (ch == EOF)
return ((char *)EOF);
if (ch == '\\'){
escaped_nl = 1;
goto begin;
}
if (ch == '\n') {
if (escaped_nl){
escaped_nl = 0;
goto begin;
}
else
return (NULL);
}
1994-05-26 05:23:31 +00:00
cp = line;
*cp++ = ch;
while ((ch = getc(fp)) != EOF) {
if (isspace(ch))
break;
*cp++ = ch;
}
*cp = 0;
if (ch == EOF)
return ((char *)EOF);
(void) ungetc(ch, fp);
return (line);
}
/*
* get_quoted_word
* like get_word but will accept something in double or single quotes
* (to allow embedded spaces).
*/
char *
Borrow phk's axe and apply the next stage of config(8)'s evolution. Use Warner Losh's "hint" driver to decode ascii strings to fill the resource table at boot time. config(8) no longer generates an ioconf.c table - ie: the configuration no longer has to be compiled into the kernel. You can reconfigure your isa devices with the likes of this at loader(8) time: set hint.ed.0.port=0x320 userconfig will be rewritten to use this style interface one day and will move to /boot/userconfig.4th or something like that. It is still possible to statically compile in a set of hints into a kernel if you do not wish to use loader(8). See the "hints" directive in GENERIC as an example. All device wiring has been moved out of config(8). There is a set of helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98) that extract the 'at isa? port foo irq bar' from the old files and produces a hints file. If you install this file as /boot/device.hints (and update /boot/defaults/loader.conf - You can do a build/install in sys/boot) then loader will load it automatically for you. You can also compile in the hints directly with: hints "device.hints" as well. There are a few things that I'm not too happy with yet. Under this scheme, things like LINT would no longer be useful as "documentation" of settings. I have renamed this file to 'NOTES' and stored the example hints strings in it. However... this is not something that config(8) understands, so there is a script that extracts the build-specific data from the documentation file (NOTES) to produce a LINT that can be config'ed and built. A stack of man4 pages will need updating. :-/ Also, since there is no longer a difference between 'device' and 'pseudo-device' I collapsed the two together, and the resulting 'device' takes a 'number of units' for devices that still have it statically allocated. eg: 'device fe 4' will compile the fe driver with NFE set to 4. You can then set hints for 4 units (0 - 3). Also note that 'device fe0' will be interpreted as "zero units of 'fe'" which would be bad, so there is a config warning for this. This is only needed for old drivers that still have static limits on numbers of units. All the statically limited drivers that I could find were marked. Please exercise EXTREME CAUTION when transitioning! Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
get_quoted_word(FILE *fp)
1994-05-26 05:23:31 +00:00
{
static char line[256];
Borrow phk's axe and apply the next stage of config(8)'s evolution. Use Warner Losh's "hint" driver to decode ascii strings to fill the resource table at boot time. config(8) no longer generates an ioconf.c table - ie: the configuration no longer has to be compiled into the kernel. You can reconfigure your isa devices with the likes of this at loader(8) time: set hint.ed.0.port=0x320 userconfig will be rewritten to use this style interface one day and will move to /boot/userconfig.4th or something like that. It is still possible to statically compile in a set of hints into a kernel if you do not wish to use loader(8). See the "hints" directive in GENERIC as an example. All device wiring has been moved out of config(8). There is a set of helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98) that extract the 'at isa? port foo irq bar' from the old files and produces a hints file. If you install this file as /boot/device.hints (and update /boot/defaults/loader.conf - You can do a build/install in sys/boot) then loader will load it automatically for you. You can also compile in the hints directly with: hints "device.hints" as well. There are a few things that I'm not too happy with yet. Under this scheme, things like LINT would no longer be useful as "documentation" of settings. I have renamed this file to 'NOTES' and stored the example hints strings in it. However... this is not something that config(8) understands, so there is a script that extracts the build-specific data from the documentation file (NOTES) to produce a LINT that can be config'ed and built. A stack of man4 pages will need updating. :-/ Also, since there is no longer a difference between 'device' and 'pseudo-device' I collapsed the two together, and the resulting 'device' takes a 'number of units' for devices that still have it statically allocated. eg: 'device fe 4' will compile the fe driver with NFE set to 4. You can then set hints for 4 units (0 - 3). Also note that 'device fe0' will be interpreted as "zero units of 'fe'" which would be bad, so there is a config warning for this. This is only needed for old drivers that still have static limits on numbers of units. All the statically limited drivers that I could find were marked. Please exercise EXTREME CAUTION when transitioning! Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
int ch;
char *cp;
int escaped_nl = 0;
1994-05-26 05:23:31 +00:00
begin:
1994-05-26 05:23:31 +00:00
while ((ch = getc(fp)) != EOF)
if (ch != ' ' && ch != '\t')
break;
if (ch == EOF)
return ((char *)EOF);
if (ch == '\\'){
escaped_nl = 1;
goto begin;
}
if (ch == '\n') {
if (escaped_nl){
escaped_nl = 0;
goto begin;
}
else
return (NULL);
}
1994-05-26 05:23:31 +00:00
cp = line;
if (ch == '"' || ch == '\'') {
Borrow phk's axe and apply the next stage of config(8)'s evolution. Use Warner Losh's "hint" driver to decode ascii strings to fill the resource table at boot time. config(8) no longer generates an ioconf.c table - ie: the configuration no longer has to be compiled into the kernel. You can reconfigure your isa devices with the likes of this at loader(8) time: set hint.ed.0.port=0x320 userconfig will be rewritten to use this style interface one day and will move to /boot/userconfig.4th or something like that. It is still possible to statically compile in a set of hints into a kernel if you do not wish to use loader(8). See the "hints" directive in GENERIC as an example. All device wiring has been moved out of config(8). There is a set of helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98) that extract the 'at isa? port foo irq bar' from the old files and produces a hints file. If you install this file as /boot/device.hints (and update /boot/defaults/loader.conf - You can do a build/install in sys/boot) then loader will load it automatically for you. You can also compile in the hints directly with: hints "device.hints" as well. There are a few things that I'm not too happy with yet. Under this scheme, things like LINT would no longer be useful as "documentation" of settings. I have renamed this file to 'NOTES' and stored the example hints strings in it. However... this is not something that config(8) understands, so there is a script that extracts the build-specific data from the documentation file (NOTES) to produce a LINT that can be config'ed and built. A stack of man4 pages will need updating. :-/ Also, since there is no longer a difference between 'device' and 'pseudo-device' I collapsed the two together, and the resulting 'device' takes a 'number of units' for devices that still have it statically allocated. eg: 'device fe 4' will compile the fe driver with NFE set to 4. You can then set hints for 4 units (0 - 3). Also note that 'device fe0' will be interpreted as "zero units of 'fe'" which would be bad, so there is a config warning for this. This is only needed for old drivers that still have static limits on numbers of units. All the statically limited drivers that I could find were marked. Please exercise EXTREME CAUTION when transitioning! Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
int quote = ch;
1994-05-26 05:23:31 +00:00
while ((ch = getc(fp)) != EOF) {
if (ch == quote)
break;
if (ch == '\n') {
*cp = 0;
printf("config: missing quote reading `%s'\n",
line);
exit(2);
}
*cp++ = ch;
}
} else {
*cp++ = ch;
while ((ch = getc(fp)) != EOF) {
if (isspace(ch))
break;
*cp++ = ch;
}
if (ch != EOF)
(void) ungetc(ch, fp);
}
*cp = 0;
if (ch == EOF)
return ((char *)EOF);
return (line);
}
/*
* prepend the path to a filename
*/
char *
path(const char *file)
1994-05-26 05:23:31 +00:00
{
char *cp = NULL;
1994-05-26 05:23:31 +00:00
if (file)
asprintf(&cp, "%s/%s", destdir, file);
else
cp = strdup(destdir);
1994-05-26 05:23:31 +00:00
return (cp);
}
static void
Borrow phk's axe and apply the next stage of config(8)'s evolution. Use Warner Losh's "hint" driver to decode ascii strings to fill the resource table at boot time. config(8) no longer generates an ioconf.c table - ie: the configuration no longer has to be compiled into the kernel. You can reconfigure your isa devices with the likes of this at loader(8) time: set hint.ed.0.port=0x320 userconfig will be rewritten to use this style interface one day and will move to /boot/userconfig.4th or something like that. It is still possible to statically compile in a set of hints into a kernel if you do not wish to use loader(8). See the "hints" directive in GENERIC as an example. All device wiring has been moved out of config(8). There is a set of helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98) that extract the 'at isa? port foo irq bar' from the old files and produces a hints file. If you install this file as /boot/device.hints (and update /boot/defaults/loader.conf - You can do a build/install in sys/boot) then loader will load it automatically for you. You can also compile in the hints directly with: hints "device.hints" as well. There are a few things that I'm not too happy with yet. Under this scheme, things like LINT would no longer be useful as "documentation" of settings. I have renamed this file to 'NOTES' and stored the example hints strings in it. However... this is not something that config(8) understands, so there is a script that extracts the build-specific data from the documentation file (NOTES) to produce a LINT that can be config'ed and built. A stack of man4 pages will need updating. :-/ Also, since there is no longer a difference between 'device' and 'pseudo-device' I collapsed the two together, and the resulting 'device' takes a 'number of units' for devices that still have it statically allocated. eg: 'device fe 4' will compile the fe driver with NFE set to 4. You can then set hints for 4 units (0 - 3). Also note that 'device fe0' will be interpreted as "zero units of 'fe'" which would be bad, so there is a config warning for this. This is only needed for old drivers that still have static limits on numbers of units. All the statically limited drivers that I could find were marked. Please exercise EXTREME CAUTION when transitioning! Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
configfile(void)
{
FILE *fi, *fo;
char *p;
int i;
fi = fopen(PREFIX, "r");
if (!fi)
1997-09-15 06:37:10 +00:00
err(2, "%s", PREFIX);
fo = fopen(p=path("config.c.new"), "w");
if (!fo)
1997-09-15 06:37:10 +00:00
err(2, "%s", p);
fprintf(fo, "#include \"opt_config.h\"\n");
fprintf(fo, "#ifdef INCLUDE_CONFIG_FILE \n");
fprintf(fo, "static 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);
}
}
fprintf(fo, "\\n\\\nEND CONFIG FILE %s\\n\\\n", PREFIX);
fprintf(fo, "\";\n");
fprintf(fo, "\n#endif /* INCLUDE_CONFIG_FILE */\n");
fclose(fi);
fclose(fo);
moveifchanged(path("config.c.new"), path("config.c"));
}
/*
* moveifchanged --
* compare two files; rename if changed.
*/
void
moveifchanged(const char *from_name, const char *to_name)
{
char *p, *q;
int changed;
size_t tsize;
struct stat from_sb, to_sb;
int from_fd, to_fd;
changed = 0;
if ((from_fd = open(from_name, O_RDONLY)) < 0)
err(EX_OSERR, "moveifchanged open(%s)", from_name);
if ((to_fd = open(to_name, O_RDONLY)) < 0)
changed++;
if (!changed && fstat(from_fd, &from_sb) < 0)
err(EX_OSERR, "moveifchanged fstat(%s)", from_name);
if (!changed && fstat(to_fd, &to_sb) < 0)
err(EX_OSERR, "moveifchanged fstat(%s)", to_name);
if (!changed && from_sb.st_size != to_sb.st_size)
changed++;
tsize = (size_t)from_sb.st_size;
if (!changed) {
p = mmap(NULL, tsize, PROT_READ, MAP_SHARED, from_fd, (off_t)0);
#ifndef MAP_FAILED
#define MAP_FAILED ((caddr_t) -1)
#endif
if (p == MAP_FAILED)
err(EX_OSERR, "mmap %s", from_name);
q = mmap(NULL, tsize, PROT_READ, MAP_SHARED, to_fd, (off_t)0);
if (q == MAP_FAILED)
err(EX_OSERR, "mmap %s", to_name);
changed = memcmp(p, q, tsize);
munmap(p, tsize);
munmap(q, tsize);
}
if (changed) {
if (rename(from_name, to_name) < 0)
err(EX_OSERR, "rename(%s, %s)", from_name, to_name);
} else {
if (unlink(from_name) < 0)
err(EX_OSERR, "unlink(%s)", from_name);
}
}
static void
cleanheaders(char *p)
{
DIR *dirp;
struct dirent *dp;
struct file_list *fl;
struct hdr_list *hl;
int i;
remember("y.tab.h");
remember("setdefs.h");
for (fl = ftab; fl != NULL; fl = fl->f_next)
remember(fl->f_fn);
/*
* Scan the build directory and clean out stuff that looks like
* it might have been a leftover NFOO header, etc.
*/
dirp = opendir(p);
while ((dp = readdir(dirp)) != NULL) {
i = dp->d_namlen - 2;
/* Skip non-headers */
if (dp->d_name[i] != '.' || dp->d_name[i + 1] != 'h')
continue;
/* Skip special stuff, eg: bus_if.h, but check opt_*.h */
if (index(dp->d_name, '_') &&
strncmp(dp->d_name, "opt_", 4) != 0)
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) {
break;
}
}
if (hl)
continue;
printf("Removing stale header: %s\n", dp->d_name);
unlink(path(dp->d_name));
}
(void)closedir(dirp);
}
void
remember(const char *file)
{
char *s;
struct hdr_list *hl;
if ((s = strrchr(file, '/')) != NULL)
s = ns(s + 1);
else
s = ns(file);
if (index(s, '_') && strncmp(s, "opt_", 4) != 0) {
free(s);
return;
}
for (hl = htab; hl != NULL; hl = hl->h_next) {
if (strcmp(s, hl->h_name) == 0) {
free(s);
return;
}
}
hl = malloc(sizeof(*hl));
bzero(hl, sizeof(*hl));
hl->h_name = s;
hl->h_next = htab;
htab = hl;
}