]> git.saurik.com Git - apple/xnu.git/blob - SETUP/config/main.c
xnu-2422.90.20.tar.gz
[apple/xnu.git] / SETUP / config / main.c
1 /*
2 * Copyright (c) 1999-2009 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License."
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24 /*
25 * Mach Operating System
26 * Copyright (c) 1990 Carnegie-Mellon University
27 * Copyright (c) 1989 Carnegie-Mellon University
28 * Copyright (c) 1988 Carnegie-Mellon University
29 * Copyright (c) 1987 Carnegie-Mellon University
30 * All rights reserved. The CMU software License Agreement specifies
31 * the terms and conditions for use and redistribution.
32 */
33
34 /*
35 * Copyright (c) 1980 Regents of the University of California.
36 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms are permitted
39 * provided that the above copyright notice and this paragraph are
40 * duplicated in all such forms and that any documentation,
41 * advertising materials, and other materials related to such
42 * distribution and use acknowledge that the software was developed
43 * by the University of California, Berkeley. The name of the
44 * University may not be used to endorse or promote products derived
45 * from this software without specific prior written permission.
46 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
47 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
48 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
49 */
50
51 #ifndef lint
52 char copyright[] =
53 "@(#) Copyright (c) 1980 Regents of the University of California.\n\
54 All rights reserved.\n";
55 #endif /* not lint */
56
57 #ifndef lint
58 static char sccsid[] __attribute__((used)) = "@(#)main.c 5.9 (Berkeley) 6/18/88";
59 #endif /* not lint */
60
61 #include <stdio.h>
62 #include <ctype.h>
63 #include "parser.h"
64 #include "config.h"
65
66 /*
67 * Config builds a set of files for building a UNIX
68 * system given a description of the desired system.
69 */
70 int
71 main(int argc, char *argv[])
72 {
73
74 source_directory = ".."; /* default */
75 object_directory = "..";
76 config_directory = (char *) 0;
77 while ((argc > 1) && (argv[1][0] == '-')) {
78 char *c;
79
80 argv++; argc--;
81 for (c = &argv[0][1]; *c ; c++) {
82 switch (*c) {
83 case 'b':
84 build_directory = argv[1];
85 goto check_arg;
86
87 case 'd':
88 source_directory = argv[1];
89 goto check_arg;
90
91 case 'o':
92 object_directory = argv[1];
93 goto check_arg;
94
95 case 'c':
96 config_directory = argv[1];
97
98 check_arg:
99 if (argv[1] == (char *) 0)
100 goto usage_error;
101 argv++; argc--;
102 break;
103
104 case 'p':
105 profiling++;
106 break;
107 default:
108 goto usage_error;
109 }
110 }
111 }
112 if (config_directory == (char *) 0) {
113 config_directory =
114 malloc((unsigned) strlen(source_directory) + 6);
115 (void) sprintf(config_directory, "%s/conf", source_directory);
116 }
117 if (argc != 2) {
118 usage_error: ;
119 fprintf(stderr, "usage: config [ -bcdo dir ] [ -p ] sysname\n");
120 exit(1);
121 }
122 if (!build_directory)
123 build_directory = argv[1];
124 if (freopen(argv[1], "r", stdin) == NULL) {
125 perror(argv[1]);
126 exit(2);
127 }
128 dtab = NULL;
129 confp = &conf_list;
130 opt = 0;
131 if (yyparse())
132 exit(3);
133 switch (machine) {
134
135 case MACHINE_VAX:
136 vax_ioconf(); /* Print ioconf.c */
137 ubglue(); /* Create ubglue.s */
138 break;
139
140 case MACHINE_SUN:
141 sun_ioconf();
142 break;
143
144 case MACHINE_SUN2:
145 case MACHINE_SUN3:
146 case MACHINE_SUN4:
147 sun_ioconf(); /* Print ioconf.c */
148 mbglue(); /* Create mbglue.s */
149 break;
150
151 case MACHINE_ROMP:
152 romp_ioconf();
153 break;
154
155 case MACHINE_MMAX:
156 mmax_ioconf();
157 break;
158
159 case MACHINE_SQT:
160 sqt_ioconf();
161 break;
162
163 case MACHINE_I386:
164 case MACHINE_IX:
165 i386_ioconf();
166 break;
167
168 case MACHINE_MIPSY:
169 case MACHINE_MIPS:
170 mips_ioconf();
171 break;
172
173 case MACHINE_I860:
174 /* i860_ioconf(); */
175 break;
176
177 case MACHINE_M68K:
178 m68k_ioconf();
179 break;
180
181 case MACHINE_M88K:
182 m88k_ioconf();
183 break;
184
185 case MACHINE_M98K:
186 m98k_ioconf();
187 break;
188
189 case MACHINE_HPPA:
190 hppa_ioconf();
191 break;
192
193 case MACHINE_SPARC:
194 sparc_ioconf();
195 break;
196
197 case MACHINE_PPC:
198 ppc_ioconf();
199 break;
200
201 case MACHINE_ARM:
202 arm_ioconf();
203 break;
204
205 case MACHINE_X86_64:
206 x86_64_ioconf();
207 break;
208
209 default:
210 printf("Specify machine type, e.g. ``machine vax''\n");
211 exit(1);
212 }
213
214 makefile(); /* build Makefile */
215 headers(); /* make a lot of .h files */
216 swapconf(); /* swap config files */
217
218 return 0;
219 }
220
221 /*
222 * get_word
223 * returns EOF on end of file
224 * NULL on end of line
225 * pointer to the word otherwise
226 */
227 const char *
228 get_word(FILE *fp)
229 {
230 static char line[80];
231 register int ch;
232 register char *cp;
233
234 while ((ch = getc(fp)) != EOF)
235 if (ch != ' ' && ch != '\t')
236 break;
237 if (ch == EOF)
238 return ((char *)EOF);
239 if (ch == '\n')
240 return (NULL);
241 if (ch == '|')
242 return( "|");
243 cp = line;
244 *cp++ = ch;
245 while ((ch = getc(fp)) != EOF) {
246 if (isspace(ch))
247 break;
248 *cp++ = ch;
249 }
250 *cp = 0;
251 if (ch == EOF)
252 return ((char *)EOF);
253 (void) ungetc(ch, fp);
254 return (line);
255 }
256
257 /*
258 * get_rest
259 * returns EOF on end of file
260 * NULL on end of line
261 * pointer to the word otherwise
262 */
263 char *
264 get_rest(FILE *fp)
265 {
266 static char line[80];
267 register int ch;
268 register char *cp;
269
270 cp = line;
271 while ((ch = getc(fp)) != EOF) {
272 if (ch == '\n')
273 break;
274 *cp++ = ch;
275 }
276 *cp = 0;
277 if (ch == EOF)
278 return ((char *)EOF);
279 return (line);
280 }
281
282 /*
283 * prepend the path to a filename
284 */
285 char *
286 path(const char *file)
287 {
288 register char *cp;
289
290 cp = malloc((unsigned)(strlen(build_directory)+
291 strlen(file)+
292 strlen(object_directory)+
293 3));
294 (void) sprintf(cp, "%s/%s/%s", object_directory, build_directory, file);
295 return (cp);
296 }