]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/config/mkmakefile.c
Import libxo-0.9.0:
[FreeBSD/FreeBSD.git] / usr.sbin / config / mkmakefile.c
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1980, 1990, 1993
5  *      The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31
32 #ifndef lint
33 #if 0
34 static char sccsid[] = "@(#)mkmakefile.c        8.1 (Berkeley) 6/6/93";
35 #endif
36 static const char rcsid[] =
37   "$FreeBSD$";
38 #endif /* not lint */
39
40 /*
41  * Build the makefile for the system, from
42  * the information in the files files and the
43  * additional files for the machine being compiled to.
44  */
45
46 #include <ctype.h>
47 #include <err.h>
48 #include <stdarg.h>
49 #include <stdio.h>
50 #include <string.h>
51 #include <sys/param.h>
52 #include "y.tab.h"
53 #include "config.h"
54 #include "configvers.h"
55
56 static char *tail(char *);
57 static void do_clean(FILE *);
58 static void do_rules(FILE *);
59 static void do_xxfiles(char *, FILE *);
60 static void do_objs(FILE *);
61 static void do_before_depend(FILE *);
62 static int opteq(const char *, const char *);
63 static void read_files(void);
64
65 static void errout(const char *fmt, ...)
66 {
67         va_list ap;
68
69         va_start(ap, fmt);
70         vfprintf(stderr, fmt, ap);
71         va_end(ap);
72         exit(1);
73 }
74
75 /*
76  * Lookup a file, by name.
77  */
78 static struct file_list *
79 fl_lookup(char *file)
80 {
81         struct file_list *fp;
82
83         STAILQ_FOREACH(fp, &ftab, f_next) {
84                 if (eq(fp->f_fn, file))
85                         return (fp);
86         }
87         return (0);
88 }
89
90 /*
91  * Make a new file list entry
92  */
93 static struct file_list *
94 new_fent(void)
95 {
96         struct file_list *fp;
97
98         fp = (struct file_list *) calloc(1, sizeof *fp);
99         if (fp == NULL)
100                 err(EXIT_FAILURE, "calloc");
101         STAILQ_INSERT_TAIL(&ftab, fp, f_next);
102         return (fp);
103 }
104
105 /*
106  * Open the correct Makefile and return it, or error out.
107  */
108 FILE *
109 open_makefile_template(void)
110 {
111         FILE *ifp;
112         char line[BUFSIZ];
113
114         snprintf(line, sizeof(line), "../../conf/Makefile.%s", machinename);
115         ifp = fopen(line, "r");
116         if (ifp == NULL) {
117                 snprintf(line, sizeof(line), "Makefile.%s", machinename);
118                 ifp = fopen(line, "r");
119         }
120         if (ifp == NULL)
121                 err(1, "%s", line);
122         return (ifp);
123 }
124
125 /*
126  * Build the makefile from the skeleton
127  */
128 void
129 makefile(void)
130 {
131         FILE *ifp, *ofp;
132         char line[BUFSIZ];
133         struct opt *op, *t;
134
135         read_files();
136         ifp = open_makefile_template();
137         ofp = fopen(path("Makefile.new"), "w");
138         if (ofp == NULL)
139                 err(1, "%s", path("Makefile.new"));
140         fprintf(ofp, "KERN_IDENT=%s\n", ident);
141         fprintf(ofp, "MACHINE=%s\n", machinename);
142         fprintf(ofp, "MACHINE_ARCH=%s\n", machinearch);
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) != NULL) {
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) != NULL) {
206                         /* zap trailing CR and/or LF */
207                         while ((s = strrchr(line, '\n')) != NULL)
208                                 *s = '\0';
209                         while ((s = strrchr(line, '\r')) != NULL)
210                                 *s = '\0';
211                         /* remove # comments */
212                         s = strchr(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) != NULL) {
268                         /* zap trailing CR and/or LF */
269                         while ((s = strrchr(line, '\n')) != NULL)
270                                 *s = '\0';
271                         while ((s = strrchr(line, '\r')) != NULL)
272                                 *s = '\0';
273                         /* remove # comments */
274                         s = strchr(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         const char *objprefix;
314         int compile, match, nreqs, std, filetype, not,
315             imp_rule, no_obj, before_depend, nowerror;
316
317         fp = fopen(fname, "r");
318         if (fp == NULL)
319                 err(1, "%s", fname);
320 next:
321         /*
322          * include "filename"
323          * filename    [ standard | optional ]
324          *      [ dev* [ | dev* ... ] | profiling-routine ] [ no-obj ]
325          *      [ compile-with "compile rule" [no-implicit-rule] ]
326          *      [ dependency "dependency-list"] [ before-depend ]
327          *      [ clean "file-list"] [ warning "text warning" ]
328          *      [ obj-prefix "file prefix"]
329          */
330         wd = get_word(fp);
331         if (wd == (char *)EOF) {
332                 (void) fclose(fp);
333                 return;
334         } 
335         if (wd == NULL)
336                 goto next;
337         if (wd[0] == '#')
338         {
339                 while (((wd = get_word(fp)) != (char *)EOF) && wd)
340                         ;
341                 goto next;
342         }
343         if (eq(wd, "include")) {
344                 wd = get_quoted_word(fp);
345                 if (wd == (char *)EOF || wd == NULL)
346                         errout("%s: missing include filename.\n", fname);
347                 (void) snprintf(ifname, sizeof(ifname), "../../%s", wd);
348                 read_file(ifname);
349                 while (((wd = get_word(fp)) != (char *)EOF) && wd)
350                         ;
351                 goto next;
352         }
353         this = ns(wd);
354         wd = get_word(fp);
355         if (wd == (char *)EOF)
356                 return;
357         if (wd == NULL)
358                 errout("%s: No type for %s.\n", fname, this);
359         tp = fl_lookup(this);
360         compile = 0;
361         match = 1;
362         nreqs = 0;
363         compilewith = 0;
364         depends = 0;
365         clean = 0;
366         warning = 0;
367         std = 0;
368         imp_rule = 0;
369         no_obj = 0;
370         before_depend = 0;
371         nowerror = 0;
372         not = 0;
373         filetype = NORMAL;
374         objprefix = "";
375         if (eq(wd, "standard"))
376                 std = 1;
377         else if (!eq(wd, "optional"))
378                 errout("%s: \"%s\" %s must be optional or standard\n",
379                     fname, wd, this);
380         for (wd = get_word(fp); wd; wd = get_word(fp)) {
381                 if (wd == (char *)EOF)
382                         return;
383                 if (eq(wd, "!")) {
384                         not = 1;
385                         continue;
386                 }
387                 if (eq(wd, "|")) {
388                         if (nreqs == 0)
389                                 errout("%s: syntax error describing %s\n",
390                                        fname, this);
391                         compile += match;
392                         match = 1;
393                         nreqs = 0;
394                         continue;
395                 }
396                 if (eq(wd, "no-obj")) {
397                         no_obj++;
398                         continue;
399                 }
400                 if (eq(wd, "no-implicit-rule")) {
401                         if (compilewith == NULL)
402                                 errout("%s: alternate rule required when "
403                                        "\"no-implicit-rule\" is specified for"
404                                        " %s.\n",
405                                        fname, this);
406                         imp_rule++;
407                         continue;
408                 }
409                 if (eq(wd, "before-depend")) {
410                         before_depend++;
411                         continue;
412                 }
413                 if (eq(wd, "dependency")) {
414                         wd = get_quoted_word(fp);
415                         if (wd == (char *)EOF || wd == NULL)
416                                 errout("%s: %s missing dependency string.\n",
417                                        fname, this);
418                         depends = ns(wd);
419                         continue;
420                 }
421                 if (eq(wd, "clean")) {
422                         wd = get_quoted_word(fp);
423                         if (wd == (char *)EOF || wd == NULL)
424                                 errout("%s: %s missing clean file list.\n",
425                                        fname, this);
426                         clean = ns(wd);
427                         continue;
428                 }
429                 if (eq(wd, "compile-with")) {
430                         wd = get_quoted_word(fp);
431                         if (wd == (char *)EOF || wd == NULL)
432                                 errout("%s: %s missing compile command string.\n",
433                                        fname, this);
434                         compilewith = ns(wd);
435                         continue;
436                 }
437                 if (eq(wd, "warning")) {
438                         wd = get_quoted_word(fp);
439                         if (wd == (char *)EOF || wd == NULL)
440                                 errout("%s: %s missing warning text string.\n",
441                                        fname, this);
442                         warning = ns(wd);
443                         continue;
444                 }
445                 if (eq(wd, "obj-prefix")) {
446                         wd = get_quoted_word(fp);
447                         if (wd == (char *)EOF || wd == NULL)
448                                 errout("%s: %s missing object prefix string.\n",
449                                        fname, this);
450                         objprefix = ns(wd);
451                         continue;
452                 }
453                 if (eq(wd, "nowerror")) {
454                         nowerror = 1;
455                         continue;
456                 }
457                 if (eq(wd, "local")) {
458                         filetype = LOCAL;
459                         continue;
460                 }
461                 if (eq(wd, "no-depend")) {
462                         filetype = NODEPEND;
463                         continue;
464                 }
465                 nreqs++;
466                 if (eq(wd, "profiling-routine")) {
467                         filetype = PROFILING;
468                         continue;
469                 }
470                 if (std)
471                         errout("standard entry %s has optional inclusion specifier %s!\n",
472                                this, wd);
473                 STAILQ_FOREACH(dp, &dtab, d_next)
474                         if (eq(dp->d_name, wd)) {
475                                 if (not)
476                                         match = 0;
477                                 else
478                                         dp->d_done |= DEVDONE;
479                                 goto nextparam;
480                         }
481                 SLIST_FOREACH(op, &opt, op_next)
482                         if (op->op_value == 0 && opteq(op->op_name, wd)) {
483                                 if (not)
484                                         match = 0;
485                                 goto nextparam;
486                         }
487                 match &= not;
488 nextparam:;
489                 not = 0;
490         }
491         compile += match;
492         if (compile && tp == NULL) {
493                 if (std == 0 && nreqs == 0)
494                         errout("%s: what is %s optional on?\n",
495                                fname, this);
496                 if (filetype == PROFILING && profiling == 0)
497                         goto next;
498                 tp = new_fent();
499                 tp->f_fn = this;
500                 tp->f_type = filetype;
501                 if (filetype == LOCAL)
502                         tp->f_srcprefix = "";
503                 else
504                         tp->f_srcprefix = "$S/";
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_compilewith = compilewith;
514                 tp->f_depends = depends;
515                 tp->f_clean = clean;
516                 tp->f_warn = warning;
517                 tp->f_objprefix = objprefix;
518         }
519         goto next;
520 }
521
522 /*
523  * Read in the information about files used in making the system.
524  * Store it in the ftab linked list.
525  */
526 static void
527 read_files(void)
528 {
529         char fname[MAXPATHLEN];
530         struct files_name *nl, *tnl;
531         
532         (void) snprintf(fname, sizeof(fname), "../../conf/files");
533         read_file(fname);
534         (void) snprintf(fname, sizeof(fname),
535                         "../../conf/files.%s", machinename);
536         read_file(fname);
537         for (nl = STAILQ_FIRST(&fntab); nl != NULL; nl = tnl) {
538                 read_file(nl->f_name);
539                 tnl = STAILQ_NEXT(nl, f_next);
540                 free(nl->f_name);
541                 free(nl);
542         }
543 }
544
545 static int
546 opteq(const char *cp, const char *dp)
547 {
548         char c, d;
549
550         for (; ; cp++, dp++) {
551                 if (*cp != *dp) {
552                         c = isupper(*cp) ? tolower(*cp) : *cp;
553                         d = isupper(*dp) ? tolower(*dp) : *dp;
554                         if (c != d)
555                                 return (0);
556                 }
557                 if (*cp == 0)
558                         return (1);
559         }
560 }
561
562 static void
563 do_before_depend(FILE *fp)
564 {
565         struct file_list *tp;
566         int lpos, len;
567
568         fputs("BEFORE_DEPEND=", fp);
569         lpos = 15;
570         STAILQ_FOREACH(tp, &ftab, f_next)
571                 if (tp->f_flags & BEFORE_DEPEND) {
572                         len = strlen(tp->f_fn);
573                         if ((len = 3 + len) + lpos > 72) {
574                                 lpos = 8;
575                                 fputs("\\\n\t", fp);
576                         }
577                         if (tp->f_flags & NO_IMPLCT_RULE)
578                                 fprintf(fp, "%s ", tp->f_fn);
579                         else
580                                 fprintf(fp, "%s%s ", tp->f_srcprefix,
581                                     tp->f_fn);
582                         lpos += len + 1;
583                 }
584         if (lpos != 8)
585                 putc('\n', fp);
586 }
587
588 static void
589 do_objs(FILE *fp)
590 {
591         struct file_list *tp;
592         int lpos, len;
593         char *cp, och, *sp;
594
595         fprintf(fp, "OBJS=");
596         lpos = 6;
597         STAILQ_FOREACH(tp, &ftab, f_next) {
598                 if (tp->f_flags & NO_OBJ)
599                         continue;
600                 sp = tail(tp->f_fn);
601                 cp = sp + (len = strlen(sp)) - 1;
602                 och = *cp;
603                 *cp = 'o';
604                 len += strlen(tp->f_objprefix);
605                 if (len + lpos > 72) {
606                         lpos = 8;
607                         fprintf(fp, "\\\n\t");
608                 }
609                 fprintf(fp, "%s%s ", tp->f_objprefix, 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         free(SUFF);
634         lpos = 8;
635         STAILQ_FOREACH(tp, &ftab, f_next)
636                 if (tp->f_type != NODEPEND) {
637                         len = strlen(tp->f_fn);
638                         if (tp->f_fn[len - slen - 1] != '.')
639                                 continue;
640                         if (strcasecmp(&tp->f_fn[len - slen], suff) != 0)
641                                 continue;
642                         if ((len = 3 + len) + lpos > 72) {
643                                 lpos = 8;
644                                 fputs("\\\n\t", fp);
645                         }
646                         fprintf(fp, "%s%s ", tp->f_srcprefix, tp->f_fn);
647                         lpos += len + 1;
648                 }
649         free(suff);
650         if (lpos != 8)
651                 putc('\n', fp);
652 }
653
654 static char *
655 tail(char *fn)
656 {
657         char *cp;
658
659         cp = strrchr(fn, '/');
660         if (cp == NULL)
661                 return (fn);
662         return (cp+1);
663 }
664
665 /*
666  * Create the makerules for each file
667  * which is part of the system.
668  */
669 static void
670 do_rules(FILE *f)
671 {
672         char *cp, *np, och;
673         struct file_list *ftp;
674         char *compilewith;
675         char cmd[128];
676
677         STAILQ_FOREACH(ftp, &ftab, f_next) {
678                 if (ftp->f_warn)
679                         fprintf(stderr, "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: %s\n",
685                                         ftp->f_objprefix, np, ftp->f_depends);
686                         else
687                                 fprintf(f, "%s%s: \n", ftp->f_objprefix, np);
688                 }
689                 else {
690                         *cp = '\0';
691                         if (och == 'o') {
692                                 fprintf(f, "%s%so:\n\t-cp %s%so .\n\n",
693                                         ftp->f_objprefix, tail(np),
694                                         ftp->f_srcprefix, np);
695                                 continue;
696                         }
697                         if (ftp->f_depends) {
698                                 fprintf(f, "%s%so: %s%s%c %s\n",
699                                         ftp->f_objprefix, tail(np),
700                                         ftp->f_srcprefix, np, och,
701                                         ftp->f_depends);
702                         }
703                         else {
704                                 fprintf(f, "%s%so: %s%s%c\n",
705                                         ftp->f_objprefix, tail(np),
706                                         ftp->f_srcprefix, np, och);
707                         }
708                 }
709                 compilewith = ftp->f_compilewith;
710                 if (compilewith == NULL) {
711                         const char *ftype = NULL;
712
713                         switch (ftp->f_type) {
714                         case NORMAL:
715                                 ftype = "NORMAL";
716                                 break;
717                         case PROFILING:
718                                 if (!profiling)
719                                         continue;
720                                 ftype = "PROFILE";
721                                 break;
722                         default:
723                                 fprintf(stderr,
724                                     "config: don't know rules for %s\n", np);
725                                 break;
726                         }
727                         snprintf(cmd, sizeof(cmd),
728                             "${%s_%c%s}", ftype,
729                             toupper(och),
730                             ftp->f_flags & NOWERROR ? "_NOWERROR" : "");
731                         compilewith = cmd;
732                 }
733                 *cp = och;
734                 if (strlen(ftp->f_objprefix))
735                         fprintf(f, "\t%s %s%s\n", compilewith,
736                             ftp->f_srcprefix, np);
737                 else
738                         fprintf(f, "\t%s\n", compilewith);
739
740                 if (!(ftp->f_flags & NO_OBJ))
741                         fprintf(f, "\t${NORMAL_CTFCONVERT}\n\n");
742                 else
743                         fprintf(f, "\n");
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 }