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