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