1 /* 2 * Copyright (c) 1980 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 18 #ifndef lint 19 char copyright[] = 20 "@(#) Copyright (c) 1980 Regents of the University of California.\n\ 21 All rights reserved.\n"; 22 #endif /* not lint */ 23 24 #ifndef lint 25 static char sccsid[] = "@(#)main.c 5.10 (Berkeley) 04/25/89"; 26 #endif /* not lint */ 27 28 #include <sys/types.h> 29 #include <sys/stat.h> 30 #include <sys/file.h> 31 #include <stdio.h> 32 #include <ctype.h> 33 #include "y.tab.h" 34 #include "config.h" 35 36 static char *PREFIX; 37 38 /* 39 * Config builds a set of files for building a UNIX 40 * system given a description of the desired system. 41 */ 42 main(argc, argv) 43 int argc; 44 char **argv; 45 { 46 47 extern char *optarg; 48 extern int optind; 49 struct stat buf; 50 int ch; 51 char *p; 52 53 while ((ch = getopt(argc, argv, "p")) != EOF) 54 switch((char)ch) { 55 case 'p': 56 profiling++; 57 break; 58 case '?': 59 default: 60 goto usage; 61 } 62 argc -= optind; 63 argv += optind; 64 65 if (argc != 1) { 66 usage: fputs("usage: config [-p] sysname\n", stderr); 67 exit(1); 68 } 69 70 if (freopen(PREFIX = *argv, "r", stdin) == NULL) { 71 perror(PREFIX); 72 exit(2); 73 } 74 if (stat(p = path((char *)NULL), &buf)) { 75 if (mkdir(p, 0755)) { 76 perror(p); 77 exit(2); 78 } 79 } 80 else if ((buf.st_mode & S_IFMT) != S_IFDIR) { 81 fprintf(stderr, "config: %s isn't a directory.\n", p); 82 exit(2); 83 } 84 85 dtab = NULL; 86 confp = &conf_list; 87 if (yyparse()) 88 exit(3); 89 switch (machine) { 90 91 case MACHINE_VAX: 92 vax_ioconf(); /* Print ioconf.c */ 93 ubglue(); /* Create ubglue.s */ 94 break; 95 96 case MACHINE_TAHOE: 97 tahoe_ioconf(); 98 vbglue(); 99 break; 100 101 default: 102 printf("Specify machine type, e.g. ``machine vax''\n"); 103 exit(1); 104 } 105 /* 106 * make symbolic links in compilation directory 107 * for "sys" (to make genassym.c work along with #include <sys/xxx>) 108 * and similarly for "machine". 109 */ 110 { 111 char xxx[80]; 112 113 (void) symlink("../sys", path("sys")); 114 (void) sprintf(xxx, "../%s", machinename); 115 (void) symlink(xxx, path("machine")); 116 } 117 makefile(); /* build Makefile */ 118 headers(); /* make a lot of .h files */ 119 swapconf(); /* swap config files */ 120 printf("Don't forget to run \"make depend\"\n"); 121 exit(0); 122 } 123 124 /* 125 * get_word 126 * returns EOF on end of file 127 * NULL on end of line 128 * pointer to the word otherwise 129 */ 130 char * 131 get_word(fp) 132 register FILE *fp; 133 { 134 static char line[80]; 135 register int ch; 136 register char *cp; 137 138 while ((ch = getc(fp)) != EOF) 139 if (ch != ' ' && ch != '\t') 140 break; 141 if (ch == EOF) 142 return ((char *)EOF); 143 if (ch == '\n') 144 return (NULL); 145 cp = line; 146 *cp++ = ch; 147 while ((ch = getc(fp)) != EOF) { 148 if (isspace(ch)) 149 break; 150 *cp++ = ch; 151 } 152 *cp = 0; 153 if (ch == EOF) 154 return ((char *)EOF); 155 (void) ungetc(ch, fp); 156 return (line); 157 } 158 159 /* 160 * prepend the path to a filename 161 */ 162 char * 163 path(file) 164 char *file; 165 { 166 register char *cp; 167 168 cp = malloc((unsigned)(strlen(PREFIX)+strlen(file)+5)); 169 (void) strcpy(cp, "../"); 170 (void) strcat(cp, PREFIX); 171 if (file) { 172 (void) strcat(cp, "/"); 173 (void) strcat(cp, file); 174 } 175 return (cp); 176 } 177