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