]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/config/mkmakefile.c
This commit was generated by cvs2svn to compensate for changes in r128345,
[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  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by the University of
16  *      California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33
34 #ifndef lint
35 #if 0
36 static char sccsid[] = "@(#)mkmakefile.c        8.1 (Berkeley) 6/6/93";
37 #endif
38 static const char rcsid[] =
39   "$FreeBSD$";
40 #endif /* not lint */
41
42 /*
43  * Build the makefile for the system, from
44  * the information in the files files and the
45  * additional files for the machine being compiled to.
46  */
47
48 #include <ctype.h>
49 #include <err.h>
50 #include <stdio.h>
51 #include <string.h>
52 #include <sys/param.h>
53 #include "y.tab.h"
54 #include "config.h"
55 #include "configvers.h"
56
57 #define next_word(fp, wd) \
58         { char *word = get_word(fp); \
59           if (word == (char *)EOF) \
60                 return; \
61           else \
62                 wd = word; \
63         }
64 #define next_quoted_word(fp, wd) \
65         { char *word = get_quoted_word(fp); \
66           if (word == (char *)EOF) \
67                 return; \
68           else \
69                 wd = word; \
70         }
71
72 static char *tail(char *);
73 static void do_clean(FILE *);
74 static void do_rules(FILE *);
75 static void do_xxfiles(char *, FILE *);
76 static void do_objs(FILE *);
77 static void do_before_depend(FILE *);
78 static int opteq(const char *, const char *);
79 static void read_files(void);
80
81 /*
82  * Lookup a file, by name.
83  */
84 static struct file_list *
85 fl_lookup(char *file)
86 {
87         struct file_list *fp;
88
89         STAILQ_FOREACH(fp, &ftab, f_next) {
90                 if (eq(fp->f_fn, file))
91                         return (fp);
92         }
93         return (0);
94 }
95
96 /*
97  * Make a new file list entry
98  */
99 static struct file_list *
100 new_fent(void)
101 {
102         struct file_list *fp;
103
104         fp = (struct file_list *) malloc(sizeof *fp);
105         bzero(fp, sizeof *fp);
106         STAILQ_INSERT_TAIL(&ftab, fp, f_next);
107         return (fp);
108 }
109
110 /*
111  * Build the makefile from the skeleton
112  */
113 void
114 makefile(void)
115 {
116         FILE *ifp, *ofp;
117         char line[BUFSIZ];
118         struct opt *op;
119         int versreq;
120         char *s;
121
122         read_files();
123         snprintf(line, sizeof(line), "../../conf/Makefile.%s", machinename);
124         ifp = fopen(line, "r");
125         if (ifp == 0) {
126                 snprintf(line, sizeof(line), "Makefile.%s", machinename);
127                 ifp = fopen(line, "r");
128         }
129         if (ifp == 0)
130                 err(1, "%s", line);
131
132         /* XXX this check seems to be misplaced. */
133         if (SLIST_EMPTY(&cputype)) {
134                 printf("cpu type must be specified\n");
135                 exit(1);
136         }
137
138         ofp = fopen(path("Makefile.new"), "w");
139         if (ofp == 0)
140                 err(1, "%s", path("Makefile.new"));
141         fprintf(ofp, "KERN_IDENT=%s\n", ident);
142         SLIST_FOREACH(op, &mkopt, op_next)
143                 fprintf(ofp, "%s=%s\n", op->op_name, op->op_value);
144         if (debugging)
145                 fprintf(ofp, "DEBUG=-g\n");
146         if (profiling)
147                 fprintf(ofp, "PROFLEVEL=%d\n", profiling);
148         if (*srcdir != '\0')
149                 fprintf(ofp,"S=%s\n", srcdir);
150         while (fgets(line, BUFSIZ, ifp) != 0) {
151                 if (*line != '%') {
152                         fprintf(ofp, "%s", line);
153                         continue;
154                 }
155                 if (eq(line, "%BEFORE_DEPEND\n"))
156                         do_before_depend(ofp);
157                 else if (eq(line, "%OBJS\n"))
158                         do_objs(ofp);
159                 else if (strncmp(line, "%FILES.", 7) == 0)
160                         do_xxfiles(line, ofp);
161                 else if (eq(line, "%RULES\n"))
162                         do_rules(ofp);
163                 else if (eq(line, "%CLEAN\n"))
164                         do_clean(ofp);
165                 else if (strncmp(line, "%VERSREQ=", sizeof("%VERSREQ=") - 1) == 0) {
166                         versreq = atoi(line + sizeof("%VERSREQ=") - 1);
167                         if (versreq != CONFIGVERS) {
168                                 fprintf(stderr, "ERROR: version of config(8) does not match kernel!\n");
169                                 fprintf(stderr, "config version = %d, ", CONFIGVERS);
170                                 fprintf(stderr, "version required = %d\n\n", versreq);
171                                 fprintf(stderr, "Make sure that /usr/src/usr.sbin/config is in sync\n");
172                                 fprintf(stderr, "with your /usr/src/sys and install a new config binary\n");
173                                 fprintf(stderr, "before trying this again.\n\n");
174                                 fprintf(stderr, "If running the new config fails check your config\n");
175                                 fprintf(stderr, "file against the GENERIC or LINT config files for\n");
176                                 fprintf(stderr, "changes in config syntax, or option/device naming\n");
177                                 fprintf(stderr, "conventions\n\n");
178                                 exit(1);
179                         }
180                 } else
181                         fprintf(stderr,
182                             "Unknown %% construct in generic makefile: %s",
183                             line);
184         }
185         (void) fclose(ifp);
186         (void) fclose(ofp);
187         moveifchanged(path("Makefile.new"), path("Makefile"));
188
189         /* XXX makefile() should make the Makefile, not hints.c. */
190         if (hints) {
191                 ifp = fopen(hints, "r");
192                 if (ifp == NULL)
193                         err(1, "%s", hints);
194         } else {
195                 ifp = NULL;
196         }
197         ofp = fopen(path("hints.c.new"), "w");
198         if (ofp == NULL)
199                 err(1, "%s", path("hints.c.new"));
200         fprintf(ofp, "#include <sys/types.h>\n");
201         fprintf(ofp, "#include <sys/systm.h>\n");
202         fprintf(ofp, "\n");
203         fprintf(ofp, "int hintmode = %d;\n", hintmode);
204         fprintf(ofp, "char static_hints[] = {\n");
205         if (ifp) {
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         }
236         fprintf(ofp, "\"\\0\"\n};\n");
237         if (ifp)
238                 fclose(ifp);
239         fclose(ofp);
240         moveifchanged(path("hints.c.new"), path("hints.c"));
241
242         /* XXX makefile() should make the Makefile, not env.c. */
243         if (env) {
244                 ifp = fopen(env, "r");
245                 if (ifp == NULL)
246                         err(1, "%s", env);
247         } else {
248                 ifp = NULL;
249         }
250         ofp = fopen(path("env.c.new"), "w");
251         if (ofp == NULL)
252                 err(1, "%s", path("env.c.new"));
253         fprintf(ofp, "#include <sys/types.h>\n");
254         fprintf(ofp, "#include <sys/systm.h>\n");
255         fprintf(ofp, "\n");
256         fprintf(ofp, "int envmode = %d;\n", envmode);
257         fprintf(ofp, "char static_env[] = {\n");
258         if (ifp) {
259                 while (fgets(line, BUFSIZ, ifp) != 0) {
260                         /* zap trailing CR and/or LF */
261                         while ((s = rindex(line, '\n')) != NULL)
262                                 *s = '\0';
263                         while ((s = rindex(line, '\r')) != NULL)
264                                 *s = '\0';
265                         /* remove # comments */
266                         s = index(line, '#');
267                         if (s)
268                                 *s = '\0';
269                         /* remove any whitespace and " characters */
270                         s = line;
271                         while (*s) {
272                                 if (*s == ' ' || *s == '\t' || *s == '"') {
273                                         while (*s) {
274                                                 s[0] = s[1];
275                                                 s++;
276                                         }
277                                         /* start over */
278                                         s = line;
279                                         continue;
280                                 }
281                                 s++;
282                         }
283                         /* anything left? */
284                         if (*line == '\0')
285                                 continue;
286                         fprintf(ofp, "\"%s\\0\"\n", line);
287                 }
288         }
289         fprintf(ofp, "\"\\0\"\n};\n");
290         if (ifp)
291                 fclose(ifp);
292         fclose(ofp);
293         moveifchanged(path("env.c.new"), path("env.c"));
294 }
295
296 /*
297  * Read in the information about files used in making the system.
298  * Store it in the ftab linked list.
299  */
300 static void
301 read_files(void)
302 {
303         FILE *fp;
304         struct file_list *tp, *pf;
305         struct device *dp;
306         struct opt *op;
307         char *wd, *this, *needs, *compilewith, *depends, *clean, *warning;
308         char fname[MAXPATHLEN];
309         int nreqs, first = 1, isdup, std, filetype,
310             imp_rule, no_obj, needcount, before_depend, mandatory, nowerror;
311
312         STAILQ_INIT(&ftab);
313         if (ident == NULL) {
314                 printf("no ident line specified\n");
315                 exit(1);
316         }
317         (void) snprintf(fname, sizeof(fname), "../../conf/files");
318 openit:
319         fp = fopen(fname, "r");
320         if (fp == 0)
321                 err(1, "%s", fname);
322 next:
323         /*
324          * filename    [ standard | mandatory | optional | count ]
325          *      [ dev* | profiling-routine ] [ no-obj ]
326          *      [ compile-with "compile rule" [no-implicit-rule] ]
327          *      [ dependency "dependency-list"] [ before-depend ]
328          *      [ clean "file-list"] [ warning "text warning" ]
329          */
330         wd = get_word(fp);
331         if (wd == (char *)EOF) {
332                 (void) fclose(fp);
333                 if (first == 1) {
334                         first++;
335                         (void) snprintf(fname, sizeof(fname),
336                             "../../conf/files.%s", machinename);
337                         fp = fopen(fname, "r");
338                         if (fp != 0)
339                                 goto next;
340                         (void) snprintf(fname, sizeof(fname),
341                             "files.%s", machinename);
342                         goto openit;
343                 }
344                 return;
345         }
346         if (wd == 0)
347                 goto next;
348         if (wd[0] == '#')
349         {
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         if ((pf = fl_lookup(this)) && (pf->f_type != INVISIBLE || pf->f_flags))
362                 isdup = ISDUP;
363         else
364                 isdup = 0;
365         tp = 0;
366         nreqs = 0;
367         compilewith = 0;
368         depends = 0;
369         clean = 0;
370         warning = 0;
371         needs = 0;
372         std = mandatory = 0;
373         imp_rule = 0;
374         no_obj = 0;
375         needcount = 0;
376         before_depend = 0;
377         nowerror = 0;
378         filetype = NORMAL;
379         if (eq(wd, "standard")) {
380                 std = 1;
381         /*
382          * If an entry is marked "mandatory", config will abort if it's
383          * not called by a configuration line in the config file.  Apart
384          * from this, the device is handled like one marked "optional".
385          */
386         } else if (eq(wd, "mandatory")) {
387                 mandatory = 1;
388         } else if (eq(wd, "count")) {
389                 needcount = 1;
390         } else if (!eq(wd, "optional")) {
391                 printf("%s: %s must be count, optional, mandatory or standard\n",
392                        fname, this);
393                 exit(1);
394         }
395 nextparam:
396         next_word(fp, wd);
397         if (wd == 0) {
398                 if (isdup)
399                         goto next;
400                 goto doneparam;
401         }
402         if (eq(wd, "no-obj")) {
403                 no_obj++;
404                 goto nextparam;
405         }
406         if (eq(wd, "no-implicit-rule")) {
407                 if (compilewith == 0) {
408                         printf("%s: alternate rule required when "
409                                "\"no-implicit-rule\" is specified.\n",
410                                fname);
411                 }
412                 imp_rule++;
413                 goto nextparam;
414         }
415         if (eq(wd, "before-depend")) {
416                 before_depend++;
417                 goto nextparam;
418         }
419         if (eq(wd, "dependency")) {
420                 next_quoted_word(fp, wd);
421                 if (wd == 0) {
422                         printf("%s: %s missing compile command string.\n",
423                                fname, this);
424                         exit(1);
425                 }
426                 depends = ns(wd);
427                 goto nextparam;
428         }
429         if (eq(wd, "clean")) {
430                 next_quoted_word(fp, wd);
431                 if (wd == 0) {
432                         printf("%s: %s missing clean file list.\n",
433                                fname, this);
434                         exit(1);
435                 }
436                 clean = ns(wd);
437                 goto nextparam;
438         }
439         if (eq(wd, "compile-with")) {
440                 next_quoted_word(fp, wd);
441                 if (wd == 0) {
442                         printf("%s: %s missing compile command string.\n",
443                                fname, this);
444                         exit(1);
445                 }
446                 compilewith = ns(wd);
447                 goto nextparam;
448         }
449         if (eq(wd, "warning")) {
450                 next_quoted_word(fp, wd);
451                 if (wd == 0) {
452                         printf("%s: %s missing warning text string.\n",
453                                 fname, this);
454                         exit(1);
455                 }
456                 warning = ns(wd);
457                 goto nextparam;
458         }
459         nreqs++;
460         if (eq(wd, "local")) {
461                 filetype = LOCAL;
462                 goto nextparam;
463         }
464         if (eq(wd, "no-depend")) {
465                 filetype = NODEPEND;
466                 goto nextparam;
467         }
468         if (eq(wd, "profiling-routine")) {
469                 filetype = PROFILING;
470                 goto nextparam;
471         }
472         if (eq(wd, "nowerror")) {
473                 nowerror = 1;
474                 goto nextparam;
475         }
476         if (needs == 0 && nreqs == 1)
477                 needs = ns(wd);
478         if (isdup)
479                 goto invis;
480         STAILQ_FOREACH(dp, &dtab, d_next)
481                 if (eq(dp->d_name, wd)) {
482                         if (std && dp->d_count <= 0)
483                                 dp->d_count = 1;
484                         goto nextparam;
485                 }
486         if (mandatory) {
487                 printf("%s: mandatory device \"%s\" not found\n",
488                        fname, wd);
489                 exit(1);
490         }
491         if (std) {
492                 printf("standard entry %s has a device keyword - %s!\n",
493                        this, wd);
494                 exit(1);
495         }
496         SLIST_FOREACH(op, &opt, op_next)
497                 if (op->op_value == 0 && opteq(op->op_name, wd)) {
498                         if (nreqs == 1) {
499                                 free(needs);
500                                 needs = 0;
501                         }
502                         goto nextparam;
503                 }
504 invis:
505         while ((wd = get_word(fp)) != 0)
506                 ;
507         if (tp == 0)
508                 tp = new_fent();
509         tp->f_fn = this;
510         tp->f_type = INVISIBLE;
511         tp->f_needs = needs;
512         tp->f_flags |= isdup;
513         if (needcount)
514                 tp->f_flags |= NEED_COUNT;
515         tp->f_compilewith = compilewith;
516         tp->f_depends = depends;
517         tp->f_clean = clean;
518         tp->f_warn = warning;
519         goto next;
520
521 doneparam:
522         if (std == 0 && nreqs == 0) {
523                 printf("%s: what is %s optional on?\n",
524                     fname, this);
525                 exit(1);
526         }
527
528         if (wd) {
529                 printf("%s: syntax error describing %s\n",
530                     fname, this);
531                 exit(1);
532         }
533         if (filetype == PROFILING && profiling == 0)
534                 goto next;
535         if (tp == 0)
536                 tp = new_fent();
537         tp->f_fn = this;
538         tp->f_type = filetype;
539         tp->f_flags &= ~ISDUP;
540         if (imp_rule)
541                 tp->f_flags |= NO_IMPLCT_RULE;
542         if (no_obj)
543                 tp->f_flags |= NO_OBJ;
544         if (before_depend)
545                 tp->f_flags |= BEFORE_DEPEND;
546         if (needcount)
547                 tp->f_flags |= NEED_COUNT;
548         if (nowerror)
549                 tp->f_flags |= NOWERROR;
550         tp->f_needs = needs;
551         tp->f_compilewith = compilewith;
552         tp->f_depends = depends;
553         tp->f_clean = clean;
554         tp->f_warn = warning;
555         if (pf && pf->f_type == INVISIBLE)
556                 pf->f_flags |= ISDUP;           /* mark as duplicate */
557         goto next;
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 }