Commit | Line | Data |
---|---|---|
cd68466f | 1 | /* |
f3c08ca3 KB |
2 | * Copyright (c) 1980, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
86f9c1e9 | 4 | * |
32ce521f | 5 | * %sccs.include.redist.c% |
cd68466f DF |
6 | */ |
7 | ||
8 | #ifndef lint | |
f3c08ca3 KB |
9 | static char copyright[] = |
10 | "@(#) Copyright (c) 1980, 1993\n\ | |
11 | The Regents of the University of California. All rights reserved.\n"; | |
86f9c1e9 | 12 | #endif /* not lint */ |
cd68466f | 13 | |
524aa063 | 14 | #ifndef lint |
f3c08ca3 | 15 | static char sccsid[] = "@(#)main.c 8.1 (Berkeley) %G%"; |
86f9c1e9 | 16 | #endif /* not lint */ |
ca5d0476 | 17 | |
7633a3ca KB |
18 | #include <sys/types.h> |
19 | #include <sys/stat.h> | |
20 | #include <sys/file.h> | |
ca5d0476 MT |
21 | #include <stdio.h> |
22 | #include <ctype.h> | |
23 | #include "y.tab.h" | |
24 | #include "config.h" | |
25 | ||
7633a3ca KB |
26 | static char *PREFIX; |
27 | ||
9995ca8d BJ |
28 | /* |
29 | * Config builds a set of files for building a UNIX | |
30 | * system given a description of the desired system. | |
31 | */ | |
ca5d0476 | 32 | main(argc, argv) |
9995ca8d BJ |
33 | int argc; |
34 | char **argv; | |
ca5d0476 | 35 | { |
9995ca8d | 36 | |
7633a3ca KB |
37 | extern char *optarg; |
38 | extern int optind; | |
39 | struct stat buf; | |
40 | int ch; | |
41 | char *p; | |
42 | ||
f4b2fb14 | 43 | while ((ch = getopt(argc, argv, "gp")) != EOF) |
441ba76a | 44 | switch (ch) { |
f4b2fb14 KM |
45 | case 'g': |
46 | debugging++; | |
47 | break; | |
7633a3ca KB |
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) { | |
f4b2fb14 | 59 | usage: fputs("usage: config [-gp] sysname\n", stderr); |
9995ca8d BJ |
60 | exit(1); |
61 | } | |
7633a3ca KB |
62 | |
63 | if (freopen(PREFIX = *argv, "r", stdin) == NULL) { | |
64 | perror(PREFIX); | |
9995ca8d BJ |
65 | exit(2); |
66 | } | |
7633a3ca | 67 | if (stat(p = path((char *)NULL), &buf)) { |
f4b2fb14 | 68 | if (mkdir(p, 0777)) { |
7633a3ca KB |
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 | ||
9995ca8d | 78 | dtab = NULL; |
36edb824 | 79 | confp = &conf_list; |
6e5546fb | 80 | compp = &comp_list; |
9995ca8d BJ |
81 | if (yyparse()) |
82 | exit(3); | |
83 | switch (machine) { | |
84 | ||
85 | case MACHINE_VAX: | |
86 | vax_ioconf(); /* Print ioconf.c */ | |
87 | ubglue(); /* Create ubglue.s */ | |
88 | break; | |
89 | ||
a0105456 SL |
90 | case MACHINE_TAHOE: |
91 | tahoe_ioconf(); | |
92 | vbglue(); | |
9995ca8d BJ |
93 | break; |
94 | ||
f4b2fb14 | 95 | case MACHINE_HP300: |
473c3377 | 96 | case MACHINE_LUNA68K: |
f4b2fb14 KM |
97 | hp300_ioconf(); |
98 | hpglue(); | |
99 | break; | |
100 | ||
1b6c65cb WN |
101 | case MACHINE_I386: |
102 | i386_ioconf(); /* Print ioconf.c */ | |
103 | vector(); /* Create vector.s */ | |
104 | break; | |
105 | ||
202b4043 RC |
106 | case MACHINE_MIPS: |
107 | case MACHINE_PMAX: | |
108 | pmax_ioconf(); | |
109 | break; | |
110 | ||
4bce7b73 KM |
111 | case MACHINE_NEWS3400: |
112 | news_ioconf(); | |
113 | break; | |
114 | ||
9995ca8d BJ |
115 | default: |
116 | printf("Specify machine type, e.g. ``machine vax''\n"); | |
117 | exit(1); | |
118 | } | |
11df43aa MK |
119 | /* |
120 | * make symbolic links in compilation directory | |
121 | * for "sys" (to make genassym.c work along with #include <sys/xxx>) | |
122 | * and similarly for "machine". | |
123 | */ | |
124 | { | |
125 | char xxx[80]; | |
126 | ||
d0aa7457 | 127 | (void) sprintf(xxx, "../../%s/include", machinename); |
11df43aa MK |
128 | (void) symlink(xxx, path("machine")); |
129 | } | |
ca5d0476 MT |
130 | makefile(); /* build Makefile */ |
131 | headers(); /* make a lot of .h files */ | |
36edb824 | 132 | swapconf(); /* swap config files */ |
94e09492 | 133 | printf("Don't forget to run \"make depend\"\n"); |
70a77d13 | 134 | exit(0); |
ca5d0476 MT |
135 | } |
136 | ||
137 | /* | |
138 | * get_word | |
139 | * returns EOF on end of file | |
140 | * NULL on end of line | |
141 | * pointer to the word otherwise | |
142 | */ | |
9995ca8d BJ |
143 | char * |
144 | get_word(fp) | |
145 | register FILE *fp; | |
ca5d0476 | 146 | { |
9995ca8d BJ |
147 | static char line[80]; |
148 | register int ch; | |
149 | register char *cp; | |
ca5d0476 | 150 | |
9995ca8d BJ |
151 | while ((ch = getc(fp)) != EOF) |
152 | if (ch != ' ' && ch != '\t') | |
153 | break; | |
154 | if (ch == EOF) | |
22d68ad0 | 155 | return ((char *)EOF); |
9995ca8d BJ |
156 | if (ch == '\n') |
157 | return (NULL); | |
158 | cp = line; | |
ca5d0476 | 159 | *cp++ = ch; |
9995ca8d BJ |
160 | while ((ch = getc(fp)) != EOF) { |
161 | if (isspace(ch)) | |
162 | break; | |
163 | *cp++ = ch; | |
164 | } | |
165 | *cp = 0; | |
166 | if (ch == EOF) | |
22d68ad0 BJ |
167 | return ((char *)EOF); |
168 | (void) ungetc(ch, fp); | |
9995ca8d | 169 | return (line); |
ca5d0476 | 170 | } |
0a2de74e | 171 | |
441ba76a MK |
172 | /* |
173 | * get_quoted_word | |
174 | * like get_word but will accept something in double or single quotes | |
175 | * (to allow embedded spaces). | |
176 | */ | |
177 | char * | |
178 | get_quoted_word(fp) | |
179 | register FILE *fp; | |
180 | { | |
181 | static char line[256]; | |
182 | register int ch; | |
183 | register char *cp; | |
184 | ||
185 | while ((ch = getc(fp)) != EOF) | |
186 | if (ch != ' ' && ch != '\t') | |
187 | break; | |
188 | if (ch == EOF) | |
189 | return ((char *)EOF); | |
190 | if (ch == '\n') | |
191 | return (NULL); | |
192 | cp = line; | |
193 | if (ch == '"' || ch == '\'') { | |
194 | register int quote = ch; | |
195 | ||
196 | while ((ch = getc(fp)) != EOF) { | |
197 | if (ch == quote) | |
198 | break; | |
199 | if (ch == '\n') { | |
200 | *cp = 0; | |
201 | printf("config: missing quote reading `%s'\n", | |
202 | line); | |
203 | exit(2); | |
204 | } | |
205 | *cp++ = ch; | |
206 | } | |
207 | } else { | |
208 | *cp++ = ch; | |
209 | while ((ch = getc(fp)) != EOF) { | |
210 | if (isspace(ch)) | |
211 | break; | |
212 | *cp++ = ch; | |
213 | } | |
214 | if (ch != EOF) | |
215 | (void) ungetc(ch, fp); | |
216 | } | |
217 | *cp = 0; | |
218 | if (ch == EOF) | |
219 | return ((char *)EOF); | |
220 | return (line); | |
221 | } | |
222 | ||
0a2de74e | 223 | /* |
9995ca8d | 224 | * prepend the path to a filename |
0a2de74e | 225 | */ |
22d68ad0 | 226 | char * |
0a2de74e | 227 | path(file) |
9995ca8d | 228 | char *file; |
0a2de74e | 229 | { |
9995ca8d | 230 | register char *cp; |
0a2de74e | 231 | |
d0aa7457 | 232 | #define CDIR "../../compile/" |
b5902fe5 | 233 | cp = malloc((unsigned int)(sizeof(CDIR) + strlen(PREFIX) + |
1b4f0d48 | 234 | (file ? strlen(file) : 0) + 2)); |
d0aa7457 | 235 | (void) strcpy(cp, CDIR); |
22d68ad0 | 236 | (void) strcat(cp, PREFIX); |
7633a3ca KB |
237 | if (file) { |
238 | (void) strcat(cp, "/"); | |
239 | (void) strcat(cp, file); | |
240 | } | |
9995ca8d | 241 | return (cp); |
0a2de74e | 242 | } |