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