xref: /xnu-10002.1.13/SETUP/config/mkmakefile.c (revision 1031c584a5e37aff177559b9f69dbd3c8c3fd30a)
1*1031c584SApple OSS Distributions /*
2*1031c584SApple OSS Distributions  * Copyright (c) 1999-2016 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 static char sccsid[] __attribute__((used)) = "@(#)mkmakefile.c	5.21 (Berkeley) 6/18/88";
53*1031c584SApple OSS Distributions #endif /* not lint */
54*1031c584SApple OSS Distributions 
55*1031c584SApple OSS Distributions /*
56*1031c584SApple OSS Distributions  * Build the makefile for the system, from
57*1031c584SApple OSS Distributions  * the information in the files files and the
58*1031c584SApple OSS Distributions  * additional files for the machine being compiled to.
59*1031c584SApple OSS Distributions  */
60*1031c584SApple OSS Distributions 
61*1031c584SApple OSS Distributions #include <stdio.h>
62*1031c584SApple OSS Distributions #include <unistd.h>     /* for unlink */
63*1031c584SApple OSS Distributions #include <ctype.h>
64*1031c584SApple OSS Distributions #include "parser.h"
65*1031c584SApple OSS Distributions #include "config.h"
66*1031c584SApple OSS Distributions 
67*1031c584SApple OSS Distributions void    read_files(void);
68*1031c584SApple OSS Distributions void    do_objs(FILE *fp, const char *msg, int ext, int flags);
69*1031c584SApple OSS Distributions void    do_files(FILE *fp, const char *msg, char ext);
70*1031c584SApple OSS Distributions void    do_machdep(FILE *ofp);
71*1031c584SApple OSS Distributions void    do_rules(FILE *f);
72*1031c584SApple OSS Distributions void    copy_dependencies(FILE *makin, FILE *makout);
73*1031c584SApple OSS Distributions 
74*1031c584SApple OSS Distributions struct file_list *fl_lookup(char *file);
75*1031c584SApple OSS Distributions struct file_list *fltail_lookup(char *file);
76*1031c584SApple OSS Distributions struct file_list *new_fent(void);
77*1031c584SApple OSS Distributions 
78*1031c584SApple OSS Distributions void    put_source_file_name(FILE *fp, struct file_list *tp);
79*1031c584SApple OSS Distributions 
80*1031c584SApple OSS Distributions 
81*1031c584SApple OSS Distributions #define next_word(fp, wd) \
82*1031c584SApple OSS Distributions 	{ const char *word = get_word(fp); \
83*1031c584SApple OSS Distributions 	  if (word == (char *)EOF) \
84*1031c584SApple OSS Distributions 	        return; \
85*1031c584SApple OSS Distributions 	  else \
86*1031c584SApple OSS Distributions 	        wd = word; \
87*1031c584SApple OSS Distributions 	}
88*1031c584SApple OSS Distributions 
89*1031c584SApple OSS Distributions static  struct file_list *fcur;
90*1031c584SApple OSS Distributions const char *tail(const char *fn);
91*1031c584SApple OSS Distributions char *allCaps(char *str);
92*1031c584SApple OSS Distributions 
93*1031c584SApple OSS Distributions /*
94*1031c584SApple OSS Distributions  * Lookup a file, by name.
95*1031c584SApple OSS Distributions  */
96*1031c584SApple OSS Distributions struct file_list *
fl_lookup(char * file)97*1031c584SApple OSS Distributions fl_lookup(char *file)
98*1031c584SApple OSS Distributions {
99*1031c584SApple OSS Distributions 	struct file_list *fp;
100*1031c584SApple OSS Distributions 
101*1031c584SApple OSS Distributions 	for (fp = ftab; fp != 0; fp = fp->f_next) {
102*1031c584SApple OSS Distributions 		if (eq(fp->f_fn, file)) {
103*1031c584SApple OSS Distributions 			return fp;
104*1031c584SApple OSS Distributions 		}
105*1031c584SApple OSS Distributions 	}
106*1031c584SApple OSS Distributions 	return 0;
107*1031c584SApple OSS Distributions }
108*1031c584SApple OSS Distributions 
109*1031c584SApple OSS Distributions /*
110*1031c584SApple OSS Distributions  * Lookup a file, by final component name.
111*1031c584SApple OSS Distributions  */
112*1031c584SApple OSS Distributions struct file_list *
fltail_lookup(char * file)113*1031c584SApple OSS Distributions fltail_lookup(char *file)
114*1031c584SApple OSS Distributions {
115*1031c584SApple OSS Distributions 	struct file_list *fp;
116*1031c584SApple OSS Distributions 
117*1031c584SApple OSS Distributions 	for (fp = ftab; fp != 0; fp = fp->f_next) {
118*1031c584SApple OSS Distributions 		if (eq(tail(fp->f_fn), tail(file))) {
119*1031c584SApple OSS Distributions 			return fp;
120*1031c584SApple OSS Distributions 		}
121*1031c584SApple OSS Distributions 	}
122*1031c584SApple OSS Distributions 	return 0;
123*1031c584SApple OSS Distributions }
124*1031c584SApple OSS Distributions 
125*1031c584SApple OSS Distributions /*
126*1031c584SApple OSS Distributions  * Make a new file list entry
127*1031c584SApple OSS Distributions  */
128*1031c584SApple OSS Distributions struct file_list *
new_fent(void)129*1031c584SApple OSS Distributions new_fent(void)
130*1031c584SApple OSS Distributions {
131*1031c584SApple OSS Distributions 	struct file_list *fp;
132*1031c584SApple OSS Distributions 
133*1031c584SApple OSS Distributions 	fp = (struct file_list *) malloc(sizeof *fp);
134*1031c584SApple OSS Distributions 	fp->f_needs = 0;
135*1031c584SApple OSS Distributions 	fp->f_next = 0;
136*1031c584SApple OSS Distributions 	fp->f_flags = 0;
137*1031c584SApple OSS Distributions 	fp->f_type = 0;
138*1031c584SApple OSS Distributions 	fp->f_extra = (char *) 0;
139*1031c584SApple OSS Distributions 	if (fcur == 0) {
140*1031c584SApple OSS Distributions 		fcur = ftab = fp;
141*1031c584SApple OSS Distributions 	} else {
142*1031c584SApple OSS Distributions 		fcur->f_next = fp;
143*1031c584SApple OSS Distributions 	}
144*1031c584SApple OSS Distributions 	fcur = fp;
145*1031c584SApple OSS Distributions 	return fp;
146*1031c584SApple OSS Distributions }
147*1031c584SApple OSS Distributions 
148*1031c584SApple OSS Distributions char    *COPTS;
149*1031c584SApple OSS Distributions 
150*1031c584SApple OSS Distributions const char *
get_VPATH(void)151*1031c584SApple OSS Distributions get_VPATH(void)
152*1031c584SApple OSS Distributions {
153*1031c584SApple OSS Distributions 	static char *vpath = NULL;
154*1031c584SApple OSS Distributions 
155*1031c584SApple OSS Distributions 	if ((vpath == NULL) &&
156*1031c584SApple OSS Distributions 	    ((vpath = getenv("VPATH")) != NULL) &&
157*1031c584SApple OSS Distributions 	    (*vpath != ':')) {
158*1031c584SApple OSS Distributions 		char *buf = malloc((unsigned)(strlen(vpath) + 2));
159*1031c584SApple OSS Distributions 
160*1031c584SApple OSS Distributions 		vpath = strcat(strcpy(buf, ":"), vpath);
161*1031c584SApple OSS Distributions 	}
162*1031c584SApple OSS Distributions 
163*1031c584SApple OSS Distributions 	return vpath ? vpath : "";
164*1031c584SApple OSS Distributions }
165*1031c584SApple OSS Distributions 
166*1031c584SApple OSS Distributions 
167*1031c584SApple OSS Distributions /*
168*1031c584SApple OSS Distributions  * Build the makefile from the skeleton
169*1031c584SApple OSS Distributions  */
170*1031c584SApple OSS Distributions void
makefile(void)171*1031c584SApple OSS Distributions makefile(void)
172*1031c584SApple OSS Distributions {
173*1031c584SApple OSS Distributions 	FILE *ifp, *ofp;
174*1031c584SApple OSS Distributions 	FILE *dfp;
175*1031c584SApple OSS Distributions 	char pname[BUFSIZ];
176*1031c584SApple OSS Distributions 	char line[BUFSIZ];
177*1031c584SApple OSS Distributions 	struct opt *op;
178*1031c584SApple OSS Distributions 
179*1031c584SApple OSS Distributions 	read_files();
180*1031c584SApple OSS Distributions 	(void) sprintf(line, "%s/Makefile.template", config_directory);
181*1031c584SApple OSS Distributions 	ifp = fopenp(VPATH, line, pname, "r");
182*1031c584SApple OSS Distributions 	if (ifp == 0) {
183*1031c584SApple OSS Distributions 		perror(line);
184*1031c584SApple OSS Distributions 		exit(1);
185*1031c584SApple OSS Distributions 	}
186*1031c584SApple OSS Distributions 	dfp = fopen(path("Makefile"), "r");
187*1031c584SApple OSS Distributions 	rename(path("Makefile"), path("Makefile.old"));
188*1031c584SApple OSS Distributions 	unlink(path("Makefile.old"));
189*1031c584SApple OSS Distributions 	ofp = fopen(path("Makefile"), "w");
190*1031c584SApple OSS Distributions 	if (ofp == 0) {
191*1031c584SApple OSS Distributions 		perror(path("Makefile"));
192*1031c584SApple OSS Distributions 		exit(1);
193*1031c584SApple OSS Distributions 	}
194*1031c584SApple OSS Distributions 	fprintf(ofp, "SOURCE_DIR=%s\n", source_directory);
195*1031c584SApple OSS Distributions 
196*1031c584SApple OSS Distributions 	fprintf(ofp, "export CONFIG_DEFINES =");
197*1031c584SApple OSS Distributions 	if (profiling) {
198*1031c584SApple OSS Distributions 		fprintf(ofp, " -DGPROF");
199*1031c584SApple OSS Distributions 	}
200*1031c584SApple OSS Distributions 
201*1031c584SApple OSS Distributions 	for (op = opt; op; op = op->op_next) {
202*1031c584SApple OSS Distributions 		if (op->op_value) {
203*1031c584SApple OSS Distributions 			fprintf(ofp, " -D%s=\"%s\"", op->op_name, op->op_value);
204*1031c584SApple OSS Distributions 		} else {
205*1031c584SApple OSS Distributions 			fprintf(ofp, " -D%s", op->op_name);
206*1031c584SApple OSS Distributions 		}
207*1031c584SApple OSS Distributions 	}
208*1031c584SApple OSS Distributions 	fprintf(ofp, "\n");
209*1031c584SApple OSS Distributions 	for (op = mkopt; op; op = op->op_next) {
210*1031c584SApple OSS Distributions 		if (op->op_value) {
211*1031c584SApple OSS Distributions 			fprintf(ofp, "%s=%s\n", op->op_name, op->op_value);
212*1031c584SApple OSS Distributions 		} else {
213*1031c584SApple OSS Distributions 			fprintf(ofp, "%s\n", op->op_name);
214*1031c584SApple OSS Distributions 		}
215*1031c584SApple OSS Distributions 	}
216*1031c584SApple OSS Distributions 
217*1031c584SApple OSS Distributions 	while (fgets(line, BUFSIZ, ifp) != 0) {
218*1031c584SApple OSS Distributions 		if (*line == '%') {
219*1031c584SApple OSS Distributions 			goto percent;
220*1031c584SApple OSS Distributions 		}
221*1031c584SApple OSS Distributions 		if (profiling && strncmp(line, "COPTS=", 6) == 0) {
222*1031c584SApple OSS Distributions 			char *cp;
223*1031c584SApple OSS Distributions 			fprintf(ofp,
224*1031c584SApple OSS Distributions 			    "GPROF.EX=$(SOURCE_DIR)/machdep/%s/gmon.ex\n", machinename);
225*1031c584SApple OSS Distributions 			cp = index(line, '\n');
226*1031c584SApple OSS Distributions 			if (cp) {
227*1031c584SApple OSS Distributions 				*cp = 0;
228*1031c584SApple OSS Distributions 			}
229*1031c584SApple OSS Distributions 			cp = line + 6;
230*1031c584SApple OSS Distributions 			while (*cp && (*cp == ' ' || *cp == '\t')) {
231*1031c584SApple OSS Distributions 				cp++;
232*1031c584SApple OSS Distributions 			}
233*1031c584SApple OSS Distributions 			COPTS = malloc((unsigned)(strlen(cp) + 1));
234*1031c584SApple OSS Distributions 			if (COPTS == 0) {
235*1031c584SApple OSS Distributions 				printf("config: out of memory\n");
236*1031c584SApple OSS Distributions 				exit(1);
237*1031c584SApple OSS Distributions 			}
238*1031c584SApple OSS Distributions 			strcpy(COPTS, cp);
239*1031c584SApple OSS Distributions 			fprintf(ofp, "%s -pg\n", line);
240*1031c584SApple OSS Distributions 			continue;
241*1031c584SApple OSS Distributions 		}
242*1031c584SApple OSS Distributions 		fprintf(ofp, "%s", line);
243*1031c584SApple OSS Distributions 		continue;
244*1031c584SApple OSS Distributions percent:
245*1031c584SApple OSS Distributions 		if (eq(line, "%OBJS\n")) {
246*1031c584SApple OSS Distributions 			do_objs(ofp, "OBJS=", -1, 0);
247*1031c584SApple OSS Distributions 		} else if (eq(line, "%LIBOBJS\n")) {
248*1031c584SApple OSS Distributions 			do_objs(ofp, "LIBOBJS=", -1, LIBRARYDEP);
249*1031c584SApple OSS Distributions 		} else if (eq(line, "%CFILES\n")) {
250*1031c584SApple OSS Distributions 			do_files(ofp, "CFILES=", 'c');
251*1031c584SApple OSS Distributions 			do_objs(ofp, "COBJS=", 'c', 0);
252*1031c584SApple OSS Distributions 		} else if (eq(line, "%CXXFILES\n")) {
253*1031c584SApple OSS Distributions 			do_files(ofp, "CXXFILES=", 'p');
254*1031c584SApple OSS Distributions 			do_objs(ofp, "CXXOBJS=", 'p', 0);
255*1031c584SApple OSS Distributions 		} else if (eq(line, "%SFILES\n")) {
256*1031c584SApple OSS Distributions 			do_files(ofp, "SFILES=", 's');
257*1031c584SApple OSS Distributions 			do_objs(ofp, "SOBJS=", 's', 0);
258*1031c584SApple OSS Distributions 		} else if (eq(line, "%MACHDEP\n")) {
259*1031c584SApple OSS Distributions 			do_machdep(ofp);
260*1031c584SApple OSS Distributions 		} else if (eq(line, "%RULES\n")) {
261*1031c584SApple OSS Distributions 			do_rules(ofp);
262*1031c584SApple OSS Distributions 		} else {
263*1031c584SApple OSS Distributions 			fprintf(stderr,
264*1031c584SApple OSS Distributions 			    "Unknown %% construct in generic makefile: %s",
265*1031c584SApple OSS Distributions 			    line);
266*1031c584SApple OSS Distributions 		}
267*1031c584SApple OSS Distributions 	}
268*1031c584SApple OSS Distributions 	if (dfp != NULL) {
269*1031c584SApple OSS Distributions 		copy_dependencies(dfp, ofp);
270*1031c584SApple OSS Distributions 		(void) fclose(dfp);
271*1031c584SApple OSS Distributions 	}
272*1031c584SApple OSS Distributions 	(void) fclose(ifp);
273*1031c584SApple OSS Distributions 	(void) fclose(ofp);
274*1031c584SApple OSS Distributions }
275*1031c584SApple OSS Distributions 
276*1031c584SApple OSS Distributions /*
277*1031c584SApple OSS Distributions  * Read in the information about files used in making the system.
278*1031c584SApple OSS Distributions  * Store it in the ftab linked list.
279*1031c584SApple OSS Distributions  */
280*1031c584SApple OSS Distributions void
read_files(void)281*1031c584SApple OSS Distributions read_files(void)
282*1031c584SApple OSS Distributions {
283*1031c584SApple OSS Distributions 	FILE *fp;
284*1031c584SApple OSS Distributions 	struct file_list *tp, *pf;
285*1031c584SApple OSS Distributions 	struct device *dp;
286*1031c584SApple OSS Distributions 	struct opt *op;
287*1031c584SApple OSS Distributions 	const char *wd;
288*1031c584SApple OSS Distributions 	char *this, *needs;
289*1031c584SApple OSS Distributions 	const char *devorprof;
290*1031c584SApple OSS Distributions 	int options;
291*1031c584SApple OSS Distributions 	int not_option;
292*1031c584SApple OSS Distributions 	int f_flags;
293*1031c584SApple OSS Distributions 	char pname[BUFSIZ];
294*1031c584SApple OSS Distributions 	char fname[1024];
295*1031c584SApple OSS Distributions 	char *rest = (char *) 0;
296*1031c584SApple OSS Distributions 	int nreqs, first = 1, isdup;
297*1031c584SApple OSS Distributions 
298*1031c584SApple OSS Distributions 	ftab = 0;
299*1031c584SApple OSS Distributions 	(void) sprintf(fname, "%s/files", config_directory);
300*1031c584SApple OSS Distributions openit:
301*1031c584SApple OSS Distributions 	fp = fopenp(VPATH, fname, pname, "r");
302*1031c584SApple OSS Distributions 	if (fp == 0) {
303*1031c584SApple OSS Distributions 		perror(fname);
304*1031c584SApple OSS Distributions 		exit(1);
305*1031c584SApple OSS Distributions 	}
306*1031c584SApple OSS Distributions next:
307*1031c584SApple OSS Distributions 	options = 0;
308*1031c584SApple OSS Distributions 	rest = (char *) 0;
309*1031c584SApple OSS Distributions 	/*
310*1031c584SApple OSS Distributions 	 * filename	[ standard | optional ]
311*1031c584SApple OSS Distributions 	 *	[ dev* | profiling-routine ] [ device-driver]
312*1031c584SApple OSS Distributions 	 */
313*1031c584SApple OSS Distributions 	wd = get_word(fp);
314*1031c584SApple OSS Distributions 	if (wd == (char *)EOF) {
315*1031c584SApple OSS Distributions 		(void) fclose(fp);
316*1031c584SApple OSS Distributions 		if (first == 1) {
317*1031c584SApple OSS Distributions 			(void) sprintf(fname, "%s/files.%s", config_directory, machinename);
318*1031c584SApple OSS Distributions 			first++;
319*1031c584SApple OSS Distributions 			goto openit;
320*1031c584SApple OSS Distributions 		}
321*1031c584SApple OSS Distributions 		return;
322*1031c584SApple OSS Distributions 	}
323*1031c584SApple OSS Distributions 	if (wd == 0) {
324*1031c584SApple OSS Distributions 		goto next;
325*1031c584SApple OSS Distributions 	}
326*1031c584SApple OSS Distributions 	/*
327*1031c584SApple OSS Distributions 	 *  Allow comment lines beginning witha '#' character.
328*1031c584SApple OSS Distributions 	 */
329*1031c584SApple OSS Distributions 	if (*wd == '#') {
330*1031c584SApple OSS Distributions 		while ((wd = get_word(fp)) && wd != (char *)EOF) {
331*1031c584SApple OSS Distributions 			;
332*1031c584SApple OSS Distributions 		}
333*1031c584SApple OSS Distributions 		goto next;
334*1031c584SApple OSS Distributions 	}
335*1031c584SApple OSS Distributions 
336*1031c584SApple OSS Distributions 	this = ns(wd);
337*1031c584SApple OSS Distributions 	next_word(fp, wd);
338*1031c584SApple OSS Distributions 	if (wd == 0) {
339*1031c584SApple OSS Distributions 		printf("%s: No type for %s.\n",
340*1031c584SApple OSS Distributions 		    fname, this);
341*1031c584SApple OSS Distributions 		exit(1);
342*1031c584SApple OSS Distributions 	}
343*1031c584SApple OSS Distributions 	if ((pf = fl_lookup(this)) && (pf->f_type != INVISIBLE || pf->f_flags)) {
344*1031c584SApple OSS Distributions 		isdup = 1;
345*1031c584SApple OSS Distributions 	} else {
346*1031c584SApple OSS Distributions 		isdup = 0;
347*1031c584SApple OSS Distributions 	}
348*1031c584SApple OSS Distributions 	tp = 0;
349*1031c584SApple OSS Distributions 	nreqs = 0;
350*1031c584SApple OSS Distributions 	devorprof = "";
351*1031c584SApple OSS Distributions 	needs = 0;
352*1031c584SApple OSS Distributions 	f_flags = 0;
353*1031c584SApple OSS Distributions 	if (eq(wd, "standard")) {
354*1031c584SApple OSS Distributions 		goto checkdev;
355*1031c584SApple OSS Distributions 	}
356*1031c584SApple OSS Distributions 	if (!eq(wd, "optional")) {
357*1031c584SApple OSS Distributions 		printf("%s: %s must be optional or standard\n", fname, this);
358*1031c584SApple OSS Distributions 		exit(1);
359*1031c584SApple OSS Distributions 	}
360*1031c584SApple OSS Distributions 	if (strncmp(this, "OPTIONS/", 8) == 0) {
361*1031c584SApple OSS Distributions 		options++;
362*1031c584SApple OSS Distributions 	}
363*1031c584SApple OSS Distributions 	not_option = 0;
364*1031c584SApple OSS Distributions nextopt:
365*1031c584SApple OSS Distributions 	next_word(fp, wd);
366*1031c584SApple OSS Distributions 	if (wd == 0) {
367*1031c584SApple OSS Distributions 		goto doneopt;
368*1031c584SApple OSS Distributions 	}
369*1031c584SApple OSS Distributions 	if (eq(wd, "not")) {
370*1031c584SApple OSS Distributions 		not_option = !not_option;
371*1031c584SApple OSS Distributions 		goto nextopt;
372*1031c584SApple OSS Distributions 	}
373*1031c584SApple OSS Distributions 	devorprof = wd;
374*1031c584SApple OSS Distributions 	if (eq(wd, "device-driver") || eq(wd, "profiling-routine")) {
375*1031c584SApple OSS Distributions 		next_word(fp, wd);
376*1031c584SApple OSS Distributions 		goto save;
377*1031c584SApple OSS Distributions 	}
378*1031c584SApple OSS Distributions 	if (eq(wd, "xnu-library")) {
379*1031c584SApple OSS Distributions 		f_flags |= LIBRARYDEP;
380*1031c584SApple OSS Distributions 		goto nextopt;
381*1031c584SApple OSS Distributions 	}
382*1031c584SApple OSS Distributions 	if (eq(wd, "bound-checks")) {
383*1031c584SApple OSS Distributions 		f_flags |= BOUND_CHECKS;
384*1031c584SApple OSS Distributions 		goto nextopt;
385*1031c584SApple OSS Distributions 	}
386*1031c584SApple OSS Distributions 	if (eq(wd, "bound-checks-soft")) {
387*1031c584SApple OSS Distributions 		f_flags |= BOUND_CHECKS_SOFT;
388*1031c584SApple OSS Distributions 		goto nextopt;
389*1031c584SApple OSS Distributions 	}
390*1031c584SApple OSS Distributions 	nreqs++;
391*1031c584SApple OSS Distributions 	if (needs == 0 && nreqs == 1) {
392*1031c584SApple OSS Distributions 		needs = ns(wd);
393*1031c584SApple OSS Distributions 	}
394*1031c584SApple OSS Distributions 	if (isdup) {
395*1031c584SApple OSS Distributions 		goto invis;
396*1031c584SApple OSS Distributions 	}
397*1031c584SApple OSS Distributions 	if (options) {
398*1031c584SApple OSS Distributions 		struct opt *lop = 0;
399*1031c584SApple OSS Distributions 		struct device tdev;
400*1031c584SApple OSS Distributions 
401*1031c584SApple OSS Distributions 		/*
402*1031c584SApple OSS Distributions 		 *  Allocate a pseudo-device entry which we will insert into
403*1031c584SApple OSS Distributions 		 *  the device list below.  The flags field is set non-zero to
404*1031c584SApple OSS Distributions 		 *  indicate an internal entry rather than one generated from
405*1031c584SApple OSS Distributions 		 *  the configuration file.  The slave field is set to define
406*1031c584SApple OSS Distributions 		 *  the corresponding symbol as 0 should we fail to find the
407*1031c584SApple OSS Distributions 		 *  option in the option list.
408*1031c584SApple OSS Distributions 		 */
409*1031c584SApple OSS Distributions 		init_dev(&tdev);
410*1031c584SApple OSS Distributions 		tdev.d_name = ns(wd);
411*1031c584SApple OSS Distributions 		tdev.d_type = PSEUDO_DEVICE;
412*1031c584SApple OSS Distributions 		tdev.d_flags++;
413*1031c584SApple OSS Distributions 		tdev.d_slave = 0;
414*1031c584SApple OSS Distributions 
415*1031c584SApple OSS Distributions 		for (op = opt; op; lop = op, op = op->op_next) {
416*1031c584SApple OSS Distributions 			char *od = allCaps(ns(wd));
417*1031c584SApple OSS Distributions 
418*1031c584SApple OSS Distributions 			/*
419*1031c584SApple OSS Distributions 			 *  Found an option which matches the current device
420*1031c584SApple OSS Distributions 			 *  dependency identifier.  Set the slave field to
421*1031c584SApple OSS Distributions 			 *  define the option in the header file.
422*1031c584SApple OSS Distributions 			 */
423*1031c584SApple OSS Distributions 			if (strcmp(op->op_name, od) == 0) {
424*1031c584SApple OSS Distributions 				tdev.d_slave = 1;
425*1031c584SApple OSS Distributions 				if (lop == 0) {
426*1031c584SApple OSS Distributions 					opt = op->op_next;
427*1031c584SApple OSS Distributions 				} else {
428*1031c584SApple OSS Distributions 					lop->op_next = op->op_next;
429*1031c584SApple OSS Distributions 				}
430*1031c584SApple OSS Distributions 				free(op);
431*1031c584SApple OSS Distributions 				op = 0;
432*1031c584SApple OSS Distributions 			}
433*1031c584SApple OSS Distributions 			free(od);
434*1031c584SApple OSS Distributions 			if (op == 0) {
435*1031c584SApple OSS Distributions 				break;
436*1031c584SApple OSS Distributions 			}
437*1031c584SApple OSS Distributions 		}
438*1031c584SApple OSS Distributions 		newdev(&tdev);
439*1031c584SApple OSS Distributions 	}
440*1031c584SApple OSS Distributions 	for (dp = dtab; dp != 0; dp = dp->d_next) {
441*1031c584SApple OSS Distributions 		if (eq(dp->d_name, wd) && (dp->d_type != PSEUDO_DEVICE || dp->d_slave)) {
442*1031c584SApple OSS Distributions 			if (not_option) {
443*1031c584SApple OSS Distributions 				goto invis;     /* dont want file if option present */
444*1031c584SApple OSS Distributions 			} else {
445*1031c584SApple OSS Distributions 				goto nextopt;
446*1031c584SApple OSS Distributions 			}
447*1031c584SApple OSS Distributions 		}
448*1031c584SApple OSS Distributions 	}
449*1031c584SApple OSS Distributions 	if (not_option) {
450*1031c584SApple OSS Distributions 		goto nextopt;           /* want file if option missing */
451*1031c584SApple OSS Distributions 	}
452*1031c584SApple OSS Distributions 	for (op = opt; op != 0; op = op->op_next) {
453*1031c584SApple OSS Distributions 		if (op->op_value == 0 && opteq(op->op_name, wd)) {
454*1031c584SApple OSS Distributions 			if (nreqs == 1) {
455*1031c584SApple OSS Distributions 				free(needs);
456*1031c584SApple OSS Distributions 				needs = 0;
457*1031c584SApple OSS Distributions 			}
458*1031c584SApple OSS Distributions 			goto nextopt;
459*1031c584SApple OSS Distributions 		}
460*1031c584SApple OSS Distributions 	}
461*1031c584SApple OSS Distributions 
462*1031c584SApple OSS Distributions invis:
463*1031c584SApple OSS Distributions 	while ((wd = get_word(fp)) != 0) {
464*1031c584SApple OSS Distributions 		;
465*1031c584SApple OSS Distributions 	}
466*1031c584SApple OSS Distributions 	if (tp == 0) {
467*1031c584SApple OSS Distributions 		tp = new_fent();
468*1031c584SApple OSS Distributions 	}
469*1031c584SApple OSS Distributions 	tp->f_fn = this;
470*1031c584SApple OSS Distributions 	tp->f_type = INVISIBLE;
471*1031c584SApple OSS Distributions 	tp->f_needs = needs;
472*1031c584SApple OSS Distributions 	tp->f_flags = isdup;
473*1031c584SApple OSS Distributions 	goto next;
474*1031c584SApple OSS Distributions 
475*1031c584SApple OSS Distributions doneopt:
476*1031c584SApple OSS Distributions 	if (nreqs == 0) {
477*1031c584SApple OSS Distributions 		printf("%s: what is %s optional on?\n",
478*1031c584SApple OSS Distributions 		    fname, this);
479*1031c584SApple OSS Distributions 		exit(1);
480*1031c584SApple OSS Distributions 	}
481*1031c584SApple OSS Distributions 
482*1031c584SApple OSS Distributions checkdev:
483*1031c584SApple OSS Distributions 	if (wd) {
484*1031c584SApple OSS Distributions 		if (*wd == '|') {
485*1031c584SApple OSS Distributions 			goto getrest;
486*1031c584SApple OSS Distributions 		}
487*1031c584SApple OSS Distributions 		next_word(fp, wd);
488*1031c584SApple OSS Distributions 		while (wd) {
489*1031c584SApple OSS Distributions 			if (eq(wd, "xnu-library")) {
490*1031c584SApple OSS Distributions 				f_flags |= LIBRARYDEP;
491*1031c584SApple OSS Distributions 				next_word(fp, wd);
492*1031c584SApple OSS Distributions 				continue;
493*1031c584SApple OSS Distributions 			}
494*1031c584SApple OSS Distributions 			if (eq(wd, "bound-checks")) {
495*1031c584SApple OSS Distributions 				f_flags |= BOUND_CHECKS;
496*1031c584SApple OSS Distributions 				next_word(fp, wd);
497*1031c584SApple OSS Distributions 				continue;
498*1031c584SApple OSS Distributions 			}
499*1031c584SApple OSS Distributions 			if (eq(wd, "bound-checks-soft")) {
500*1031c584SApple OSS Distributions 				f_flags |= BOUND_CHECKS_SOFT;
501*1031c584SApple OSS Distributions 				next_word(fp, wd);
502*1031c584SApple OSS Distributions 				continue;
503*1031c584SApple OSS Distributions 			}
504*1031c584SApple OSS Distributions 
505*1031c584SApple OSS Distributions 			devorprof = wd;
506*1031c584SApple OSS Distributions 			next_word(fp, wd);
507*1031c584SApple OSS Distributions 			break;
508*1031c584SApple OSS Distributions 		}
509*1031c584SApple OSS Distributions 	}
510*1031c584SApple OSS Distributions 
511*1031c584SApple OSS Distributions save:
512*1031c584SApple OSS Distributions getrest:
513*1031c584SApple OSS Distributions 	if (wd) {
514*1031c584SApple OSS Distributions 		if (*wd == '|') {
515*1031c584SApple OSS Distributions 			rest = ns(get_rest(fp));
516*1031c584SApple OSS Distributions 		} else {
517*1031c584SApple OSS Distributions 			printf("%s: syntax error describing %s\n",
518*1031c584SApple OSS Distributions 			    fname, this);
519*1031c584SApple OSS Distributions 			exit(1);
520*1031c584SApple OSS Distributions 		}
521*1031c584SApple OSS Distributions 	}
522*1031c584SApple OSS Distributions 	if (eq(devorprof, "profiling-routine") && profiling == 0) {
523*1031c584SApple OSS Distributions 		goto next;
524*1031c584SApple OSS Distributions 	}
525*1031c584SApple OSS Distributions 	if (tp == 0) {
526*1031c584SApple OSS Distributions 		tp = new_fent();
527*1031c584SApple OSS Distributions 	}
528*1031c584SApple OSS Distributions 	tp->f_fn = this;
529*1031c584SApple OSS Distributions 	tp->f_extra = rest;
530*1031c584SApple OSS Distributions 	if (options) {
531*1031c584SApple OSS Distributions 		tp->f_type = INVISIBLE;
532*1031c584SApple OSS Distributions 	} else if (eq(devorprof, "device-driver")) {
533*1031c584SApple OSS Distributions 		tp->f_type = DRIVER;
534*1031c584SApple OSS Distributions 	} else if (eq(devorprof, "profiling-routine")) {
535*1031c584SApple OSS Distributions 		tp->f_type = PROFILING;
536*1031c584SApple OSS Distributions 	} else {
537*1031c584SApple OSS Distributions 		tp->f_type = NORMAL;
538*1031c584SApple OSS Distributions 	}
539*1031c584SApple OSS Distributions 	tp->f_flags = f_flags;
540*1031c584SApple OSS Distributions 	tp->f_needs = needs;
541*1031c584SApple OSS Distributions 	if (pf && pf->f_type == INVISIBLE) {
542*1031c584SApple OSS Distributions 		pf->f_flags = 1;                /* mark as duplicate */
543*1031c584SApple OSS Distributions 	}
544*1031c584SApple OSS Distributions 	goto next;
545*1031c584SApple OSS Distributions }
546*1031c584SApple OSS Distributions 
547*1031c584SApple OSS Distributions int
opteq(const char * cp,const char * dp)548*1031c584SApple OSS Distributions opteq(const char *cp, const char *dp)
549*1031c584SApple OSS Distributions {
550*1031c584SApple OSS Distributions 	char c, d;
551*1031c584SApple OSS Distributions 
552*1031c584SApple OSS Distributions 	for (;; cp++, dp++) {
553*1031c584SApple OSS Distributions 		if (*cp != *dp) {
554*1031c584SApple OSS Distributions 			c = isupper(*cp) ? tolower(*cp) : *cp;
555*1031c584SApple OSS Distributions 			d = isupper(*dp) ? tolower(*dp) : *dp;
556*1031c584SApple OSS Distributions 			if (c != d) {
557*1031c584SApple OSS Distributions 				return 0;
558*1031c584SApple OSS Distributions 			}
559*1031c584SApple OSS Distributions 		}
560*1031c584SApple OSS Distributions 		if (*cp == 0) {
561*1031c584SApple OSS Distributions 			return 1;
562*1031c584SApple OSS Distributions 		}
563*1031c584SApple OSS Distributions 	}
564*1031c584SApple OSS Distributions }
565*1031c584SApple OSS Distributions 
566*1031c584SApple OSS Distributions void
put_source_file_name(FILE * fp,struct file_list * tp)567*1031c584SApple OSS Distributions put_source_file_name(FILE *fp, struct file_list *tp)
568*1031c584SApple OSS Distributions {
569*1031c584SApple OSS Distributions 	if ((tp->f_fn[0] == '.') && (tp->f_fn[1] == '/')) {
570*1031c584SApple OSS Distributions 		fprintf(fp, "%s ", tp->f_fn);
571*1031c584SApple OSS Distributions 	} else {
572*1031c584SApple OSS Distributions 		fprintf(fp, "$(SOURCE_DIR)/%s ", tp->f_fn);
573*1031c584SApple OSS Distributions 	}
574*1031c584SApple OSS Distributions }
575*1031c584SApple OSS Distributions 
576*1031c584SApple OSS Distributions void
do_objs(FILE * fp,const char * msg,int ext,int flags)577*1031c584SApple OSS Distributions do_objs(FILE *fp, const char *msg, int ext, int flags)
578*1031c584SApple OSS Distributions {
579*1031c584SApple OSS Distributions 	struct file_list *tp;
580*1031c584SApple OSS Distributions 	int lpos, len;
581*1031c584SApple OSS Distributions 	char *cp;
582*1031c584SApple OSS Distributions 	char och;
583*1031c584SApple OSS Distributions 	const char *sp;
584*1031c584SApple OSS Distributions 
585*1031c584SApple OSS Distributions 	fprintf(fp, "%s", msg);
586*1031c584SApple OSS Distributions 	lpos = strlen(msg);
587*1031c584SApple OSS Distributions 	for (tp = ftab; tp != 0; tp = tp->f_next) {
588*1031c584SApple OSS Distributions 		if (tp->f_type == INVISIBLE) {
589*1031c584SApple OSS Distributions 			continue;
590*1031c584SApple OSS Distributions 		}
591*1031c584SApple OSS Distributions 
592*1031c584SApple OSS Distributions 		/*
593*1031c584SApple OSS Distributions 		 * Check flags (if any)
594*1031c584SApple OSS Distributions 		 */
595*1031c584SApple OSS Distributions 		if (flags && ((tp->f_flags & flags) != flags)) {
596*1031c584SApple OSS Distributions 			continue;
597*1031c584SApple OSS Distributions 		}
598*1031c584SApple OSS Distributions 
599*1031c584SApple OSS Distributions 		/*
600*1031c584SApple OSS Distributions 		 *	Check for '.o' file in list
601*1031c584SApple OSS Distributions 		 */
602*1031c584SApple OSS Distributions 		cp = tp->f_fn + (len = strlen(tp->f_fn)) - 1;
603*1031c584SApple OSS Distributions 		if (ext != -1 && *cp != ext) {
604*1031c584SApple OSS Distributions 			continue;
605*1031c584SApple OSS Distributions 		} else if (*cp == 'o') {
606*1031c584SApple OSS Distributions 			if (len + lpos > 72) {
607*1031c584SApple OSS Distributions 				lpos = 8;
608*1031c584SApple OSS Distributions 				fprintf(fp, "\\\n\t");
609*1031c584SApple OSS Distributions 			}
610*1031c584SApple OSS Distributions 			put_source_file_name(fp, tp);
611*1031c584SApple OSS Distributions 			fprintf(fp, " ");
612*1031c584SApple OSS Distributions 			lpos += len + 1;
613*1031c584SApple OSS Distributions 			continue;
614*1031c584SApple OSS Distributions 		}
615*1031c584SApple OSS Distributions 		sp = tail(tp->f_fn);
616*1031c584SApple OSS Distributions 		cp = (char *)sp + (len = strlen(sp)) - 1;
617*1031c584SApple OSS Distributions 		och = *cp;
618*1031c584SApple OSS Distributions 		*cp = 'o';
619*1031c584SApple OSS Distributions 		if (len + lpos > 72) {
620*1031c584SApple OSS Distributions 			lpos = 8;
621*1031c584SApple OSS Distributions 			fprintf(fp, "\\\n\t");
622*1031c584SApple OSS Distributions 		}
623*1031c584SApple OSS Distributions 		fprintf(fp, "%s ", sp);
624*1031c584SApple OSS Distributions 		lpos += len + 1;
625*1031c584SApple OSS Distributions 		*cp = och;
626*1031c584SApple OSS Distributions 	}
627*1031c584SApple OSS Distributions 	putc('\n', fp);
628*1031c584SApple OSS Distributions }
629*1031c584SApple OSS Distributions 
630*1031c584SApple OSS Distributions void
do_files(FILE * fp,const char * msg,char ext)631*1031c584SApple OSS Distributions do_files(FILE *fp, const char *msg, char ext)
632*1031c584SApple OSS Distributions {
633*1031c584SApple OSS Distributions 	struct file_list *tp;
634*1031c584SApple OSS Distributions 	int lpos, len = 0; /* dvw: init to 0 */
635*1031c584SApple OSS Distributions 
636*1031c584SApple OSS Distributions 	fprintf(fp, "%s", msg);
637*1031c584SApple OSS Distributions 	lpos = 8;
638*1031c584SApple OSS Distributions 	for (tp = ftab; tp != 0; tp = tp->f_next) {
639*1031c584SApple OSS Distributions 		if (tp->f_type == INVISIBLE) {
640*1031c584SApple OSS Distributions 			continue;
641*1031c584SApple OSS Distributions 		}
642*1031c584SApple OSS Distributions 		if (tp->f_fn[strlen(tp->f_fn) - 1] != ext) {
643*1031c584SApple OSS Distributions 			continue;
644*1031c584SApple OSS Distributions 		}
645*1031c584SApple OSS Distributions 		/*
646*1031c584SApple OSS Distributions 		 * Always generate a newline.
647*1031c584SApple OSS Distributions 		 * Our Makefile's aren't readable anyway.
648*1031c584SApple OSS Distributions 		 */
649*1031c584SApple OSS Distributions 
650*1031c584SApple OSS Distributions 		lpos = 8;
651*1031c584SApple OSS Distributions 		fprintf(fp, "\\\n\t");
652*1031c584SApple OSS Distributions 		put_source_file_name(fp, tp);
653*1031c584SApple OSS Distributions 		lpos += len + 1;
654*1031c584SApple OSS Distributions 	}
655*1031c584SApple OSS Distributions 	putc('\n', fp);
656*1031c584SApple OSS Distributions }
657*1031c584SApple OSS Distributions 
658*1031c584SApple OSS Distributions /*
659*1031c584SApple OSS Distributions  *  Include machine dependent makefile in output
660*1031c584SApple OSS Distributions  */
661*1031c584SApple OSS Distributions 
662*1031c584SApple OSS Distributions void
do_machdep(FILE * ofp)663*1031c584SApple OSS Distributions do_machdep(FILE *ofp)
664*1031c584SApple OSS Distributions {
665*1031c584SApple OSS Distributions 	FILE *ifp;
666*1031c584SApple OSS Distributions 	char pname[BUFSIZ];
667*1031c584SApple OSS Distributions 	char line[BUFSIZ];
668*1031c584SApple OSS Distributions 
669*1031c584SApple OSS Distributions 	(void) sprintf(line, "%s/Makefile.%s", config_directory, machinename);
670*1031c584SApple OSS Distributions 	ifp = fopenp(VPATH, line, pname, "r");
671*1031c584SApple OSS Distributions 	if (ifp == 0) {
672*1031c584SApple OSS Distributions 		perror(line);
673*1031c584SApple OSS Distributions 		exit(1);
674*1031c584SApple OSS Distributions 	}
675*1031c584SApple OSS Distributions 	while (fgets(line, BUFSIZ, ifp) != 0) {
676*1031c584SApple OSS Distributions 		if (profiling && (strncmp(line, "LIBS=", 5) == 0)) {
677*1031c584SApple OSS Distributions 			fprintf(ofp, "LIBS=${LIBS_P}\n");
678*1031c584SApple OSS Distributions 		} else {
679*1031c584SApple OSS Distributions 			fputs(line, ofp);
680*1031c584SApple OSS Distributions 		}
681*1031c584SApple OSS Distributions 	}
682*1031c584SApple OSS Distributions 	fclose(ifp);
683*1031c584SApple OSS Distributions }
684*1031c584SApple OSS Distributions 
685*1031c584SApple OSS Distributions const char *
tail(const char * fn)686*1031c584SApple OSS Distributions tail(const char *fn)
687*1031c584SApple OSS Distributions {
688*1031c584SApple OSS Distributions 	const char *cp;
689*1031c584SApple OSS Distributions 
690*1031c584SApple OSS Distributions 	cp = rindex(fn, '/');
691*1031c584SApple OSS Distributions 	if (cp == 0) {
692*1031c584SApple OSS Distributions 		return fn;
693*1031c584SApple OSS Distributions 	}
694*1031c584SApple OSS Distributions 	return cp + 1;
695*1031c584SApple OSS Distributions }
696*1031c584SApple OSS Distributions 
697*1031c584SApple OSS Distributions /*
698*1031c584SApple OSS Distributions  * Create the makerules for each file
699*1031c584SApple OSS Distributions  * which is part of the system.
700*1031c584SApple OSS Distributions  * Devices are processed with the special c2 option -i
701*1031c584SApple OSS Distributions  * which avoids any problem areas with i/o addressing
702*1031c584SApple OSS Distributions  * (e.g. for the VAX); assembler files are processed by as.
703*1031c584SApple OSS Distributions  */
704*1031c584SApple OSS Distributions void
do_rules(FILE * f)705*1031c584SApple OSS Distributions do_rules(FILE *f)
706*1031c584SApple OSS Distributions {
707*1031c584SApple OSS Distributions 	char *cp;
708*1031c584SApple OSS Distributions 	char *np, och;
709*1031c584SApple OSS Distributions 	const char *tp;
710*1031c584SApple OSS Distributions 	struct file_list *ftp;
711*1031c584SApple OSS Distributions 	const char *extras = ""; /* dvw: init to "" */
712*1031c584SApple OSS Distributions 	char *source_dir;
713*1031c584SApple OSS Distributions 	char och_upper;
714*1031c584SApple OSS Distributions 	const char *nl = "";
715*1031c584SApple OSS Distributions 
716*1031c584SApple OSS Distributions 	for (ftp = ftab; ftp != 0; ftp = ftp->f_next) {
717*1031c584SApple OSS Distributions 		if (ftp->f_type == INVISIBLE) {
718*1031c584SApple OSS Distributions 			continue;
719*1031c584SApple OSS Distributions 		}
720*1031c584SApple OSS Distributions 		cp = (np = ftp->f_fn) + strlen(ftp->f_fn) - 1;
721*1031c584SApple OSS Distributions 		och = *cp;
722*1031c584SApple OSS Distributions 		/*
723*1031c584SApple OSS Distributions 		 *	Don't compile '.o' files
724*1031c584SApple OSS Distributions 		 */
725*1031c584SApple OSS Distributions 		if (och == 'o') {
726*1031c584SApple OSS Distributions 			continue;
727*1031c584SApple OSS Distributions 		}
728*1031c584SApple OSS Distributions 		/*
729*1031c584SApple OSS Distributions 		 *	Determine where sources should come from
730*1031c584SApple OSS Distributions 		 */
731*1031c584SApple OSS Distributions 		if ((np[0] == '.') && (np[1] == '/')) {
732*1031c584SApple OSS Distributions 			source_dir = "";
733*1031c584SApple OSS Distributions 			np += 2;
734*1031c584SApple OSS Distributions 		} else {
735*1031c584SApple OSS Distributions 			source_dir = "$(SOURCE_DIR)/";
736*1031c584SApple OSS Distributions 		}
737*1031c584SApple OSS Distributions 		*cp = '\0';
738*1031c584SApple OSS Distributions 		tp = tail(np);  /* dvw: init tp before 'if' */
739*1031c584SApple OSS Distributions 		fprintf(f, "-include %sd\n", tp);
740*1031c584SApple OSS Distributions 		if (ftp->f_flags & BOUND_CHECKS) {
741*1031c584SApple OSS Distributions 			fprintf(f, "%so_CFLAGS_ADD += ${CFLAGS_BOUND_CHECKS}\n", tp);
742*1031c584SApple OSS Distributions 		}
743*1031c584SApple OSS Distributions 
744*1031c584SApple OSS Distributions 		if (ftp->f_flags & BOUND_CHECKS_SOFT) {
745*1031c584SApple OSS Distributions 			fprintf(f, "%so_CFLAGS_ADD += ${CFLAGS_BOUND_CHECKS_SOFT}\n", tp);
746*1031c584SApple OSS Distributions 		}
747*1031c584SApple OSS Distributions 		fprintf(f, "%so: %s%s%c\n", tp, source_dir, np, och);
748*1031c584SApple OSS Distributions 		if (och == 's') {
749*1031c584SApple OSS Distributions 			fprintf(f, "\t${S_RULE_0}\n");
750*1031c584SApple OSS Distributions 			fprintf(f, "\t${S_RULE_1A} %s%.*s${S_RULE_1B}%s\n",
751*1031c584SApple OSS Distributions 			    source_dir, (int)(tp - np), np, nl);
752*1031c584SApple OSS Distributions 			fprintf(f, "\t${S_RULE_2}%s\n", nl);
753*1031c584SApple OSS Distributions 			continue;
754*1031c584SApple OSS Distributions 		}
755*1031c584SApple OSS Distributions 		extras = "";
756*1031c584SApple OSS Distributions 		switch (ftp->f_type) {
757*1031c584SApple OSS Distributions 		case NORMAL:
758*1031c584SApple OSS Distributions 			goto common;
759*1031c584SApple OSS Distributions 			break;
760*1031c584SApple OSS Distributions 
761*1031c584SApple OSS Distributions 		case DRIVER:
762*1031c584SApple OSS Distributions 			extras = "_D";
763*1031c584SApple OSS Distributions 			goto common;
764*1031c584SApple OSS Distributions 			break;
765*1031c584SApple OSS Distributions 
766*1031c584SApple OSS Distributions 		case PROFILING:
767*1031c584SApple OSS Distributions 			if (!profiling) {
768*1031c584SApple OSS Distributions 				continue;
769*1031c584SApple OSS Distributions 			}
770*1031c584SApple OSS Distributions 			if (COPTS == 0) {
771*1031c584SApple OSS Distributions 				fprintf(stderr,
772*1031c584SApple OSS Distributions 				    "config: COPTS undefined in generic makefile");
773*1031c584SApple OSS Distributions 				COPTS = "";
774*1031c584SApple OSS Distributions 			}
775*1031c584SApple OSS Distributions 			extras = "_P";
776*1031c584SApple OSS Distributions 			goto common;
777*1031c584SApple OSS Distributions 
778*1031c584SApple OSS Distributions common:
779*1031c584SApple OSS Distributions 			och_upper = och + 'A' - 'a';
780*1031c584SApple OSS Distributions 			fprintf(f, "\t${%c_RULE_0%s}\n", och_upper, extras);
781*1031c584SApple OSS Distributions 			fprintf(f, "\t${%c_RULE_1A%s}", och_upper, extras);
782*1031c584SApple OSS Distributions 			if (ftp->f_extra) {
783*1031c584SApple OSS Distributions 				fprintf(f, "%s", ftp->f_extra);
784*1031c584SApple OSS Distributions 			}
785*1031c584SApple OSS Distributions 			fprintf(f, " %s%.*s${%c_RULE_1B%s}%s\n",
786*1031c584SApple OSS Distributions 			    source_dir, (int)(tp - np), np, och_upper, extras, nl);
787*1031c584SApple OSS Distributions 
788*1031c584SApple OSS Distributions 			fprintf(f, "\t${%c_RULE_2%s}%s\n", och_upper, extras, nl);
789*1031c584SApple OSS Distributions 			fprintf(f, "\t${%c_RULE_3%s}%s\n", och_upper, extras, nl);
790*1031c584SApple OSS Distributions 			fprintf(f, "\t$(if ${%c_RULE_4A%s},${%c_RULE_4A%s}",
791*1031c584SApple OSS Distributions 			    och_upper, extras, och_upper, extras);
792*1031c584SApple OSS Distributions 			if (ftp->f_extra) {
793*1031c584SApple OSS Distributions 				fprintf(f, "%s", ftp->f_extra);
794*1031c584SApple OSS Distributions 			}
795*1031c584SApple OSS Distributions 			fprintf(f, "%s%.*s${%c_RULE_4B%s}%s)\n",
796*1031c584SApple OSS Distributions 			    source_dir, (int)(tp - np), np, och_upper, extras, nl);
797*1031c584SApple OSS Distributions 			break;
798*1031c584SApple OSS Distributions 
799*1031c584SApple OSS Distributions 		default:
800*1031c584SApple OSS Distributions 			printf("Don't know rules for %s\n", np);
801*1031c584SApple OSS Distributions 			break;
802*1031c584SApple OSS Distributions 		}
803*1031c584SApple OSS Distributions 		*cp = och;
804*1031c584SApple OSS Distributions 	}
805*1031c584SApple OSS Distributions }
806*1031c584SApple OSS Distributions 
807*1031c584SApple OSS Distributions char *
allCaps(char * str)808*1031c584SApple OSS Distributions allCaps(char *str)
809*1031c584SApple OSS Distributions {
810*1031c584SApple OSS Distributions 	char *cp = str;
811*1031c584SApple OSS Distributions 
812*1031c584SApple OSS Distributions 	while (*str) {
813*1031c584SApple OSS Distributions 		if (islower(*str)) {
814*1031c584SApple OSS Distributions 			*str = toupper(*str);
815*1031c584SApple OSS Distributions 		}
816*1031c584SApple OSS Distributions 		str++;
817*1031c584SApple OSS Distributions 	}
818*1031c584SApple OSS Distributions 	return cp;
819*1031c584SApple OSS Distributions }
820*1031c584SApple OSS Distributions 
821*1031c584SApple OSS Distributions #define OLDSALUTATION "# DO NOT DELETE THIS LINE"
822*1031c584SApple OSS Distributions 
823*1031c584SApple OSS Distributions #define LINESIZE 1024
824*1031c584SApple OSS Distributions static char makbuf[LINESIZE];           /* one line buffer for makefile */
825*1031c584SApple OSS Distributions 
826*1031c584SApple OSS Distributions void
copy_dependencies(FILE * makin,FILE * makout)827*1031c584SApple OSS Distributions copy_dependencies(FILE *makin, FILE *makout)
828*1031c584SApple OSS Distributions {
829*1031c584SApple OSS Distributions 	int oldlen = (sizeof OLDSALUTATION - 1);
830*1031c584SApple OSS Distributions 
831*1031c584SApple OSS Distributions 	while (fgets(makbuf, LINESIZE, makin) != NULL) {
832*1031c584SApple OSS Distributions 		if (!strncmp(makbuf, OLDSALUTATION, oldlen)) {
833*1031c584SApple OSS Distributions 			break;
834*1031c584SApple OSS Distributions 		}
835*1031c584SApple OSS Distributions 	}
836*1031c584SApple OSS Distributions 	while (fgets(makbuf, LINESIZE, makin) != NULL) {
837*1031c584SApple OSS Distributions 		if (oldlen != 0) {
838*1031c584SApple OSS Distributions 			if (makbuf[0] == '\n') {
839*1031c584SApple OSS Distributions 				continue;
840*1031c584SApple OSS Distributions 			} else {
841*1031c584SApple OSS Distributions 				oldlen = 0;
842*1031c584SApple OSS Distributions 			}
843*1031c584SApple OSS Distributions 		}
844*1031c584SApple OSS Distributions 		fputs(makbuf, makout);
845*1031c584SApple OSS Distributions 	}
846*1031c584SApple OSS Distributions }
847