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