1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1980 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
|
|
|
|
char copyright[] =
|
|
|
|
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
|
|
|
|
All rights reserved.\n";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1993-08-01 21:54:45 +04:00
|
|
|
/*static char sccsid[] = "from: @(#)main.c 5.17 (Berkeley) 7/1/91";*/
|
|
|
|
static char rcsid[] = "$Id: main.c,v 1.4 1993/08/01 18:00:17 mycroft Exp $";
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include "y.tab.h"
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
static char *PREFIX;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Config builds a set of files for building a UNIX
|
|
|
|
* system given a description of the desired system.
|
|
|
|
*/
|
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
|
|
|
|
extern char *optarg;
|
|
|
|
extern int optind;
|
|
|
|
struct stat buf;
|
|
|
|
int ch;
|
|
|
|
char *p;
|
|
|
|
|
1993-04-10 16:11:55 +04:00
|
|
|
fatal_errors =1;
|
|
|
|
while ((ch = getopt(argc, argv, "gpk")) != EOF)
|
1993-03-21 12:45:37 +03:00
|
|
|
switch (ch) {
|
|
|
|
case 'g':
|
|
|
|
debugging++;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
profiling++;
|
|
|
|
break;
|
1993-04-10 16:11:55 +04:00
|
|
|
case 'k':
|
|
|
|
fatal_errors=0;
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc != 1) {
|
1993-04-10 16:11:55 +04:00
|
|
|
usage: fputs("usage: config [-gkp] sysname\n", stderr);
|
1993-03-21 12:45:37 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (freopen(PREFIX = *argv, "r", stdin) == NULL) {
|
|
|
|
perror(PREFIX);
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
if (stat(p = path((char *)NULL), &buf)) {
|
|
|
|
if (mkdir(p, 0777)) {
|
|
|
|
perror(p);
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((buf.st_mode & S_IFMT) != S_IFDIR) {
|
|
|
|
fprintf(stderr, "config: %s isn't a directory.\n", p);
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
dtab = NULL;
|
|
|
|
confp = &conf_list;
|
|
|
|
if (yyparse())
|
|
|
|
exit(3);
|
|
|
|
switch (machine) {
|
|
|
|
|
|
|
|
case MACHINE_VAX:
|
|
|
|
vax_ioconf(); /* Print ioconf.c */
|
|
|
|
ubglue(); /* Create ubglue.s */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MACHINE_TAHOE:
|
|
|
|
tahoe_ioconf();
|
|
|
|
vbglue();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MACHINE_HP300:
|
|
|
|
hp300_ioconf();
|
|
|
|
hpglue();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MACHINE_I386:
|
|
|
|
i386_ioconf(); /* Print ioconf.c */
|
|
|
|
vector(); /* Create vector.s */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("Specify machine type, e.g. ``machine vax''\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* make symbolic links in compilation directory
|
|
|
|
* for "sys" (to make genassym.c work along with #include <sys/xxx>)
|
|
|
|
* and similarly for "machine".
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
char xxx[80];
|
|
|
|
|
1993-05-17 13:10:06 +04:00
|
|
|
(void) sprintf(xxx, "../../include", machinename);
|
1993-03-21 12:45:37 +03:00
|
|
|
(void) symlink(xxx, path("machine"));
|
|
|
|
}
|
|
|
|
makefile(); /* build Makefile */
|
|
|
|
headers(); /* make a lot of .h files */
|
|
|
|
swapconf(); /* swap config files */
|
|
|
|
printf("Don't forget to run \"make depend\"\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
1993-04-10 16:11:55 +04:00
|
|
|
#define is_paren(x) ((x == '(') || (x == ')'))
|
|
|
|
#define is_comment(x) (x == '#')
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* get_word
|
|
|
|
* returns EOF on end of file
|
|
|
|
* NULL on end of line
|
|
|
|
* pointer to the word otherwise
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
get_word(fp)
|
|
|
|
register FILE *fp;
|
|
|
|
{
|
|
|
|
static char line[80];
|
|
|
|
register int ch;
|
|
|
|
register char *cp;
|
|
|
|
|
|
|
|
while ((ch = getc(fp)) != EOF)
|
|
|
|
if (ch != ' ' && ch != '\t')
|
|
|
|
break;
|
|
|
|
if (ch == EOF)
|
|
|
|
return ((char *)EOF);
|
|
|
|
if (ch == '\n')
|
|
|
|
return (NULL);
|
1993-04-10 16:11:55 +04:00
|
|
|
if (is_paren(ch)) {
|
|
|
|
line[0] = ch;
|
|
|
|
line[1] = '\0';
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
if (is_comment(ch)) {
|
|
|
|
while ((ch = getc(fp)) != EOF)
|
|
|
|
if (ch == '\n')
|
|
|
|
break;
|
|
|
|
if (ch == EOF) return ((char *)EOF);
|
|
|
|
else return NULL;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
cp = line;
|
|
|
|
*cp++ = ch;
|
|
|
|
while ((ch = getc(fp)) != EOF) {
|
1993-04-10 16:11:55 +04:00
|
|
|
if (isspace(ch) || is_paren(ch))
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
*cp++ = ch;
|
|
|
|
}
|
|
|
|
*cp = 0;
|
|
|
|
if (ch == EOF)
|
|
|
|
return ((char *)EOF);
|
|
|
|
(void) ungetc(ch, fp);
|
|
|
|
return (line);
|
|
|
|
}
|
|
|
|
|
1993-04-10 16:11:55 +04:00
|
|
|
/*
|
|
|
|
* get_rword
|
|
|
|
* returns EOF on end of file
|
|
|
|
* NULL on end of line
|
|
|
|
* pointer to the word otherwise
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
get_rword(fp)
|
|
|
|
register FILE *fp;
|
|
|
|
{
|
|
|
|
static char line[80];
|
|
|
|
register int ch;
|
|
|
|
register char *cp;
|
|
|
|
|
|
|
|
while ((ch = getc(fp)) != EOF)
|
|
|
|
if (ch != ' ' && ch != '\t')
|
|
|
|
break;
|
|
|
|
if (ch == EOF)
|
|
|
|
return ((char *)EOF);
|
|
|
|
if (ch == '\n')
|
|
|
|
return (NULL);
|
|
|
|
cp = line;
|
|
|
|
*cp++ = ch;
|
|
|
|
while ((ch = getc(fp)) != EOF) {
|
|
|
|
if (isspace(ch) || is_paren(ch))
|
|
|
|
break;
|
|
|
|
*cp++ = ch;
|
|
|
|
}
|
|
|
|
*cp = 0;
|
|
|
|
if (ch == EOF)
|
|
|
|
return ((char *)EOF);
|
|
|
|
(void) ungetc(ch, fp);
|
|
|
|
return (line);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* get_quoted_word
|
|
|
|
* like get_word but will accept something in double or single quotes
|
|
|
|
* (to allow embedded spaces).
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
get_quoted_word(fp)
|
|
|
|
register FILE *fp;
|
|
|
|
{
|
|
|
|
static char line[256];
|
|
|
|
register int ch;
|
|
|
|
register char *cp;
|
|
|
|
|
|
|
|
while ((ch = getc(fp)) != EOF)
|
|
|
|
if (ch != ' ' && ch != '\t')
|
|
|
|
break;
|
|
|
|
if (ch == EOF)
|
|
|
|
return ((char *)EOF);
|
|
|
|
if (ch == '\n')
|
|
|
|
return (NULL);
|
|
|
|
cp = line;
|
|
|
|
if (ch == '"' || ch == '\'') {
|
|
|
|
register int quote = ch;
|
|
|
|
|
|
|
|
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(file)
|
|
|
|
char *file;
|
|
|
|
{
|
|
|
|
register char *cp;
|
|
|
|
|
1993-05-17 13:10:06 +04:00
|
|
|
#define CDIR "../compile/"
|
1993-03-21 12:45:37 +03:00
|
|
|
cp = malloc((unsigned int)(sizeof(CDIR) + strlen(PREFIX) +
|
|
|
|
(file ? strlen(file) : 0) + 2));
|
|
|
|
(void) strcpy(cp, CDIR);
|
|
|
|
(void) strcat(cp, PREFIX);
|
|
|
|
if (file) {
|
|
|
|
(void) strcat(cp, "/");
|
|
|
|
(void) strcat(cp, file);
|
|
|
|
}
|
|
|
|
return (cp);
|
|
|
|
}
|