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