/* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * advertising materials, and other materials related to such * distribution and use acknowledge that the software was developed * by the University of California, Berkeley. The name of the * University may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef lint char copyright[] = "@(#) Copyright (c) 1980 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)main.c 5.9 (Berkeley) 6/18/88"; #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; while ((ch = getopt(argc, argv, "p")) != EOF) switch((char)ch) { case 'p': profiling++; break; case '?': default: goto usage; } argc -= optind; argv += optind; if (argc != 1) { usage: fputs("usage: config [-p] sysname\n", stderr); exit(1); } if (freopen(PREFIX = *argv, "r", stdin) == NULL) { perror(PREFIX); exit(2); } if (stat(p = path((char *)NULL), &buf)) { if (mkdir(p, 0755)) { 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; 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]; (void) symlink("../h", path("sys")); (void) sprintf(xxx, "../%s", machinename); (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); } /* * 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); 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); } /* * prepend the path to a filename */ char * path(file) char *file; { register char *cp; cp = malloc((unsigned)(strlen(PREFIX)+strlen(file)+5)); (void) strcpy(cp, "../"); (void) strcat(cp, PREFIX); if (file) { (void) strcat(cp, "/"); (void) strcat(cp, file); } return (cp); }