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