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