main.c revision 1553
1/* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35static char copyright[] = 36"@(#) Copyright (c) 1980, 1993\n\ 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; 42#endif /* not lint */ 43 44#include <sys/types.h> 45#include <sys/stat.h> 46#include <sys/file.h> 47#include <stdio.h> 48#include <ctype.h> 49#include "y.tab.h" 50#include "config.h" 51 52static char *PREFIX; 53 54/* 55 * Config builds a set of files for building a UNIX 56 * system given a description of the desired system. 57 */ 58main(argc, argv) 59 int argc; 60 char **argv; 61{ 62 63 extern char *optarg; 64 extern int optind; 65 struct stat buf; 66 int ch; 67 char *p; 68 69 while ((ch = getopt(argc, argv, "gp")) != EOF) 70 switch (ch) { 71 case 'g': 72 debugging++; 73 break; 74 case 'p': 75 profiling++; 76 break; 77 case '?': 78 default: 79 goto usage; 80 } 81 argc -= optind; 82 argv += optind; 83 84 if (argc != 1) { 85usage: fputs("usage: config [-gp] sysname\n", stderr); 86 exit(1); 87 } 88 89 if (freopen(PREFIX = *argv, "r", stdin) == NULL) { 90 perror(PREFIX); 91 exit(2); 92 } 93 if (stat(p = path((char *)NULL), &buf)) { 94 if (mkdir(p, 0777)) { 95 perror(p); 96 exit(2); 97 } 98 } 99 else if ((buf.st_mode & S_IFMT) != S_IFDIR) { 100 fprintf(stderr, "config: %s isn't a directory.\n", p); 101 exit(2); 102 } 103 104 dtab = NULL; 105 confp = &conf_list; 106 compp = &comp_list; 107 if (yyparse()) 108 exit(3); 109 switch (machine) { 110 111 case MACHINE_VAX: 112 vax_ioconf(); /* Print ioconf.c */ 113 ubglue(); /* Create ubglue.s */ 114 break; 115 116 case MACHINE_TAHOE: 117 tahoe_ioconf(); 118 vbglue(); 119 break; 120 121 case MACHINE_HP300: 122 case MACHINE_LUNA68K: 123 hp300_ioconf(); 124 hpglue(); 125 break; 126 127 case MACHINE_I386: 128 i386_ioconf(); /* Print ioconf.c */ 129 vector(); /* Create vector.s */ 130 break; 131 132 case MACHINE_MIPS: 133 case MACHINE_PMAX: 134 pmax_ioconf(); 135 break; 136 137 case MACHINE_NEWS3400: 138 news_ioconf(); 139 break; 140 141 default: 142 printf("Specify machine type, e.g. ``machine vax''\n"); 143 exit(1); 144 } 145 /* 146 * make symbolic links in compilation directory 147 * for "sys" (to make genassym.c work along with #include <sys/xxx>) 148 * and similarly for "machine". 149 */ 150 { 151 char xxx[80]; 152 153 (void) sprintf(xxx, "../../%s/include", machinename); 154 (void) symlink(xxx, path("machine")); 155 } 156 makefile(); /* build Makefile */ 157 headers(); /* make a lot of .h files */ 158 swapconf(); /* swap config files */ 159 printf("Don't forget to run \"make depend\"\n"); 160 exit(0); 161} 162 163/* 164 * get_word 165 * returns EOF on end of file 166 * NULL on end of line 167 * pointer to the word otherwise 168 */ 169char * 170get_word(fp) 171 register FILE *fp; 172{ 173 static char line[80]; 174 register int ch; 175 register char *cp; 176 177 while ((ch = getc(fp)) != EOF) 178 if (ch != ' ' && ch != '\t') 179 break; 180 if (ch == EOF) 181 return ((char *)EOF); 182 if (ch == '\n') 183 return (NULL); 184 cp = line; 185 *cp++ = ch; 186 while ((ch = getc(fp)) != EOF) { 187 if (isspace(ch)) 188 break; 189 *cp++ = ch; 190 } 191 *cp = 0; 192 if (ch == EOF) 193 return ((char *)EOF); 194 (void) ungetc(ch, fp); 195 return (line); 196} 197 198/* 199 * get_quoted_word 200 * like get_word but will accept something in double or single quotes 201 * (to allow embedded spaces). 202 */ 203char * 204get_quoted_word(fp) 205 register FILE *fp; 206{ 207 static char line[256]; 208 register int ch; 209 register char *cp; 210 211 while ((ch = getc(fp)) != EOF) 212 if (ch != ' ' && ch != '\t') 213 break; 214 if (ch == EOF) 215 return ((char *)EOF); 216 if (ch == '\n') 217 return (NULL); 218 cp = line; 219 if (ch == '"' || ch == '\'') { 220 register int quote = ch; 221 222 while ((ch = getc(fp)) != EOF) { 223 if (ch == quote) 224 break; 225 if (ch == '\n') { 226 *cp = 0; 227 printf("config: missing quote reading `%s'\n", 228 line); 229 exit(2); 230 } 231 *cp++ = ch; 232 } 233 } else { 234 *cp++ = ch; 235 while ((ch = getc(fp)) != EOF) { 236 if (isspace(ch)) 237 break; 238 *cp++ = ch; 239 } 240 if (ch != EOF) 241 (void) ungetc(ch, fp); 242 } 243 *cp = 0; 244 if (ch == EOF) 245 return ((char *)EOF); 246 return (line); 247} 248 249/* 250 * prepend the path to a filename 251 */ 252char * 253path(file) 254 char *file; 255{ 256 register char *cp; 257 258#define CDIR "../../compile/" 259 cp = malloc((unsigned int)(sizeof(CDIR) + strlen(PREFIX) + 260 (file ? strlen(file) : 0) + 2)); 261 (void) strcpy(cp, CDIR); 262 (void) strcat(cp, PREFIX); 263 if (file) { 264 (void) strcat(cp, "/"); 265 (void) strcat(cp, file); 266 } 267 return (cp); 268} 269