Annotation of 42BSD/etc/config/mkmakefile.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)mkmakefile.c       1.30 (Berkeley) 8/11/83";
                      3: #endif
                      4: 
                      5: /*
                      6:  * Build the makefile for the system, from
                      7:  * the information in the files files and the
                      8:  * additional files for the machine being compiled to.
                      9:  */
                     10: 
                     11: #include <stdio.h>
                     12: #include <ctype.h>
                     13: #include "y.tab.h"
                     14: #include "config.h"
                     15: 
                     16: #define next_word(fp, wd) \
                     17:        { register char *word = get_word(fp); \
                     18:          if (word == (char *)EOF) \
                     19:                return; \
                     20:          else \
                     21:                wd = word; \
                     22:        }
                     23: 
                     24: static struct file_list *fcur;
                     25: char *tail();
                     26: 
                     27: /*
                     28:  * Lookup a file, by make.
                     29:  */
                     30: struct file_list *
                     31: fl_lookup(file)
                     32:        register char *file;
                     33: {
                     34:        register struct file_list *fp;
                     35: 
                     36:        for (fp = ftab ; fp != 0; fp = fp->f_next) {
                     37:                if (eq(fp->f_fn, file))
                     38:                        return (fp);
                     39:        }
                     40:        return (0);
                     41: }
                     42: 
                     43: /*
                     44:  * Lookup a file, by final component name.
                     45:  */
                     46: struct file_list *
                     47: fltail_lookup(file)
                     48:        register char *file;
                     49: {
                     50:        register struct file_list *fp;
                     51: 
                     52:        for (fp = ftab ; fp != 0; fp = fp->f_next) {
                     53:                if (eq(tail(fp->f_fn), tail(file)))
                     54:                        return (fp);
                     55:        }
                     56:        return (0);
                     57: }
                     58: 
                     59: /*
                     60:  * Make a new file list entry
                     61:  */
                     62: struct file_list *
                     63: new_fent()
                     64: {
                     65:        register struct file_list *fp;
                     66: 
                     67:        fp = (struct file_list *) malloc(sizeof *fp);
                     68:        fp->f_needs = 0;
                     69:        fp->f_next = 0;
                     70:        fp->f_flags = 0;
                     71:        fp->f_type = 0;
                     72:        if (fcur == 0)
                     73:                fcur = ftab = fp;
                     74:        else
                     75:                fcur->f_next = fp;
                     76:        fcur = fp;
                     77:        return (fp);
                     78: }
                     79: 
                     80: char   *COPTS;
                     81: 
                     82: /*
                     83:  * Build the makefile from the skeleton
                     84:  */
                     85: makefile()
                     86: {
                     87:        FILE *ifp, *ofp;
                     88:        char line[BUFSIZ];
                     89:        struct opt *op;
                     90: 
                     91:        read_files();
                     92:        strcpy(line, "../conf/makefile.");
                     93:        (void) strcat(line, machinename);
                     94:        ifp = fopen(line, "r");
                     95:        if (ifp == 0) {
                     96:                perror(line);
                     97:                exit(1);
                     98:        }
                     99:        ofp = fopen(path("makefile"), "w");
                    100:        if (ofp == 0) {
                    101:                perror(path("makefile"));
                    102:                exit(1);
                    103:        }
                    104:        fprintf(ofp, "IDENT=-D%s", raise(ident));
                    105:        if (profiling)
                    106:                fprintf(ofp, " -DGPROF");
                    107:        if (cputype == 0) {
                    108:                printf("cpu type must be specified\n");
                    109:                exit(1);
                    110:        }
                    111:        { struct cputype *cp;
                    112:          for (cp = cputype; cp; cp = cp->cpu_next)
                    113:                fprintf(ofp, " -D%s", cp->cpu_name);
                    114:        }
                    115:        for (op = opt; op; op = op->op_next)
                    116:                if (op->op_value)
                    117:                        fprintf(ofp, " -D%s=\"%s\"", op->op_name, op->op_value);
                    118:                else
                    119:                        fprintf(ofp, " -D%s", op->op_name);
                    120:        fprintf(ofp, "\n");
                    121:        if (hadtz == 0)
                    122:                printf("timezone not specified; gmt assumed\n");
                    123: #ifdef vax
                    124:        if (maxusers == 0) {
                    125:                printf("maxusers not specified; 24 assumed\n");
                    126:                maxusers = 24;
                    127:        } else if (maxusers < 8) {
                    128:                printf("minimum of 8 maxusers assumed\n");
                    129:                maxusers = 8;
                    130:        } else if (maxusers > 128) {
                    131:                printf("maxusers truncated to 128\n");
                    132:                maxusers = 128;
                    133:        }
                    134: #endif
                    135: #ifdef sun
                    136:        if (maxusers == 0) {
                    137:                printf("maxusers not specified; 8 assumed\n");
                    138:                maxusers = 8;
                    139:        } else if (maxusers < 2) {
                    140:                printf("minimum of 2 maxusers assumed\n");
                    141:                maxusers = 2;
                    142:        } else if (maxusers > 32) {
                    143:                printf("maxusers truncated to 32\n");
                    144:                maxusers = 32;
                    145:        }
                    146: #endif
                    147:        fprintf(ofp, "PARAM=-DTIMEZONE=%d -DDST=%d -DMAXUSERS=%d\n",
                    148:            timezone, dst, maxusers);
                    149:        while (fgets(line, BUFSIZ, ifp) != 0) {
                    150:                if (*line == '%')
                    151:                        goto percent;
                    152:                if (profiling && strncmp(line, "COPTS=", 6) == 0) {
                    153:                        register char *cp;
                    154: 
                    155:                        fprintf(ofp, 
                    156:                            "GPROF.EX=/usr/src/lib/libc/%s/csu/gmon.ex\n",
                    157:                            machinename);
                    158:                        cp = index(line, '\n');
                    159:                        if (cp)
                    160:                                *cp = 0;
                    161:                        cp = line + 6;
                    162:                        while (*cp && (*cp == ' ' || *cp == '\t'))
                    163:                                cp++;
                    164:                        COPTS = malloc((unsigned)(strlen(cp) + 1));
                    165:                        if (COPTS == 0) {
                    166:                                printf("config: out of memory\n");
                    167:                                exit(1);
                    168:                        }
                    169:                        strcpy(COPTS, cp);
                    170:                        fprintf(ofp, "%s -pg\n", line);
                    171:                        continue;
                    172:                }
                    173:                fprintf(ofp, "%s", line);
                    174:                continue;
                    175:        percent:
                    176:                if (eq(line, "%OBJS\n"))
                    177:                        do_objs(ofp);
                    178:                else if (eq(line, "%CFILES\n"))
                    179:                        do_cfiles(ofp);
                    180:                else if (eq(line, "%RULES\n"))
                    181:                        do_rules(ofp);
                    182:                else if (eq(line, "%LOAD\n"))
                    183:                        do_load(ofp);
                    184:                else
                    185:                        fprintf(stderr,
                    186:                            "Unknown %% construct in generic makefile: %s",
                    187:                            line);
                    188:        }
                    189:        (void) fclose(ifp);
                    190:        (void) fclose(ofp);
                    191: }
                    192: 
                    193: /*
                    194:  * Read in the information about files used in making the system.
                    195:  * Store it in the ftab linked list.
                    196:  */
                    197: read_files()
                    198: {
                    199:        FILE *fp;
                    200:        register struct file_list *tp;
                    201:        register struct device *dp;
                    202:        char *wd, *this, *needs, *devorprof;
                    203:        char fname[32];
                    204:        int nreqs, first = 1, configdep;
                    205: 
                    206:        ftab = 0;
                    207:        (void) strcpy(fname, "files");
                    208: openit:
                    209:        fp = fopen(fname, "r");
                    210:        if (fp == 0) {
                    211:                perror(fname);
                    212:                exit(1);
                    213:        }
                    214: next:
                    215:        /*
                    216:         * filename     [ standard | optional ] [ config-dependent ]
                    217:         *      [ dev* | profiling-routine ] [ device-driver]
                    218:         */
                    219:        wd = get_word(fp);
                    220:        if (wd == (char *)EOF) {
                    221:                (void) fclose(fp);
                    222:                if (first == 1) {
                    223:                        (void) sprintf(fname, "files.%s", machinename);
                    224:                        first++;
                    225:                        goto openit;
                    226:                }
                    227:                if (first == 2) {
                    228:                        (void) sprintf(fname, "files.%s", raise(ident));
                    229:                        first++;
                    230:                        fp = fopen(fname, "r");
                    231:                        if (fp != 0)
                    232:                                goto next;
                    233:                }
                    234:                return;
                    235:        }
                    236:        if (wd == 0)
                    237:                goto next;
                    238:        this = ns(wd);
                    239:        next_word(fp, wd);
                    240:        if (wd == 0) {
                    241:                printf("%s: No type for %s.\n",
                    242:                    fname, this);
                    243:                exit(1);
                    244:        }
                    245:        if (fl_lookup(this)) {
                    246:                printf("%s: Duplicate file %s.\n",
                    247:                    fname, this);
                    248:                exit(1);
                    249:        }
                    250:        tp = 0;
                    251:        if (first == 3 && (tp = fltail_lookup(this)) != 0)
                    252:                printf("%s: Local file %s overrides %s.\n",
                    253:                    fname, this, tp->f_fn);
                    254:        nreqs = 0;
                    255:        devorprof = "";
                    256:        configdep = 0;
                    257:        needs = 0;
                    258:        if (eq(wd, "standard"))
                    259:                goto checkdev;
                    260:        if (!eq(wd, "optional")) {
                    261:                printf("%s: %s must be optional or standard\n", fname, this);
                    262:                exit(1);
                    263:        }
                    264: nextopt:
                    265:        next_word(fp, wd);
                    266:        if (wd == 0)
                    267:                goto doneopt;
                    268:        if (eq(wd, "config-dependent")) {
                    269:                configdep++;
                    270:                goto nextopt;
                    271:        }
                    272:        devorprof = wd;
                    273:        if (eq(wd, "device-driver") || eq(wd, "profiling-routine")) {
                    274:                next_word(fp, wd);
                    275:                goto save;
                    276:        }
                    277:        nreqs++;
                    278:        if (needs == 0)
                    279:                needs = ns(wd);
                    280:        for (dp = dtab; dp != 0; dp = dp->d_next)
                    281:                if (eq(dp->d_name, wd))
                    282:                        goto nextopt;
                    283:        while ((wd = get_word(fp)) != 0)
                    284:                ;
                    285:        if (tp == 0)
                    286:                tp = new_fent();
                    287:        tp->f_fn = this;
                    288:        tp->f_type = INVISIBLE;
                    289:        tp->f_needs = needs;
                    290:        goto next;
                    291: 
                    292: doneopt:
                    293:        if (nreqs == 0) {
                    294:                printf("%s: what is %s optional on?\n",
                    295:                    fname, this);
                    296:                exit(1);
                    297:        }
                    298: 
                    299: checkdev:
                    300:        if (wd) {
                    301:                next_word(fp, wd);
                    302:                if (wd) {
                    303:                        if (eq(wd, "config-dependent")) {
                    304:                                configdep++;
                    305:                                goto checkdev;
                    306:                        }
                    307:                        devorprof = wd;
                    308:                        next_word(fp, wd);
                    309:                }
                    310:        }
                    311: 
                    312: save:
                    313:        if (wd) {
                    314:                printf("%s: syntax error describing %s\n",
                    315:                    fname, this);
                    316:                exit(1);
                    317:        }
                    318:        if (eq(devorprof, "profiling-routine") && profiling == 0)
                    319:                goto next;
                    320:        if (tp == 0)
                    321:                tp = new_fent();
                    322:        tp->f_fn = this;
                    323:        if (eq(devorprof, "device-driver"))
                    324:                tp->f_type = DRIVER;
                    325:        else if (eq(devorprof, "profiling-routine"))
                    326:                tp->f_type = PROFILING;
                    327:        else
                    328:                tp->f_type = NORMAL;
                    329:        tp->f_flags = 0;
                    330:        if (configdep)
                    331:                tp->f_flags |= CONFIGDEP;
                    332:        tp->f_needs = needs;
                    333:        goto next;
                    334: }
                    335: 
                    336: do_objs(fp)
                    337:        FILE *fp;
                    338: {
                    339:        register struct file_list *tp, *fl;
                    340:        register int lpos, len;
                    341:        register char *cp, och, *sp;
                    342:        char swapname[32];
                    343: 
                    344:        fprintf(fp, "OBJS=");
                    345:        lpos = 6;
                    346:        for (tp = ftab; tp != 0; tp = tp->f_next) {
                    347:                if (tp->f_type == INVISIBLE)
                    348:                        continue;
                    349:                sp = tail(tp->f_fn);
                    350:                for (fl = conf_list; fl; fl = fl->f_next) {
                    351:                        if (fl->f_type != SWAPSPEC)
                    352:                                continue;
                    353:                        sprintf(swapname, "swap%s.c", fl->f_fn);
                    354:                        if (eq(sp, swapname))
                    355:                                goto cont;
                    356:                }
                    357:                cp = sp + (len = strlen(sp)) - 1;
                    358:                och = *cp;
                    359:                *cp = 'o';
                    360:                if (len + lpos > 72) {
                    361:                        lpos = 8;
                    362:                        fprintf(fp, "\\\n\t");
                    363:                }
                    364:                fprintf(fp, "%s ", sp);
                    365:                lpos += len + 1;
                    366:                *cp = och;
                    367: cont:
                    368:                ;
                    369:        }
                    370:        if (lpos != 8)
                    371:                putc('\n', fp);
                    372: }
                    373: 
                    374: do_cfiles(fp)
                    375:        FILE *fp;
                    376: {
                    377:        register struct file_list *tp;
                    378:        register int lpos, len;
                    379: 
                    380:        fprintf(fp, "CFILES=");
                    381:        lpos = 8;
                    382:        for (tp = ftab; tp != 0; tp = tp->f_next) {
                    383:                if (tp->f_type == INVISIBLE)
                    384:                        continue;
                    385:                if (tp->f_fn[strlen(tp->f_fn)-1] != 'c')
                    386:                        continue;
                    387:                if ((len = 3 + strlen(tp->f_fn)) + lpos > 72) {
                    388:                        lpos = 8;
                    389:                        fprintf(fp, "\\\n\t");
                    390:                }
                    391:                fprintf(fp, "../%s ", tp->f_fn);
                    392:                lpos += len + 1;
                    393:        }
                    394:        if (lpos != 8)
                    395:                putc('\n', fp);
                    396: }
                    397: 
                    398: char *
                    399: tail(fn)
                    400:        char *fn;
                    401: {
                    402:        register char *cp;
                    403: 
                    404:        cp = rindex(fn, '/');
                    405:        if (cp == 0)
                    406:                return (fn);
                    407:        return (cp+1);
                    408: }
                    409: 
                    410: /*
                    411:  * Create the makerules for each file
                    412:  * which is part of the system.
                    413:  * Devices are processed with the special c2 option -i
                    414:  * which avoids any problem areas with i/o addressing
                    415:  * (e.g. for the VAX); assembler files are processed by as.
                    416:  */
                    417: do_rules(f)
                    418:        FILE *f;
                    419: {
                    420:        register char *cp, *np, och, *tp;
                    421:        register struct file_list *ftp;
                    422:        char *extras;
                    423: 
                    424: for (ftp = ftab; ftp != 0; ftp = ftp->f_next) {
                    425:        if (ftp->f_type == INVISIBLE)
                    426:                continue;
                    427:        cp = (np = ftp->f_fn) + strlen(ftp->f_fn) - 1;
                    428:        och = *cp;
                    429:        *cp = '\0';
                    430:        fprintf(f, "%so: ../%s%c\n", tail(np), np, och);
                    431:        tp = tail(np);
                    432:        if (och == 's') {
                    433:                fprintf(f, "\t${AS} -o %so ../%ss\n\n", tp, np);
                    434:                continue;
                    435:        }
                    436:        if (ftp->f_flags & CONFIGDEP)
                    437:                extras = "${PARAM} ";
                    438:        else
                    439:                extras = "";
                    440:        switch (ftp->f_type) {
                    441: 
                    442:        case NORMAL:
                    443:                switch (machine) {
                    444: 
                    445:                case MACHINE_VAX:
                    446:                        fprintf(f, "\t${CC} -I. -c -S ${COPTS} %s../%sc\n",
                    447:                                extras, np);
                    448:                        fprintf(f, "\t${C2} %ss | sed -f ../%s/asm.sed |",
                    449:                            tp, machinename);
                    450:                        fprintf(f, " ${AS} -o %so\n", tp);
                    451:                        fprintf(f, "\trm -f %ss\n\n", tp);
                    452:                        break;
                    453: 
                    454:                case MACHINE_SUN:
                    455:                        fprintf(f, "\t${CC} -I. -c -O ${COPTS} %s../%sc\n\n",
                    456:                                extras, np);
                    457:                        break;
                    458:                }
                    459:                break;
                    460: 
                    461:        case DRIVER:
                    462:                switch (machine) {
                    463: 
                    464:                case MACHINE_VAX:
                    465:                        fprintf(f, "\t${CC} -I. -c -S ${COPTS} %s../%sc\n",
                    466:                                extras, np);
                    467:                        fprintf(f,"\t${C2} -i %ss | sed -f ../%s/asm.sed |",
                    468:                            tp, machinename);
                    469:                        fprintf(f, " ${AS} -o %so\n", tp);
                    470:                        fprintf(f, "\trm -f %ss\n\n", tp);
                    471:                        break;
                    472: 
                    473:                case MACHINE_SUN:
                    474:                        fprintf(f, "\t${CC} -I. -c -O ${COPTS} %s../%sc\n\n",
                    475:                                extras, np);
                    476:                }
                    477:                break;
                    478: 
                    479:        case PROFILING:
                    480:                if (!profiling)
                    481:                        continue;
                    482:                if (COPTS == 0) {
                    483:                        fprintf(stderr,
                    484:                            "config: COPTS undefined in generic makefile");
                    485:                        COPTS = "";
                    486:                }
                    487:                switch (machine) {
                    488: 
                    489:                case MACHINE_VAX:
                    490:                        fprintf(f, "\t${CC} -I. -c -S %s %s../%sc\n",
                    491:                                COPTS, extras, np);
                    492:                        fprintf(f, "\tex - %ss < ${GPROF.EX}\n", tp);
                    493:                        fprintf(f,
                    494:                            "\tsed -f ../vax/asm.sed %ss | ${AS} -o %so\n",
                    495:                            tp, tp);
                    496:                        fprintf(f, "\trm -f %ss\n\n", tp);
                    497:                        break;
                    498: 
                    499:                case MACHINE_SUN:
                    500:                        fprintf(stderr,
                    501:                            "config: don't know how to profile kernel on sun\n");
                    502:                        break;
                    503:                }
                    504:                break;
                    505: 
                    506:        default:
                    507:                printf("Don't know rules for %s\n", np);
                    508:                break;
                    509:        }
                    510:        *cp = och;
                    511: }
                    512: }
                    513: 
                    514: /*
                    515:  * Create the load strings
                    516:  */
                    517: do_load(f)
                    518:        register FILE *f;
                    519: {
                    520:        register struct file_list *fl;
                    521:        int first = 1;
                    522:        struct file_list *do_systemspec();
                    523: 
                    524:        fl = conf_list;
                    525:        while (fl) {
                    526:                if (fl->f_type != SYSTEMSPEC) {
                    527:                        fl = fl->f_next;
                    528:                        continue;
                    529:                }
                    530:                fl = do_systemspec(f, fl, first);
                    531:                if (first)
                    532:                        first = 0;
                    533:        }
                    534:        fprintf(f, "all:");
                    535:        for (fl = conf_list; fl != 0; fl = fl->f_next)
                    536:                if (fl->f_type == SYSTEMSPEC)
                    537:                        fprintf(f, " %s", fl->f_needs);
                    538:        fprintf(f, "\n");
                    539: }
                    540: 
                    541: struct file_list *
                    542: do_systemspec(f, fl, first)
                    543:        FILE *f;
                    544:        register struct file_list *fl;
                    545:        int first;
                    546: {
                    547: 
                    548:        fprintf(f, "%s: makefile locore.o ${OBJS} param.o", fl->f_needs);
                    549:        fprintf(f, " ioconf.o swap%s.o\n", fl->f_fn);
                    550:        fprintf(f, "\t@echo loading %s\n\t@rm -f %s\n",
                    551:            fl->f_needs, fl->f_needs);
                    552:        if (first) {
                    553:                fprintf(f, "\t@sh ../conf/newvers.sh\n");
                    554:                fprintf(f, "\t@${CC} $(CFLAGS) -c vers.c\n");
                    555:        }
                    556:        switch (machine) {
                    557: 
                    558:        case MACHINE_VAX:
                    559:                fprintf(f, "\t@${LD} -n -o %s -e start -x -T 80000000 ",
                    560:                        fl->f_needs);
                    561:                break;
                    562: 
                    563:        case MACHINE_SUN:
                    564:                fprintf(f, "\t@${LD} -o %s -e start -x -T 4000 ",
                    565:                        fl->f_needs);
                    566:                break;
                    567:        }
                    568:        fprintf(f, "locore.o ${OBJS} vers.o ioconf.o param.o ");
                    569:        fprintf(f, "swap%s.o\n", fl->f_fn);
                    570:        fprintf(f, "\t@echo rearranging symbols\n");
                    571:        fprintf(f, "\t@-symorder ../%s/symbols.sort %s\n",
                    572:            machinename, fl->f_needs);
                    573:        fprintf(f, "\t@size %s\n", fl->f_needs);
                    574:        fprintf(f, "\t@chmod 755 %s\n\n", fl->f_needs);
                    575:        do_swapspec(f, fl->f_fn);
                    576:        for (fl = fl->f_next; fl->f_type == SWAPSPEC; fl = fl->f_next)
                    577:                ;
                    578:        return (fl);
                    579: }
                    580: 
                    581: do_swapspec(f, name)
                    582:        FILE *f;
                    583:        register char *name;
                    584: {
                    585: 
                    586:        if (!eq(name, "generic")) {
                    587:                fprintf(f, "swap%s.o: swap%s.c\n", name, name);
                    588:                fprintf(f, "\t${CC} -I. -c -O ${COPTS} swap%s.c\n\n", name);
                    589:                return;
                    590:        }
                    591:        fprintf(f, "swapgeneric.o: ../%s/swapgeneric.c\n", machinename);
                    592:        switch (machine) {
                    593: 
                    594:        case MACHINE_VAX:
                    595:                fprintf(f, "\t${CC} -I. -c -S ${COPTS} ");
                    596:                fprintf(f, "../%s/swapgeneric.c\n", machinename);
                    597:                fprintf(f, "\t${C2} swapgeneric.s | sed -f ../%s/asm.sed",
                    598:                    machinename);
                    599:                fprintf(f, " | ${AS} -o swapgeneric.o\n");
                    600:                fprintf(f, "\trm -f swapgeneric.s\n\n");
                    601:                break;
                    602: 
                    603:        case MACHINE_SUN:
                    604:                fprintf(f, "\t${CC} -I. -c -O ${COPTS} ");
                    605:                fprintf(f, "../%s/swapgeneric.c\n\n", machinename);
                    606:                break;
                    607:        }
                    608: }
                    609: 
                    610: char *
                    611: raise(str)
                    612:        register char *str;
                    613: {
                    614:        register char *cp = str;
                    615: 
                    616:        while (*str) {
                    617:                if (islower(*str))
                    618:                        *str = toupper(*str);
                    619:                str++;
                    620:        }
                    621:        return (cp);
                    622: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.