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