xref: /dragonfly/usr.sbin/config/mkmakefile.c (revision 335b9e93)
1 /*
2  * Copyright (c) 1993, 19801990
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * @(#)mkmakefile.c	8.1 (Berkeley) 6/6/93
30  * $FreeBSD: src/usr.sbin/config/mkmakefile.c,v 1.51.2.3 2001/01/23 00:09:32 peter Exp $
31  */
32 
33 /*
34  * Build the makefile for the system, from
35  * the information in the 'files' files and the
36  * additional files for the machine being compiled to.
37  */
38 
39 #include <ctype.h>
40 #include <err.h>
41 #include <stdio.h>
42 #include <string.h>
43 #include <sys/param.h>
44 #include "y.tab.h"
45 #include "config.h"
46 #include "configvers.h"
47 
48 #define next_word(fp, wd)						\
49 	{								\
50 		char *word;						\
51 									\
52 		word = get_word(fp);					\
53 		if (word == (char *)EOF)				\
54 			return;						\
55 		else							\
56 			wd = word;					\
57 	}
58 #define next_quoted_word(fp, wd)					\
59 	{								\
60 		char *word;						\
61 									\
62 		word = get_quoted_word(fp);				\
63 		if (word == (char *)EOF)				\
64 			return;						\
65 		else							\
66 			wd = word;					\
67 	}
68 
69 static struct file_list *fcur;
70 
71 static char *tail(char *);
72 static void do_clean(FILE *);
73 static void do_rules(FILE *);
74 static void do_sfiles(FILE *);
75 static void do_mfiles(FILE *);
76 static void do_cfiles(FILE *);
77 static void do_objs(FILE *);
78 static void do_before_depend(FILE *);
79 static int opteq(char *, char *);
80 static void read_files(void);
81 
82 /*
83  * Lookup a file, by name.
84  */
85 static struct file_list *
86 fl_lookup(char *file)
87 {
88 	struct file_list *fp;
89 
90 	for (fp = ftab; fp != NULL; fp = fp->f_next) {
91 		if (strcmp(fp->f_fn, file) == 0)
92 			return(fp);
93 	}
94 	return(0);
95 }
96 
97 /*
98  * Lookup a file, by final component name.
99  */
100 static struct file_list *
101 fltail_lookup(char *file)
102 {
103 	struct file_list *fp;
104 
105 	for (fp = ftab; fp != NULL; fp = fp->f_next) {
106 		if (strcmp(tail(fp->f_fn), tail(file)) == 0)
107 			return(fp);
108 	}
109 	return(0);
110 }
111 
112 /*
113  * Make a new file list entry
114  */
115 static struct file_list *
116 new_fent(void)
117 {
118 	struct file_list *fp;
119 
120 	fp = malloc(sizeof(*fp));
121 	bzero(fp, sizeof(*fp));
122 	if (fcur == NULL)
123 		fcur = ftab = fp;
124 	else
125 		fcur->f_next = fp;
126 	fcur = fp;
127 	return(fp);
128 }
129 
130 /*
131  * Build the makefile from the skeleton
132  */
133 void
134 makefile(void)
135 {
136 	FILE *ifp, *ofp;
137 	char line[BUFSIZ];
138 	struct opt *op;
139 	int versreq;
140 
141 	read_files();
142 	snprintf(line, sizeof(line), "../platform/%s/conf/Makefile",
143 		 platformname);
144 	ifp = fopen(line, "r");
145 	if (ifp == NULL) {
146 		snprintf(line, sizeof(line), "Makefile.%s", platformname);
147 		ifp = fopen(line, "r");
148 	}
149 	if (ifp == NULL)
150 		err(1, "%s", line);
151 	ofp = fopen(path("Makefile.new"), "w");
152 	if (ofp == NULL)
153 		err(1, "%s", path("Makefile.new"));
154 	fprintf(ofp, "KERN_IDENT=%s\n", raisestr(ident));
155 	fprintf(ofp, "MACHINE_PLATFORM=%s\n", platformname);
156 	fprintf(ofp, "MACHINE=%s\n", machinename);
157 	fprintf(ofp, "MACHINE_ARCH=%s\n", machinearchname);
158 	fprintf(ofp, ".export MACHINE_PLATFORM\n");
159 	fprintf(ofp, ".export MACHINE\n");
160 	fprintf(ofp, ".export MACHINE_ARCH\n");
161 	fprintf(ofp, "IDENT=");
162 
163 	if (cputype == 0) {
164 		printf("cpu type must be specified\n");
165 		exit(1);
166 	}
167 	fprintf(ofp, "\n");
168 	for (op = mkopt; op != NULL; op = op->op_next)
169 		fprintf(ofp, "%s=%s\n", op->op_name, op->op_value);
170 	if (debugging)
171 		fprintf(ofp, "DEBUG=-g\n");
172 	if (*srcdir != '\0')
173 		fprintf(ofp,"S=%s\n", srcdir);
174 	while (fgets(line, BUFSIZ, ifp) != 0) {
175 		if (*line != '%') {
176 			fprintf(ofp, "%s", line);
177 			continue;
178 		}
179 		if (strcmp(line, "%BEFORE_DEPEND\n") == 0)
180 			do_before_depend(ofp);
181 		else if (strcmp(line, "%OBJS\n") == 0)
182 			do_objs(ofp);
183 		else if (strcmp(line, "%MFILES\n") == 0)
184 			do_mfiles(ofp);
185 		else if (strcmp(line, "%CFILES\n") == 0)
186 			do_cfiles(ofp);
187 		else if (strcmp(line, "%SFILES\n") == 0)
188 			do_sfiles(ofp);
189 		else if (strcmp(line, "%RULES\n") == 0)
190 			do_rules(ofp);
191 		else if (strcmp(line, "%CLEAN\n") == 0)
192 			do_clean(ofp);
193 		else if (strncmp(line, "%VERSREQ=", sizeof("%VERSREQ=") - 1) == 0) {
194 			versreq = atoi(line + sizeof("%VERSREQ=") - 1);
195 			if (versreq != CONFIGVERS) {
196 				fprintf(stderr, "ERROR: version of config(8) does not match kernel!\n");
197 				fprintf(stderr, "config version = %d, ", CONFIGVERS);
198 				fprintf(stderr, "version required = %d\n\n", versreq);
199 				fprintf(stderr, "Make sure that /usr/src/usr.sbin/config is in sync\n");
200 				fprintf(stderr, "with your /usr/src/sys and install a new config binary\n");
201 				fprintf(stderr, "before trying this again.\n\n");
202 				fprintf(stderr, "If running the new config fails check your config\n");
203 				fprintf(stderr, "file against the GENERIC or LINT config files for\n");
204 				fprintf(stderr, "changes in config syntax, or option/device naming\n");
205 				fprintf(stderr, "conventions\n\n");
206 				exit(1);
207 			}
208 		} else
209 			fprintf(stderr,
210 			    "Unknown %% construct in generic makefile: %s",
211 			    line);
212 	}
213 	fclose(ifp);
214 	fclose(ofp);
215 	moveifchanged(path("Makefile.new"), path("Makefile"));
216 }
217 
218 /*
219  * Read in the information about files used in making the system.
220  * Store it in the ftab linked list.
221  */
222 static void
223 read_files(void)
224 {
225 	FILE *fp;
226 	struct file_list *tp, *pf;
227 	struct device *dp;
228 	struct device *save_dp;
229 	struct opt *op;
230 	char *wd, *this, *needs, *special, *depends, *clean, *warning;
231 	char fname[MAXPATHLEN];
232 	int nonoptional;
233 	int nreqs, first = 1, configdep, isdup, std, filetype,
234 	    imp_rule, no_obj, before_depend, nowerror, mandatory;
235 
236 	ftab = 0;
237 	save_dp = NULL;
238 	if (ident == NULL) {
239 		printf("no ident line specified\n");
240 		exit(1);
241 	}
242 	snprintf(fname, sizeof(fname), "../conf/files");
243 openit:
244 	fp = fopen(fname, "r");
245 	if (fp == NULL)
246 		err(1, "%s", fname);
247 next:
248 	/*
249 	 * filename    [ standard | mandatory | optional ] [ config-dependent ]
250 	 *	[ dev* ] [ no-obj ]
251 	 *	[ compile-with "compile rule" [no-implicit-rule] ]
252 	 *      [ dependency "dependency-list"] [ before-depend ]
253 	 *	[ clean "file-list"] [ warning "text warning" ]
254 	 */
255 	wd = get_word(fp);
256 	if (wd == (char *)EOF) {
257 		fclose(fp);
258 		if (first == 1) {
259 			first++;
260 			snprintf(fname, sizeof(fname),
261 			    "../platform/%s/conf/files",
262 			    platformname);
263 			fp = fopen(fname, "r");
264 			if (fp != NULL)
265 				goto next;
266 			snprintf(fname, sizeof(fname),
267 			    "files.%s", platformname);
268 			goto openit;
269 		}
270 		if (first == 2) {
271 			first++;
272 			snprintf(fname, sizeof(fname),
273 			    "files.%s", raisestr(ident));
274 			fp = fopen(fname, "r");
275 			if (fp != NULL)
276 				goto next;
277 		}
278 		return;
279 	}
280 	if (wd == NULL)
281 		goto next;
282 	if (wd[0] == '#')
283 	{
284 		while (((wd = get_word(fp)) != (char *)EOF) && wd)
285 			;
286 		goto next;
287 	}
288 	this = strdup(wd);
289 	next_word(fp, wd);
290 	if (wd == NULL) {
291 		printf("%s: No type for %s.\n",
292 		    fname, this);
293 		exit(1);
294 	}
295 	if ((pf = fl_lookup(this)) && (pf->f_type != INVISIBLE || pf->f_flags))
296 		isdup = 1;
297 	else
298 		isdup = 0;
299 	tp = NULL;
300 	if (first == 3 && pf == NULL && (tp = fltail_lookup(this)) != NULL) {
301 		if (tp->f_type != INVISIBLE || tp->f_flags)
302 			printf("%s: Local file %s overrides %s.\n",
303 			    fname, this, tp->f_fn);
304 		else
305 			printf("%s: Local file %s could override %s"
306 			    " with a different kernel configuration.\n",
307 			    fname, this, tp->f_fn);
308 	}
309 	nreqs = 0;
310 	special = NULL;
311 	depends = NULL;
312 	clean = NULL;
313 	warning = NULL;
314 	configdep = 0;
315 	needs = NULL;
316 	std = mandatory = nonoptional = 0;
317 	imp_rule = 0;
318 	no_obj = 0;
319 	before_depend = 0;
320 	nowerror = 0;
321 	filetype = NORMAL;
322 	if (strcmp(wd, "standard") == 0) {
323 		std = 1;
324 	} else if (strcmp(wd, "mandatory") == 0) {
325 		/*
326 		 * If an entry is marked "mandatory", config will abort if
327 		 * it's not called by a configuration line in the config
328 		 * file.  Apart from this, the device is handled like one
329 		 * marked "optional".
330 		 */
331 		mandatory = 1;
332 	} else if (strcmp(wd, "nonoptional") == 0) {
333 		nonoptional = 1;
334 	} else if (strcmp(wd, "optional") == 0) {
335 		/* don't need to do anything */
336 	} else {
337 		printf("%s: %s must be optional, mandatory or standard\n",
338 		       fname, this);
339 		printf("Alternatively, your version of config(8) may be out of sync with your\nkernel source.\n");
340 		exit(1);
341 	}
342 nextparam:
343 	next_word(fp, wd);
344 	if (wd == NULL)
345 		goto doneparam;
346 	if (strcmp(wd, "config-dependent") == 0) {
347 		configdep++;
348 		goto nextparam;
349 	}
350 	if (strcmp(wd, "no-obj") == 0) {
351 		no_obj++;
352 		goto nextparam;
353 	}
354 	if (strcmp(wd, "no-implicit-rule") == 0) {
355 		if (special == NULL) {
356 			printf("%s: alternate rule required when "
357 			       "\"no-implicit-rule\" is specified.\n",
358 			       fname);
359 		}
360 		imp_rule++;
361 		goto nextparam;
362 	}
363 	if (strcmp(wd, "before-depend") == 0) {
364 		before_depend++;
365 		goto nextparam;
366 	}
367 	if (strcmp(wd, "dependency") == 0) {
368 		next_quoted_word(fp, wd);
369 		if (wd == NULL) {
370 			printf("%s: %s missing compile command string.\n",
371 			       fname, this);
372 			exit(1);
373 		}
374 		depends = strdup(wd);
375 		goto nextparam;
376 	}
377 	if (strcmp(wd, "clean") == 0) {
378 		next_quoted_word(fp, wd);
379 		if (wd == NULL) {
380 			printf("%s: %s missing clean file list.\n",
381 			       fname, this);
382 			exit(1);
383 		}
384 		clean = strdup(wd);
385 		goto nextparam;
386 	}
387 	if (strcmp(wd, "compile-with") == 0) {
388 		next_quoted_word(fp, wd);
389 		if (wd == NULL) {
390 			printf("%s: %s missing compile command string.\n",
391 			       fname, this);
392 			exit(1);
393 		}
394 		special = strdup(wd);
395 		goto nextparam;
396 	}
397 	if (strcmp(wd, "nowerror") == 0) {
398 		nowerror++;
399 		goto nextparam;
400 	}
401 	if (strcmp(wd, "warning") == 0) {
402 		next_quoted_word(fp, wd);
403 		if (wd == NULL) {
404 			printf("%s: %s missing warning text string.\n",
405 				fname, this);
406 			exit(1);
407 		}
408 		warning = strdup(wd);
409 		goto nextparam;
410 	}
411 	nreqs++;
412 	if (strcmp(wd, "local") == 0) {
413 		filetype = LOCAL;
414 		goto nextparam;
415 	}
416 	if (strcmp(wd, "no-depend") == 0) {
417 		filetype = NODEPEND;
418 		goto nextparam;
419 	}
420 	if (strcmp(wd, "device-driver") == 0) {
421 		printf("%s: `device-driver' flag obsolete.\n", fname);
422 		exit(1);
423 	}
424 	if (needs == NULL && nreqs == 1)
425 		needs = strdup(wd);
426 	if (isdup)
427 		goto invis;
428 	for (dp = dtab; dp != NULL; save_dp = dp, dp = dp->d_next)
429 		if (strcmp(dp->d_name, wd) == 0) {
430 			if (std && dp->d_type == PSEUDO_DEVICE &&
431 			    dp->d_count <= 0)
432 				dp->d_count = 1;
433 			goto nextparam;
434 		}
435 	if (mandatory) {
436 		printf("%s: mandatory device \"%s\" not found\n",
437 		       fname, wd);
438 		exit(1);
439 	}
440 	if (std) {
441 		dp = malloc(sizeof(*dp));
442 		bzero(dp, sizeof(*dp));
443 		init_dev(dp);
444 		dp->d_name = strdup(wd);
445 		dp->d_type = PSEUDO_DEVICE;
446 		dp->d_count = 1;
447 		save_dp->d_next = dp;
448 		goto nextparam;
449 	}
450 	for (op = opt; op != NULL; op = op->op_next) {
451 		if (op->op_value == 0 && opteq(op->op_name, wd)) {
452 			if (nreqs == 1) {
453 				free(needs);
454 				needs = NULL;
455 			}
456 			goto nextparam;
457 		}
458 	}
459 	if (nonoptional) {
460 		printf("%s: the option \"%s\" MUST be specified\n",
461 			fname, wd);
462 		exit(1);
463 	}
464 invis:
465 	while ((wd = get_word(fp)) != NULL)
466 		;
467 	if (tp == NULL)
468 		tp = new_fent();
469 	tp->f_fn = this;
470 	tp->f_type = INVISIBLE;
471 	tp->f_needs = needs;
472 	tp->f_flags = isdup;
473 	tp->f_special = special;
474 	tp->f_depends = depends;
475 	tp->f_clean = clean;
476 	tp->f_warn = warning;
477 	goto next;
478 
479 doneparam:
480 	if (std == 0 && nreqs == 0) {
481 		printf("%s: what is %s optional on?\n",
482 		    fname, this);
483 		exit(1);
484 	}
485 
486 	if (wd != NULL) {
487 		printf("%s: syntax error describing %s\n",
488 		    fname, this);
489 		exit(1);
490 	}
491 	if (tp == NULL)
492 		tp = new_fent();
493 	tp->f_fn = this;
494 	tp->f_type = filetype;
495 	tp->f_flags = 0;
496 	if (configdep)
497 		tp->f_flags |= CONFIGDEP;
498 	if (imp_rule)
499 		tp->f_flags |= NO_IMPLCT_RULE;
500 	if (no_obj)
501 		tp->f_flags |= NO_OBJ;
502 	if (before_depend)
503 		tp->f_flags |= BEFORE_DEPEND;
504 	if (nowerror)
505 		tp->f_flags |= NOWERROR;
506 	if (imp_rule)
507 		tp->f_flags |= NO_IMPLCT_RULE;
508 	if (no_obj)
509 		tp->f_flags |= NO_OBJ;
510 	tp->f_needs = needs;
511 	tp->f_special = special;
512 	tp->f_depends = depends;
513 	tp->f_clean = clean;
514 	tp->f_warn = warning;
515 	if (pf && pf->f_type == INVISIBLE)
516 		pf->f_flags = 1;		/* mark as duplicate */
517 	goto next;
518 }
519 
520 static int
521 opteq(char *cp, char *dp)
522 {
523 	char c, d;
524 
525 	for (;; cp++, dp++) {
526 		if (*cp != *dp) {
527 			c = isupper(*cp) ? tolower(*cp) : *cp;
528 			d = isupper(*dp) ? tolower(*dp) : *dp;
529 			if (c != d)
530 				return(0);
531 		}
532 		if (*cp == 0)
533 			return(1);
534 	}
535 }
536 
537 static void
538 do_before_depend(FILE *fp)
539 {
540 	struct file_list *tp;
541 	int lpos, len;
542 
543 	fputs("BEFORE_DEPEND=", fp);
544 	lpos = 15;
545 	for (tp = ftab; tp != NULL; tp = tp->f_next)
546 		if (tp->f_flags & BEFORE_DEPEND) {
547 			len = strlen(tp->f_fn);
548 			if ((len = 3 + len) + lpos > 72) {
549 				lpos = 8;
550 				fputs("\\\n\t", fp);
551 			}
552 			if (tp->f_flags & NO_IMPLCT_RULE)
553 				fprintf(fp, "%s ", tp->f_fn);
554 			else
555 				fprintf(fp, "$S/%s ", tp->f_fn);
556 			lpos += len + 1;
557 		}
558 	if (lpos != 8)
559 		putc('\n', fp);
560 }
561 
562 static void
563 do_objs(FILE *fp)
564 {
565 	struct file_list *tp;
566 	int lpos, len;
567 	char *cp, och, *sp;
568 
569 	fprintf(fp, "OBJS=");
570 	lpos = 6;
571 	for (tp = ftab; tp != NULL; tp = tp->f_next) {
572 		if (tp->f_type == INVISIBLE || tp->f_flags & NO_OBJ)
573 			continue;
574 		sp = tail(tp->f_fn);
575 		cp = sp + (len = strlen(sp)) - 1;
576 		och = *cp;
577 		*cp = 'o';
578 		if (len + lpos > 72) {
579 			lpos = 8;
580 			fprintf(fp, "\\\n\t");
581 		}
582 		fprintf(fp, "%s ", sp);
583 		lpos += len + 1;
584 		*cp = och;
585 	}
586 	if (lpos != 8)
587 		putc('\n', fp);
588 }
589 
590 static void
591 do_cfiles(FILE *fp)
592 {
593 	struct file_list *tp;
594 	int lpos, len;
595 
596 	fputs("CFILES=", fp);
597 	lpos = 8;
598 	for (tp = ftab; tp != NULL; tp = tp->f_next)
599 		if (tp->f_type != INVISIBLE && tp->f_type != NODEPEND) {
600 			len = strlen(tp->f_fn);
601 			if (tp->f_fn[len - 1] != 'c')
602 				continue;
603 			if ((len = 3 + len) + lpos > 72) {
604 				lpos = 8;
605 				fputs("\\\n\t", fp);
606 			}
607 			if (tp->f_type != LOCAL)
608 				fprintf(fp, "$S/%s ", tp->f_fn);
609 			else
610 				fprintf(fp, "%s ", tp->f_fn);
611 
612 			lpos += len + 1;
613 		}
614 	if (lpos != 8)
615 		putc('\n', fp);
616 }
617 
618 static void
619 do_mfiles(FILE *fp)
620 {
621 	struct file_list *tp;
622 	int lpos, len;
623 
624 	fputs("MFILES=", fp);
625 	lpos = 8;
626 	for (tp = ftab; tp != NULL; tp = tp->f_next)
627 		if (tp->f_type != INVISIBLE) {
628 			len = strlen(tp->f_fn);
629 			if (tp->f_fn[len - 1] != 'm' || tp->f_fn[len - 2] != '.')
630 				continue;
631 			if ((len = 3 + len) + lpos > 72) {
632 				lpos = 8;
633 				fputs("\\\n\t", fp);
634 			}
635 			fprintf(fp, "$S/%s ", tp->f_fn);
636 			lpos += len + 1;
637 		}
638 	if (lpos != 8)
639 		putc('\n', fp);
640 }
641 
642 static void
643 do_sfiles(FILE *fp)
644 {
645 	struct file_list *tp;
646 	int lpos, len;
647 
648 	fputs("SFILES=", fp);
649 	lpos = 8;
650 	for (tp = ftab; tp != NULL; tp = tp->f_next)
651 		if (tp->f_type != INVISIBLE) {
652 			len = strlen(tp->f_fn);
653 			if (tp->f_fn[len - 1] != 'S' && tp->f_fn[len - 1] != 's')
654 				continue;
655 			if ((len = 3 + len) + lpos > 72) {
656 				lpos = 8;
657 				fputs("\\\n\t", fp);
658 			}
659 			fprintf(fp, "$S/%s ", tp->f_fn);
660 			lpos += len + 1;
661 		}
662 	if (lpos != 8)
663 		putc('\n', fp);
664 }
665 
666 
667 static char *
668 tail(char *fn)
669 {
670 	char *cp;
671 
672 	cp = strrchr(fn, '/');
673 	if (cp == NULL)
674 		return(fn);
675 	return(cp + 1);
676 }
677 
678 /*
679  * Create the makerules for each file
680  * which is part of the system.
681  * Devices are processed with the special c2 option -i
682  * which avoids any problem areas with i/o addressing
683  * (e.g. for the VAX); assembler files are processed by as.
684  */
685 static void
686 do_rules(FILE *f)
687 {
688 	char *cp, *np, och;
689 	struct file_list *ftp;
690 	char *special;
691 
692 	for (ftp = ftab; ftp != NULL; ftp = ftp->f_next) {
693 		if (ftp->f_type == INVISIBLE)
694 			continue;
695 		if (ftp->f_warn != NULL)
696 			printf("WARNING: %s\n", ftp->f_warn);
697 		cp = (np = ftp->f_fn) + strlen(ftp->f_fn) - 1;
698 		och = *cp;
699 		if (ftp->f_flags & NO_IMPLCT_RULE) {
700 			if (ftp->f_depends)
701 				fprintf(f, "%s: %s\n", np, ftp->f_depends);
702 			else
703 				fprintf(f, "%s: \n", np);
704 		}
705 		else {
706 			*cp = '\0';
707 			if (och == 'o') {
708 				fprintf(f, "%so:\n\t-cp $S/%so .\n\n",
709 					tail(np), np);
710 				continue;
711 			}
712 			if (ftp->f_depends)
713 				fprintf(f, "%so: $S/%s%c %s\n", tail(np),
714 					np, och, ftp->f_depends);
715 			else
716 				fprintf(f, "%so: $S/%s%c\n", tail(np),
717 					np, och);
718 		}
719 		special = ftp->f_special;
720 		if (special == NULL) {
721 			const char *ftype = NULL;
722 			static char cmd[128];
723 
724 			switch (ftp->f_type) {
725 
726 			case NORMAL:
727 				ftype = "NORMAL";
728 				break;
729 
730 			default:
731 				printf("config: don't know rules for %s\n", np);
732 				break;
733 			}
734 			snprintf(cmd, sizeof(cmd), "${%s_%c%s}%s",
735 			    ftype, toupper(och),
736 			    ftp->f_flags & CONFIGDEP ? "_C" : "",
737 			    ftp->f_flags & NOWERROR ? "" : " ${WERROR}");
738 			special = cmd;
739 		}
740 		*cp = och;
741 		fprintf(f, "\t%s\n\n", special);
742 	}
743 }
744 
745 static void
746 do_clean(FILE *fp)
747 {
748 	struct file_list *tp;
749 	int lpos, len;
750 
751 	fputs("CLEAN=", fp);
752 	lpos = 7;
753 	for (tp = ftab; tp != NULL; tp = tp->f_next)
754 		if (tp->f_clean) {
755 			len = strlen(tp->f_clean);
756 			if (len + lpos > 72) {
757 				lpos = 8;
758 				fputs("\\\n\t", fp);
759 			}
760 			fprintf(fp, "%s ", tp->f_clean);
761 			lpos += len + 1;
762 		}
763 	if (lpos != 8)
764 		putc('\n', fp);
765 }
766 
767 char *
768 raisestr(char *str)
769 {
770 	char *cp = str;
771 
772 	while (*str) {
773 		if (islower(*str))
774 			*str = toupper(*str);
775 		str++;
776 	}
777 	return(cp);
778 }
779