]> git.saurik.com Git - apple/xnu.git/blob - SETUP/config/main.c
xnu-3789.41.3.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
134 mkioconf(); /* ioconf.c */
135 makefile(); /* build Makefile */
136 headers(); /* make a lot of .h files */
137
138 return 0;
139 }
140
141 /*
142 * get_word
143 * returns EOF on end of file
144 * NULL on end of line
145 * pointer to the word otherwise
146 */
147 const char *
148 get_word(FILE *fp)
149 {
150 static char line[80];
151 int ch;
152 char *cp;
153
154 while ((ch = getc(fp)) != EOF)
155 if (ch != ' ' && ch != '\t')
156 break;
157 if (ch == EOF)
158 return ((char *)EOF);
159 if (ch == '\n')
160 return (NULL);
161 if (ch == '|')
162 return( "|");
163 cp = line;
164 *cp++ = ch;
165 while ((ch = getc(fp)) != EOF) {
166 if (isspace(ch))
167 break;
168 *cp++ = ch;
169 }
170 *cp = 0;
171 if (ch == EOF)
172 return ((char *)EOF);
173 (void) ungetc(ch, fp);
174 return (line);
175 }
176
177 /*
178 * get_rest
179 * returns EOF on end of file
180 * NULL on end of line
181 * pointer to the word otherwise
182 */
183 char *
184 get_rest(FILE *fp)
185 {
186 static char line[80];
187 int ch;
188 char *cp;
189
190 cp = line;
191 while ((ch = getc(fp)) != EOF) {
192 if (ch == '\n')
193 break;
194 *cp++ = ch;
195 }
196 *cp = 0;
197 if (ch == EOF)
198 return ((char *)EOF);
199 return (line);
200 }
201
202 /*
203 * prepend the path to a filename
204 */
205 char *
206 path(const char *file)
207 {
208 char *cp;
209
210 cp = malloc((unsigned)(strlen(build_directory)+
211 strlen(file)+
212 strlen(object_directory)+
213 3));
214 (void) sprintf(cp, "%s/%s/%s", object_directory, build_directory, file);
215 return (cp);
216 }