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