1*1031c584SApple OSS Distributions /*
2*1031c584SApple OSS Distributions * Copyright (c) 1999-2009 Apple Inc. All rights reserved.
3*1031c584SApple OSS Distributions *
4*1031c584SApple OSS Distributions * @APPLE_LICENSE_HEADER_START@
5*1031c584SApple OSS Distributions *
6*1031c584SApple OSS Distributions * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7*1031c584SApple OSS Distributions * Reserved. This file contains Original Code and/or Modifications of
8*1031c584SApple OSS Distributions * Original Code as defined in and that are subject to the Apple Public
9*1031c584SApple OSS Distributions * Source License Version 1.0 (the 'License'). You may not use this file
10*1031c584SApple OSS Distributions * except in compliance with the License. Please obtain a copy of the
11*1031c584SApple OSS Distributions * License at http://www.apple.com/publicsource and read it before using
12*1031c584SApple OSS Distributions * this file.
13*1031c584SApple OSS Distributions *
14*1031c584SApple OSS Distributions * The Original Code and all software distributed under the License are
15*1031c584SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16*1031c584SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17*1031c584SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18*1031c584SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19*1031c584SApple OSS Distributions * License for the specific language governing rights and limitations
20*1031c584SApple OSS Distributions * under the License."
21*1031c584SApple OSS Distributions *
22*1031c584SApple OSS Distributions * @APPLE_LICENSE_HEADER_END@
23*1031c584SApple OSS Distributions */
24*1031c584SApple OSS Distributions /*
25*1031c584SApple OSS Distributions * Mach Operating System
26*1031c584SApple OSS Distributions * Copyright (c) 1990 Carnegie-Mellon University
27*1031c584SApple OSS Distributions * Copyright (c) 1989 Carnegie-Mellon University
28*1031c584SApple OSS Distributions * Copyright (c) 1988 Carnegie-Mellon University
29*1031c584SApple OSS Distributions * Copyright (c) 1987 Carnegie-Mellon University
30*1031c584SApple OSS Distributions * All rights reserved. The CMU software License Agreement specifies
31*1031c584SApple OSS Distributions * the terms and conditions for use and redistribution.
32*1031c584SApple OSS Distributions */
33*1031c584SApple OSS Distributions
34*1031c584SApple OSS Distributions /*
35*1031c584SApple OSS Distributions * Copyright (c) 1980 Regents of the University of California.
36*1031c584SApple OSS Distributions * All rights reserved.
37*1031c584SApple OSS Distributions *
38*1031c584SApple OSS Distributions * Redistribution and use in source and binary forms are permitted
39*1031c584SApple OSS Distributions * provided that the above copyright notice and this paragraph are
40*1031c584SApple OSS Distributions * duplicated in all such forms and that any documentation,
41*1031c584SApple OSS Distributions * advertising materials, and other materials related to such
42*1031c584SApple OSS Distributions * distribution and use acknowledge that the software was developed
43*1031c584SApple OSS Distributions * by the University of California, Berkeley. The name of the
44*1031c584SApple OSS Distributions * University may not be used to endorse or promote products derived
45*1031c584SApple OSS Distributions * from this software without specific prior written permission.
46*1031c584SApple OSS Distributions * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
47*1031c584SApple OSS Distributions * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
48*1031c584SApple OSS Distributions * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
49*1031c584SApple OSS Distributions */
50*1031c584SApple OSS Distributions
51*1031c584SApple OSS Distributions #ifndef lint
52*1031c584SApple OSS Distributions char copyright[] =
53*1031c584SApple OSS Distributions "@(#) Copyright (c) 1980 Regents of the University of California.\n\
54*1031c584SApple OSS Distributions All rights reserved.\n";
55*1031c584SApple OSS Distributions #endif /* not lint */
56*1031c584SApple OSS Distributions
57*1031c584SApple OSS Distributions #ifndef lint
58*1031c584SApple OSS Distributions static char sccsid[] __attribute__((used)) = "@(#)main.c 5.9 (Berkeley) 6/18/88";
59*1031c584SApple OSS Distributions #endif /* not lint */
60*1031c584SApple OSS Distributions
61*1031c584SApple OSS Distributions #include <stdio.h>
62*1031c584SApple OSS Distributions #include <ctype.h>
63*1031c584SApple OSS Distributions #include "parser.h"
64*1031c584SApple OSS Distributions #include "config.h"
65*1031c584SApple OSS Distributions
66*1031c584SApple OSS Distributions /*
67*1031c584SApple OSS Distributions * Config builds a set of files for building a UNIX
68*1031c584SApple OSS Distributions * system given a description of the desired system.
69*1031c584SApple OSS Distributions */
70*1031c584SApple OSS Distributions int
main(int argc,char * argv[])71*1031c584SApple OSS Distributions main(int argc, char *argv[])
72*1031c584SApple OSS Distributions {
73*1031c584SApple OSS Distributions source_directory = ".."; /* default */
74*1031c584SApple OSS Distributions object_directory = "..";
75*1031c584SApple OSS Distributions config_directory = (char *) 0;
76*1031c584SApple OSS Distributions while ((argc > 1) && (argv[1][0] == '-')) {
77*1031c584SApple OSS Distributions char *c;
78*1031c584SApple OSS Distributions
79*1031c584SApple OSS Distributions argv++; argc--;
80*1031c584SApple OSS Distributions for (c = &argv[0][1]; *c; c++) {
81*1031c584SApple OSS Distributions switch (*c) {
82*1031c584SApple OSS Distributions case 'b':
83*1031c584SApple OSS Distributions build_directory = argv[1];
84*1031c584SApple OSS Distributions goto check_arg;
85*1031c584SApple OSS Distributions
86*1031c584SApple OSS Distributions case 'd':
87*1031c584SApple OSS Distributions source_directory = argv[1];
88*1031c584SApple OSS Distributions goto check_arg;
89*1031c584SApple OSS Distributions
90*1031c584SApple OSS Distributions case 'o':
91*1031c584SApple OSS Distributions object_directory = argv[1];
92*1031c584SApple OSS Distributions goto check_arg;
93*1031c584SApple OSS Distributions
94*1031c584SApple OSS Distributions case 'c':
95*1031c584SApple OSS Distributions config_directory = argv[1];
96*1031c584SApple OSS Distributions
97*1031c584SApple OSS Distributions check_arg:
98*1031c584SApple OSS Distributions if (argv[1] == (char *) 0) {
99*1031c584SApple OSS Distributions goto usage_error;
100*1031c584SApple OSS Distributions }
101*1031c584SApple OSS Distributions argv++; argc--;
102*1031c584SApple OSS Distributions break;
103*1031c584SApple OSS Distributions
104*1031c584SApple OSS Distributions case 'p':
105*1031c584SApple OSS Distributions profiling++;
106*1031c584SApple OSS Distributions break;
107*1031c584SApple OSS Distributions default:
108*1031c584SApple OSS Distributions goto usage_error;
109*1031c584SApple OSS Distributions }
110*1031c584SApple OSS Distributions }
111*1031c584SApple OSS Distributions }
112*1031c584SApple OSS Distributions if (config_directory == (char *) 0) {
113*1031c584SApple OSS Distributions config_directory =
114*1031c584SApple OSS Distributions malloc((unsigned) strlen(source_directory) + 6);
115*1031c584SApple OSS Distributions (void) sprintf(config_directory, "%s/conf", source_directory);
116*1031c584SApple OSS Distributions }
117*1031c584SApple OSS Distributions if (argc != 2) {
118*1031c584SApple OSS Distributions usage_error: ;
119*1031c584SApple OSS Distributions fprintf(stderr, "usage: config [ -bcdo dir ] [ -p ] sysname\n");
120*1031c584SApple OSS Distributions exit(1);
121*1031c584SApple OSS Distributions }
122*1031c584SApple OSS Distributions if (!build_directory) {
123*1031c584SApple OSS Distributions build_directory = argv[1];
124*1031c584SApple OSS Distributions }
125*1031c584SApple OSS Distributions if (freopen(argv[1], "r", stdin) == NULL) {
126*1031c584SApple OSS Distributions perror(argv[1]);
127*1031c584SApple OSS Distributions exit(2);
128*1031c584SApple OSS Distributions }
129*1031c584SApple OSS Distributions dtab = NULL;
130*1031c584SApple OSS Distributions confp = &conf_list;
131*1031c584SApple OSS Distributions opt = 0;
132*1031c584SApple OSS Distributions if (yyparse()) {
133*1031c584SApple OSS Distributions exit(3);
134*1031c584SApple OSS Distributions }
135*1031c584SApple OSS Distributions
136*1031c584SApple OSS Distributions mkioconf(); /* ioconf.c */
137*1031c584SApple OSS Distributions makefile(); /* build Makefile */
138*1031c584SApple OSS Distributions headers(); /* make a lot of .h files */
139*1031c584SApple OSS Distributions
140*1031c584SApple OSS Distributions return 0;
141*1031c584SApple OSS Distributions }
142*1031c584SApple OSS Distributions
143*1031c584SApple OSS Distributions /*
144*1031c584SApple OSS Distributions * get_word
145*1031c584SApple OSS Distributions * returns EOF on end of file
146*1031c584SApple OSS Distributions * NULL on end of line
147*1031c584SApple OSS Distributions * pointer to the word otherwise
148*1031c584SApple OSS Distributions */
149*1031c584SApple OSS Distributions const char *
get_word(FILE * fp)150*1031c584SApple OSS Distributions get_word(FILE *fp)
151*1031c584SApple OSS Distributions {
152*1031c584SApple OSS Distributions static char line[80];
153*1031c584SApple OSS Distributions int ch;
154*1031c584SApple OSS Distributions char *cp;
155*1031c584SApple OSS Distributions
156*1031c584SApple OSS Distributions while ((ch = getc(fp)) != EOF) {
157*1031c584SApple OSS Distributions if (ch != ' ' && ch != '\t') {
158*1031c584SApple OSS Distributions break;
159*1031c584SApple OSS Distributions }
160*1031c584SApple OSS Distributions }
161*1031c584SApple OSS Distributions if (ch == EOF) {
162*1031c584SApple OSS Distributions return (char *)EOF;
163*1031c584SApple OSS Distributions }
164*1031c584SApple OSS Distributions if (ch == '\n') {
165*1031c584SApple OSS Distributions return NULL;
166*1031c584SApple OSS Distributions }
167*1031c584SApple OSS Distributions if (ch == '|') {
168*1031c584SApple OSS Distributions return "|";
169*1031c584SApple OSS Distributions }
170*1031c584SApple OSS Distributions cp = line;
171*1031c584SApple OSS Distributions *cp++ = ch;
172*1031c584SApple OSS Distributions while ((ch = getc(fp)) != EOF) {
173*1031c584SApple OSS Distributions if (isspace(ch)) {
174*1031c584SApple OSS Distributions break;
175*1031c584SApple OSS Distributions }
176*1031c584SApple OSS Distributions *cp++ = ch;
177*1031c584SApple OSS Distributions }
178*1031c584SApple OSS Distributions *cp = 0;
179*1031c584SApple OSS Distributions if (ch == EOF) {
180*1031c584SApple OSS Distributions return (char *)EOF;
181*1031c584SApple OSS Distributions }
182*1031c584SApple OSS Distributions (void) ungetc(ch, fp);
183*1031c584SApple OSS Distributions return line;
184*1031c584SApple OSS Distributions }
185*1031c584SApple OSS Distributions
186*1031c584SApple OSS Distributions /*
187*1031c584SApple OSS Distributions * get_rest
188*1031c584SApple OSS Distributions * returns EOF on end of file
189*1031c584SApple OSS Distributions * NULL on end of line
190*1031c584SApple OSS Distributions * pointer to the word otherwise
191*1031c584SApple OSS Distributions */
192*1031c584SApple OSS Distributions char *
get_rest(FILE * fp)193*1031c584SApple OSS Distributions get_rest(FILE *fp)
194*1031c584SApple OSS Distributions {
195*1031c584SApple OSS Distributions static char line[80];
196*1031c584SApple OSS Distributions int ch;
197*1031c584SApple OSS Distributions char *cp;
198*1031c584SApple OSS Distributions
199*1031c584SApple OSS Distributions cp = line;
200*1031c584SApple OSS Distributions while ((ch = getc(fp)) != EOF) {
201*1031c584SApple OSS Distributions if (ch == '\n') {
202*1031c584SApple OSS Distributions break;
203*1031c584SApple OSS Distributions }
204*1031c584SApple OSS Distributions *cp++ = ch;
205*1031c584SApple OSS Distributions }
206*1031c584SApple OSS Distributions *cp = 0;
207*1031c584SApple OSS Distributions if (ch == EOF) {
208*1031c584SApple OSS Distributions return (char *)EOF;
209*1031c584SApple OSS Distributions }
210*1031c584SApple OSS Distributions return line;
211*1031c584SApple OSS Distributions }
212*1031c584SApple OSS Distributions
213*1031c584SApple OSS Distributions /*
214*1031c584SApple OSS Distributions * prepend the path to a filename
215*1031c584SApple OSS Distributions */
216*1031c584SApple OSS Distributions char *
path(const char * file)217*1031c584SApple OSS Distributions path(const char *file)
218*1031c584SApple OSS Distributions {
219*1031c584SApple OSS Distributions char *cp;
220*1031c584SApple OSS Distributions
221*1031c584SApple OSS Distributions cp = malloc((unsigned)(strlen(build_directory) +
222*1031c584SApple OSS Distributions strlen(file) +
223*1031c584SApple OSS Distributions strlen(object_directory) +
224*1031c584SApple OSS Distributions 3));
225*1031c584SApple OSS Distributions (void) sprintf(cp, "%s/%s/%s", object_directory, build_directory, file);
226*1031c584SApple OSS Distributions return cp;
227*1031c584SApple OSS Distributions }
228