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