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