Commit | Line | Data |
---|---|---|
15637ed4 RG |
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, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | */ | |
33 | ||
34 | #ifndef lint | |
35 | char copyright[] = | |
36 | "@(#) Copyright (c) 1980 Regents of the University of California.\n\ | |
37 | All rights reserved.\n"; | |
38 | #endif /* not lint */ | |
39 | ||
40 | #ifndef lint | |
41 | static char sccsid[] = "@(#)main.c 5.17 (Berkeley) 7/1/91"; | |
42 | #endif /* not lint */ | |
43 | ||
44 | #include <sys/types.h> | |
45 | #include <sys/stat.h> | |
46 | #include <sys/file.h> | |
47 | #include <stdio.h> | |
48 | #include <ctype.h> | |
49 | #include "y.tab.h" | |
50 | #include "config.h" | |
51 | ||
52 | static char *PREFIX; | |
53 | ||
54 | /* | |
55 | * Config builds a set of files for building a UNIX | |
56 | * system given a description of the desired system. | |
57 | */ | |
58 | main(argc, argv) | |
59 | int argc; | |
60 | char **argv; | |
61 | { | |
62 | ||
63 | extern char *optarg; | |
64 | extern int optind; | |
65 | struct stat buf; | |
66 | int ch; | |
67 | char *p; | |
68 | ||
69 | while ((ch = getopt(argc, argv, "gp")) != EOF) | |
70 | switch (ch) { | |
71 | case 'g': | |
72 | debugging++; | |
73 | break; | |
74 | case 'p': | |
75 | profiling++; | |
76 | break; | |
77 | case '?': | |
78 | default: | |
79 | goto usage; | |
80 | } | |
81 | argc -= optind; | |
82 | argv += optind; | |
83 | ||
84 | if (argc != 1) { | |
85 | usage: fputs("usage: config [-gp] sysname\n", stderr); | |
86 | exit(1); | |
87 | } | |
88 | ||
89 | if (freopen(PREFIX = *argv, "r", stdin) == NULL) { | |
90 | perror(PREFIX); | |
91 | exit(2); | |
92 | } | |
93 | if (stat(p = path((char *)NULL), &buf)) { | |
94 | if (mkdir(p, 0777)) { | |
95 | perror(p); | |
96 | exit(2); | |
97 | } | |
98 | } | |
99 | else if ((buf.st_mode & S_IFMT) != S_IFDIR) { | |
100 | fprintf(stderr, "config: %s isn't a directory.\n", p); | |
101 | exit(2); | |
102 | } | |
103 | ||
104 | dtab = NULL; | |
105 | confp = &conf_list; | |
106 | if (yyparse()) | |
107 | exit(3); | |
108 | switch (machine) { | |
109 | ||
110 | case MACHINE_VAX: | |
111 | vax_ioconf(); /* Print ioconf.c */ | |
112 | ubglue(); /* Create ubglue.s */ | |
113 | break; | |
114 | ||
115 | case MACHINE_TAHOE: | |
116 | tahoe_ioconf(); | |
117 | vbglue(); | |
118 | break; | |
119 | ||
120 | case MACHINE_HP300: | |
121 | hp300_ioconf(); | |
122 | hpglue(); | |
123 | break; | |
124 | ||
125 | case MACHINE_I386: | |
126 | i386_ioconf(); /* Print ioconf.c */ | |
127 | vector(); /* Create vector.s */ | |
128 | break; | |
129 | ||
130 | default: | |
131 | printf("Specify machine type, e.g. ``machine vax''\n"); | |
132 | exit(1); | |
133 | } | |
134 | /* | |
135 | * make symbolic links in compilation directory | |
136 | * for "sys" (to make genassym.c work along with #include <sys/xxx>) | |
137 | * and similarly for "machine". | |
138 | */ | |
139 | { | |
140 | char xxx[80]; | |
141 | ||
142 | (void) sprintf(xxx, "../../%s/include", machinename); | |
143 | (void) symlink(xxx, path("machine")); | |
144 | } | |
145 | makefile(); /* build Makefile */ | |
146 | headers(); /* make a lot of .h files */ | |
147 | swapconf(); /* swap config files */ | |
148 | printf("Don't forget to run \"make depend\"\n"); | |
149 | exit(0); | |
150 | } | |
151 | ||
152 | /* | |
153 | * get_word | |
154 | * returns EOF on end of file | |
155 | * NULL on end of line | |
156 | * pointer to the word otherwise | |
157 | */ | |
158 | char * | |
159 | get_word(fp) | |
160 | register FILE *fp; | |
161 | { | |
162 | static char line[80]; | |
163 | register int ch; | |
164 | register char *cp; | |
165 | ||
166 | while ((ch = getc(fp)) != EOF) | |
167 | if (ch != ' ' && ch != '\t') | |
168 | break; | |
169 | if (ch == EOF) | |
170 | return ((char *)EOF); | |
171 | if (ch == '\n') | |
172 | return (NULL); | |
173 | cp = line; | |
174 | *cp++ = ch; | |
175 | while ((ch = getc(fp)) != EOF) { | |
176 | if (isspace(ch)) | |
177 | break; | |
178 | *cp++ = ch; | |
179 | } | |
180 | *cp = 0; | |
181 | if (ch == EOF) | |
182 | return ((char *)EOF); | |
183 | (void) ungetc(ch, fp); | |
184 | return (line); | |
185 | } | |
186 | ||
187 | /* | |
188 | * get_quoted_word | |
189 | * like get_word but will accept something in double or single quotes | |
190 | * (to allow embedded spaces). | |
191 | */ | |
192 | char * | |
193 | get_quoted_word(fp) | |
194 | register FILE *fp; | |
195 | { | |
196 | static char line[256]; | |
197 | register int ch; | |
198 | register char *cp; | |
199 | ||
200 | while ((ch = getc(fp)) != EOF) | |
201 | if (ch != ' ' && ch != '\t') | |
202 | break; | |
203 | if (ch == EOF) | |
204 | return ((char *)EOF); | |
205 | if (ch == '\n') | |
206 | return (NULL); | |
207 | cp = line; | |
208 | if (ch == '"' || ch == '\'') { | |
209 | register int quote = ch; | |
210 | ||
211 | while ((ch = getc(fp)) != EOF) { | |
212 | if (ch == quote) | |
213 | break; | |
214 | if (ch == '\n') { | |
215 | *cp = 0; | |
216 | printf("config: missing quote reading `%s'\n", | |
217 | line); | |
218 | exit(2); | |
219 | } | |
220 | *cp++ = ch; | |
221 | } | |
222 | } else { | |
223 | *cp++ = ch; | |
224 | while ((ch = getc(fp)) != EOF) { | |
225 | if (isspace(ch)) | |
226 | break; | |
227 | *cp++ = ch; | |
228 | } | |
229 | if (ch != EOF) | |
230 | (void) ungetc(ch, fp); | |
231 | } | |
232 | *cp = 0; | |
233 | if (ch == EOF) | |
234 | return ((char *)EOF); | |
235 | return (line); | |
236 | } | |
237 | ||
238 | /* | |
239 | * prepend the path to a filename | |
240 | */ | |
241 | char * | |
242 | path(file) | |
243 | char *file; | |
244 | { | |
245 | register char *cp; | |
246 | ||
247 | #define CDIR "../../compile/" | |
248 | cp = malloc((unsigned int)(sizeof(CDIR) + strlen(PREFIX) + | |
249 | (file ? strlen(file) : 0) + 2)); | |
250 | (void) strcpy(cp, CDIR); | |
251 | (void) strcat(cp, PREFIX); | |
252 | if (file) { | |
253 | (void) strcat(cp, "/"); | |
254 | (void) strcat(cp, file); | |
255 | } | |
256 | return (cp); | |
257 | } |