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