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.15 (Berkeley) 02/06/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((char)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 default: 105 printf("Specify machine type, e.g. ``machine vax''\n"); 106 exit(1); 107 } 108 /* 109 * make symbolic links in compilation directory 110 * for "sys" (to make genassym.c work along with #include <sys/xxx>) 111 * and similarly for "machine". 112 */ 113 { 114 char xxx[80]; 115 116 (void) sprintf(xxx, "../../%s/include", machinename); 117 (void) symlink(xxx, path("machine")); 118 } 119 makefile(); /* build Makefile */ 120 headers(); /* make a lot of .h files */ 121 swapconf(); /* swap config files */ 122 printf("Don't forget to run \"make depend\"\n"); 123 exit(0); 124 } 125 126 /* 127 * get_word 128 * returns EOF on end of file 129 * NULL on end of line 130 * pointer to the word otherwise 131 */ 132 char * 133 get_word(fp) 134 register FILE *fp; 135 { 136 static char line[80]; 137 register int ch; 138 register char *cp; 139 140 while ((ch = getc(fp)) != EOF) 141 if (ch != ' ' && ch != '\t') 142 break; 143 if (ch == EOF) 144 return ((char *)EOF); 145 if (ch == '\n') 146 return (NULL); 147 cp = line; 148 *cp++ = ch; 149 while ((ch = getc(fp)) != EOF) { 150 if (isspace(ch)) 151 break; 152 *cp++ = ch; 153 } 154 *cp = 0; 155 if (ch == EOF) 156 return ((char *)EOF); 157 (void) ungetc(ch, fp); 158 return (line); 159 } 160 161 /* 162 * prepend the path to a filename 163 */ 164 char * 165 path(file) 166 char *file; 167 { 168 register char *cp; 169 170 #define CDIR "../../compile/" 171 cp = malloc((unsigned int)(sizeof(CDIR) + strlen(PREFIX) + 172 strlen(file) + 2)); 173 (void) strcpy(cp, CDIR); 174 (void) strcat(cp, PREFIX); 175 if (file) { 176 (void) strcat(cp, "/"); 177 (void) strcat(cp, file); 178 } 179 return (cp); 180 } 181