1 /* 2 * Copyright (c) 1980 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 char copyright[] = 10 "@(#) Copyright (c) 1980 Regents of the University of California.\n\ 11 All rights reserved.\n"; 12 #endif /* not lint */ 13 14 #ifndef lint 15 static char sccsid[] = "@(#)main.c 5.20 (Berkeley) 07/31/92"; 16 #endif /* not lint */ 17 18 #include <sys/types.h> 19 #include <sys/stat.h> 20 #include <sys/file.h> 21 #include <stdio.h> 22 #include <ctype.h> 23 #include "y.tab.h" 24 #include "config.h" 25 26 static char *PREFIX; 27 28 /* 29 * Config builds a set of files for building a UNIX 30 * system given a description of the desired system. 31 */ 32 main(argc, argv) 33 int argc; 34 char **argv; 35 { 36 37 extern char *optarg; 38 extern int optind; 39 struct stat buf; 40 int ch; 41 char *p; 42 43 while ((ch = getopt(argc, argv, "gp")) != EOF) 44 switch (ch) { 45 case 'g': 46 debugging++; 47 break; 48 case 'p': 49 profiling++; 50 break; 51 case '?': 52 default: 53 goto usage; 54 } 55 argc -= optind; 56 argv += optind; 57 58 if (argc != 1) { 59 usage: fputs("usage: config [-gp] sysname\n", stderr); 60 exit(1); 61 } 62 63 if (freopen(PREFIX = *argv, "r", stdin) == NULL) { 64 perror(PREFIX); 65 exit(2); 66 } 67 if (stat(p = path((char *)NULL), &buf)) { 68 if (mkdir(p, 0777)) { 69 perror(p); 70 exit(2); 71 } 72 } 73 else if ((buf.st_mode & S_IFMT) != S_IFDIR) { 74 fprintf(stderr, "config: %s isn't a directory.\n", p); 75 exit(2); 76 } 77 78 dtab = NULL; 79 confp = &conf_list; 80 if (yyparse()) 81 exit(3); 82 switch (machine) { 83 84 case MACHINE_VAX: 85 vax_ioconf(); /* Print ioconf.c */ 86 ubglue(); /* Create ubglue.s */ 87 break; 88 89 case MACHINE_TAHOE: 90 tahoe_ioconf(); 91 vbglue(); 92 break; 93 94 case MACHINE_HP300: 95 case MACHINE_LUNA68K: 96 hp300_ioconf(); 97 hpglue(); 98 break; 99 100 case MACHINE_I386: 101 i386_ioconf(); /* Print ioconf.c */ 102 vector(); /* Create vector.s */ 103 break; 104 105 case MACHINE_MIPS: 106 case MACHINE_PMAX: 107 pmax_ioconf(); 108 break; 109 110 case MACHINE_NEWS3400: 111 news_ioconf(); 112 break; 113 114 default: 115 printf("Specify machine type, e.g. ``machine vax''\n"); 116 exit(1); 117 } 118 /* 119 * make symbolic links in compilation directory 120 * for "sys" (to make genassym.c work along with #include <sys/xxx>) 121 * and similarly for "machine". 122 */ 123 { 124 char xxx[80]; 125 126 (void) sprintf(xxx, "../../%s/include", machinename); 127 (void) symlink(xxx, path("machine")); 128 } 129 makefile(); /* build Makefile */ 130 headers(); /* make a lot of .h files */ 131 swapconf(); /* swap config files */ 132 printf("Don't forget to run \"make depend\"\n"); 133 exit(0); 134 } 135 136 /* 137 * get_word 138 * returns EOF on end of file 139 * NULL on end of line 140 * pointer to the word otherwise 141 */ 142 char * 143 get_word(fp) 144 register FILE *fp; 145 { 146 static char line[80]; 147 register int ch; 148 register char *cp; 149 150 while ((ch = getc(fp)) != EOF) 151 if (ch != ' ' && ch != '\t') 152 break; 153 if (ch == EOF) 154 return ((char *)EOF); 155 if (ch == '\n') 156 return (NULL); 157 cp = line; 158 *cp++ = ch; 159 while ((ch = getc(fp)) != EOF) { 160 if (isspace(ch)) 161 break; 162 *cp++ = ch; 163 } 164 *cp = 0; 165 if (ch == EOF) 166 return ((char *)EOF); 167 (void) ungetc(ch, fp); 168 return (line); 169 } 170 171 /* 172 * get_quoted_word 173 * like get_word but will accept something in double or single quotes 174 * (to allow embedded spaces). 175 */ 176 char * 177 get_quoted_word(fp) 178 register FILE *fp; 179 { 180 static char line[256]; 181 register int ch; 182 register char *cp; 183 184 while ((ch = getc(fp)) != EOF) 185 if (ch != ' ' && ch != '\t') 186 break; 187 if (ch == EOF) 188 return ((char *)EOF); 189 if (ch == '\n') 190 return (NULL); 191 cp = line; 192 if (ch == '"' || ch == '\'') { 193 register int quote = ch; 194 195 while ((ch = getc(fp)) != EOF) { 196 if (ch == quote) 197 break; 198 if (ch == '\n') { 199 *cp = 0; 200 printf("config: missing quote reading `%s'\n", 201 line); 202 exit(2); 203 } 204 *cp++ = ch; 205 } 206 } else { 207 *cp++ = ch; 208 while ((ch = getc(fp)) != EOF) { 209 if (isspace(ch)) 210 break; 211 *cp++ = ch; 212 } 213 if (ch != EOF) 214 (void) ungetc(ch, fp); 215 } 216 *cp = 0; 217 if (ch == EOF) 218 return ((char *)EOF); 219 return (line); 220 } 221 222 /* 223 * prepend the path to a filename 224 */ 225 char * 226 path(file) 227 char *file; 228 { 229 register char *cp; 230 231 #define CDIR "../../compile/" 232 cp = malloc((unsigned int)(sizeof(CDIR) + strlen(PREFIX) + 233 (file ? strlen(file) : 0) + 2)); 234 (void) strcpy(cp, CDIR); 235 (void) strcat(cp, PREFIX); 236 if (file) { 237 (void) strcat(cp, "/"); 238 (void) strcat(cp, file); 239 } 240 return (cp); 241 } 242