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