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