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.18 (Berkeley) 09/07/91"; 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 hp300_ioconf(); 96 hpglue(); 97 break; 98 99 case MACHINE_I386: 100 i386_ioconf(); /* Print ioconf.c */ 101 vector(); /* Create vector.s */ 102 break; 103 104 case MACHINE_MIPS: 105 case MACHINE_PMAX: 106 pmax_ioconf(); 107 break; 108 109 default: 110 printf("Specify machine type, e.g. ``machine vax''\n"); 111 exit(1); 112 } 113 /* 114 * make symbolic links in compilation directory 115 * for "sys" (to make genassym.c work along with #include <sys/xxx>) 116 * and similarly for "machine". 117 */ 118 { 119 char xxx[80]; 120 121 (void) sprintf(xxx, "../../%s/include", machinename); 122 (void) symlink(xxx, path("machine")); 123 } 124 makefile(); /* build Makefile */ 125 headers(); /* make a lot of .h files */ 126 swapconf(); /* swap config files */ 127 printf("Don't forget to run \"make depend\"\n"); 128 exit(0); 129 } 130 131 /* 132 * get_word 133 * returns EOF on end of file 134 * NULL on end of line 135 * pointer to the word otherwise 136 */ 137 char * 138 get_word(fp) 139 register FILE *fp; 140 { 141 static char line[80]; 142 register int ch; 143 register char *cp; 144 145 while ((ch = getc(fp)) != EOF) 146 if (ch != ' ' && ch != '\t') 147 break; 148 if (ch == EOF) 149 return ((char *)EOF); 150 if (ch == '\n') 151 return (NULL); 152 cp = line; 153 *cp++ = ch; 154 while ((ch = getc(fp)) != EOF) { 155 if (isspace(ch)) 156 break; 157 *cp++ = ch; 158 } 159 *cp = 0; 160 if (ch == EOF) 161 return ((char *)EOF); 162 (void) ungetc(ch, fp); 163 return (line); 164 } 165 166 /* 167 * get_quoted_word 168 * like get_word but will accept something in double or single quotes 169 * (to allow embedded spaces). 170 */ 171 char * 172 get_quoted_word(fp) 173 register FILE *fp; 174 { 175 static char line[256]; 176 register int ch; 177 register char *cp; 178 179 while ((ch = getc(fp)) != EOF) 180 if (ch != ' ' && ch != '\t') 181 break; 182 if (ch == EOF) 183 return ((char *)EOF); 184 if (ch == '\n') 185 return (NULL); 186 cp = line; 187 if (ch == '"' || ch == '\'') { 188 register int quote = ch; 189 190 while ((ch = getc(fp)) != EOF) { 191 if (ch == quote) 192 break; 193 if (ch == '\n') { 194 *cp = 0; 195 printf("config: missing quote reading `%s'\n", 196 line); 197 exit(2); 198 } 199 *cp++ = ch; 200 } 201 } else { 202 *cp++ = ch; 203 while ((ch = getc(fp)) != EOF) { 204 if (isspace(ch)) 205 break; 206 *cp++ = ch; 207 } 208 if (ch != EOF) 209 (void) ungetc(ch, fp); 210 } 211 *cp = 0; 212 if (ch == EOF) 213 return ((char *)EOF); 214 return (line); 215 } 216 217 /* 218 * prepend the path to a filename 219 */ 220 char * 221 path(file) 222 char *file; 223 { 224 register char *cp; 225 226 #define CDIR "../../compile/" 227 cp = malloc((unsigned int)(sizeof(CDIR) + strlen(PREFIX) + 228 (file ? strlen(file) : 0) + 2)); 229 (void) strcpy(cp, CDIR); 230 (void) strcat(cp, PREFIX); 231 if (file) { 232 (void) strcat(cp, "/"); 233 (void) strcat(cp, file); 234 } 235 return (cp); 236 } 237