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