Annotation of researchv9/sys/conf/src/config/mkmakefile.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * mkmakefile.c        1.10    81/05/18
        !             3:  *     Functions in this file build the makefile from the files list
        !             4:  *     and the information in the config table
        !             5:  */
        !             6: 
        !             7: #include <stdio.h>
        !             8: #include <ctype.h>
        !             9: #include "y.tab.h"
        !            10: #include "config.h"
        !            11: 
        !            12: char *mkfile = "mkfile";
        !            13: 
        !            14: #define next_word(fp, wd)\
        !            15:     { register char *word = get_word(fp);\
        !            16:        if (word == WEOF) return EOF; \
        !            17:        else wd = word; }
        !            18: 
        !            19: static struct file_list *fcur;
        !            20: 
        !            21: /*
        !            22:  * fl_lookup
        !            23:  *     look up a file name
        !            24:  */
        !            25: 
        !            26: struct file_list *fl_lookup(file)
        !            27: register char *file;
        !            28: {
        !            29:     register struct file_list *fp;
        !            30: 
        !            31:     for (fp = ftab ; fp != NULL; fp = fp->f_next)
        !            32:     {
        !            33:        if (eq(fp->f_fn, file))
        !            34:            return fp;
        !            35:     }
        !            36:     return NULL;
        !            37: }
        !            38: 
        !            39: /*
        !            40:  * new_fent
        !            41:  *     Make a new file list entry
        !            42:  */
        !            43: 
        !            44: struct file_list *new_fent()
        !            45: {
        !            46:     register struct file_list *fp;
        !            47: 
        !            48:     fp = (struct file_list *) malloc(sizeof *fp);
        !            49:     fp->f_needs = NULL;
        !            50:     fp->f_next = NULL;
        !            51:     if (fcur == NULL)
        !            52:        fcur = ftab = fp;
        !            53:     else
        !            54:        fcur->f_next = fp;
        !            55:     fcur = fp;
        !            56:     return fp;
        !            57: }
        !            58: 
        !            59: /*
        !            60:  * makefile:
        !            61:  *     Build the makefile from the skeleton
        !            62:  */
        !            63: 
        !            64: makefile()
        !            65: {
        !            66:     FILE *ifp, *ofp;
        !            67:     char line[BUFSIZ];
        !            68:     struct cputype *cp;
        !            69:     struct opt *op;
        !            70:     char *raise();
        !            71: 
        !            72:     read_files();                      /* Read in the "files" file */
        !            73:     ifp = fopen(GLOBAL(mkfile), "r");
        !            74:     if (ifp == NULL) {
        !            75:        perror(GLOBAL(mkfile));
        !            76:        exit(1);
        !            77:     }
        !            78:     ofp = fopen(LOCAL(mkfile), "w");
        !            79:     if (ofp == NULL) {
        !            80:        perror(LOCAL(mkfile));
        !            81:        exit(1);
        !            82:     }
        !            83:     fprintf(ofp, "IDENT=");
        !            84:     if (cputype == NULL) {
        !            85:        printf("cpu type must be specified\n");
        !            86:        exit(1);
        !            87:     }
        !            88:     for (cp = cputype; cp; cp = cp->cpu_next)
        !            89:        fprintf(ofp, " -D%s", cp->cpu_name);
        !            90:     for (op = opt; op; op = op->op_next)
        !            91:          fprintf(ofp, " -D%s", op->op_name);
        !            92:     fprintf(ofp, "\n");
        !            93:     if (hz == 0) {
        !            94: #ifdef notdef
        !            95:        printf("hz not specified; 50hz assumed\n");
        !            96: #endif
        !            97: #ifdef vax
        !            98:        hz = 60;
        !            99: #endif
        !           100: #ifdef sun
        !           101:        hz = 50;
        !           102: #endif
        !           103:     }
        !           104:     if (hadtz == 0)
        !           105:        printf("timezone not specified; gmt assumed\n");
        !           106:     if (maxusers == 0) {
        !           107:        printf("maxusers not specified; 24 assumed\n");
        !           108:        maxusers = 24;
        !           109:     } else if (maxusers < 8) {
        !           110:        printf("minimum of 8 maxusers assumed\n");
        !           111:        maxusers = 8;
        !           112:     } else if (maxusers > 128) {
        !           113:        printf("maxusers truncated to 128\n");
        !           114:        maxusers = 128;
        !           115:     }
        !           116:     fprintf(ofp, "PARAM= -DHZ=%d -DTIMEZONE=%d -DDST=%d -DMAXUSERS=%d\n",
        !           117:        hz, timezone, dst, maxusers);
        !           118:     while(fgets(line, BUFSIZ, ifp) != NULL)
        !           119:     {
        !           120:        if (*line != '%')
        !           121:        {
        !           122:            fprintf(ofp, "%s", line);
        !           123:            continue;
        !           124:        }
        !           125:        else if (eq(line, "%OBJS\n"))
        !           126:            do_objs(ofp);
        !           127:        else if (eq(line, "%CFILES\n"))
        !           128:            do_cfiles(ofp);
        !           129:        else if (eq(line, "%SFILES\n"))
        !           130:            do_sfiles(ofp);
        !           131:        else if (eq(line, "%RULES\n"))
        !           132:            do_rules(ofp);
        !           133:        else if (eq(line, "%LOAD\n"))
        !           134:            do_load(ofp);
        !           135:        else
        !           136:            fprintf(stderr, "Unknown %% construct in generic %s: %s", mkfile, line);
        !           137:     }
        !           138:     fclose(ifp);
        !           139:     fclose(ofp);
        !           140: }
        !           141: 
        !           142: /*
        !           143:  * files:
        !           144:  *     Read in the "files" file.
        !           145:  *     Store it in the ftab linked list
        !           146:  */
        !           147: 
        !           148: read_files()
        !           149: {
        !           150: 
        !           151:     ftab = NULL;
        !           152:     read_files_file(GLOBAL("files"), TRUE);
        !           153:     read_files_file(LOCAL("files"), FALSE);
        !           154: }
        !           155: 
        !           156: read_files_file(filename, must_exist)
        !           157:     char *filename;
        !           158: {
        !           159:     FILE *fp;
        !           160:     register struct file_list *tp;
        !           161:     register struct device *dp;
        !           162:     register char *wd, *this;
        !           163:     int type;
        !           164: 
        !           165:     fp = fopen(filename, "r");
        !           166:     if (fp == NULL) {
        !           167:        if (must_exist) {
        !           168:            perror(filename);
        !           169:            exit(1);
        !           170:        } else
        !           171:            return;
        !           172:     }
        !           173:     while((wd = get_word(fp)) != WEOF)
        !           174:     {
        !           175:        if (wd == NULL)
        !           176:            continue;
        !           177:        this = ns(wd);
        !           178:        /*
        !           179:         * Read standard/optional
        !           180:         */
        !           181:        next_word(fp, wd);
        !           182:        if (wd == NULL)
        !           183:        {
        !           184:            fprintf(stderr, "Huh, no type for %s in files.\n", this);
        !           185:            exit(10);
        !           186:        }
        !           187:        if ((tp = fl_lookup(wd)) == NULL)
        !           188:            tp = new_fent();
        !           189:        else
        !           190:            free(tp->f_fn);
        !           191:        tp->f_fn = this;
        !           192:        type = 0;
        !           193:        if (eq(wd, "optional"))
        !           194:        {
        !           195:            next_word(fp, wd);
        !           196:            if (wd == NULL)
        !           197:            {
        !           198:                fprintf(stderr, "Needed a dev for optional(%s)\n", this);
        !           199:                exit(11);
        !           200:            }
        !           201:            tp->f_needs = ns(wd);
        !           202:            for (dp = dtab ; dp != NULL; dp = dp->d_next)
        !           203:            {
        !           204:                if (eq(dp->d_name, wd))
        !           205:                    break;
        !           206:            }
        !           207:            if (dp == NULL)
        !           208:                type = INVISIBLE;
        !           209:        }
        !           210:        next_word(fp, wd);
        !           211:        if (type == 0 && wd != NULL)
        !           212:            type = DEVICE;
        !           213:        else if (type == 0)
        !           214:            type = NORMAL;
        !           215:        tp->f_type = type;
        !           216:     }
        !           217:     fclose(fp);
        !           218: }
        !           219: 
        !           220: /*
        !           221:  * do_objs
        !           222:  *     Spew forth the OBJS definition
        !           223:  */
        !           224: 
        !           225: do_objs(fp)
        !           226: FILE *fp;
        !           227: {
        !           228:     register struct file_list *tp;
        !           229:     register int lpos, len;
        !           230:     register char *cp, och, *sp;
        !           231:     char *tail();
        !           232: 
        !           233:     fprintf(fp, "OBJS=");
        !           234:     lpos = 6;
        !           235:     for (tp = ftab; tp != NULL; tp = tp->f_next)
        !           236:     {
        !           237:        if (tp->f_type == INVISIBLE)
        !           238:            continue;
        !           239:        sp = tail(tp->f_fn);
        !           240:        cp = sp + (len = strlen(sp)) - 1;
        !           241:        och = *cp;
        !           242:        *cp = 'o';
        !           243:        if (len + lpos > 72)
        !           244:        {
        !           245:            lpos = 8;
        !           246:            fprintf(fp, "\\\n\t");
        !           247:        }
        !           248:        fprintf(fp, "%s ", sp);
        !           249:        lpos += len + 1;
        !           250:        *cp = och;
        !           251:     }
        !           252:     if (lpos != 8)
        !           253:        putc('\n', fp);
        !           254: }
        !           255: 
        !           256: /*
        !           257:  * do_cfiles
        !           258:  *     Spew forth the CFILES definition
        !           259:  */
        !           260: 
        !           261: do_cfiles(fp)
        !           262: FILE *fp;
        !           263: {
        !           264:     register struct file_list *tp;
        !           265:     register int lpos, len;
        !           266: 
        !           267:     fprintf(fp, "CFILES=");
        !           268:     lpos = 8;
        !           269:     for (tp = ftab; tp != NULL; tp = tp->f_next)
        !           270:     {
        !           271:        if (tp->f_type == INVISIBLE)
        !           272:            continue;
        !           273:        if (tp->f_fn[strlen(tp->f_fn)-1] != 'c')
        !           274:            continue;
        !           275:        if ((len = 3 + strlen(tp->f_fn)) + lpos > 72)
        !           276:        {
        !           277:            lpos = 8;
        !           278:            fprintf(fp, "\\\n\t");
        !           279:        }
        !           280:        fprintf(fp, "../%s ", tp->f_fn);
        !           281:        lpos += len + 1;
        !           282:     }
        !           283:     if (lpos != 8)
        !           284:        putc('\n', fp);
        !           285: }
        !           286: 
        !           287: /*
        !           288:  * do_sfiles
        !           289:  *     Spew forth the SFILES definition
        !           290:  */
        !           291: 
        !           292: do_sfiles(fp)
        !           293: FILE *fp;
        !           294: {
        !           295:     register struct file_list *tp;
        !           296:     register int lpos, len;
        !           297: 
        !           298:     fprintf(fp, "SFILES=");
        !           299:     lpos = 8;
        !           300:     for (tp = ftab; tp != NULL; tp = tp->f_next)
        !           301:     {
        !           302:        if (tp->f_type == INVISIBLE)
        !           303:            continue;
        !           304:        if (tp->f_fn[strlen(tp->f_fn)-1] != 's')
        !           305:            continue;
        !           306:        if ((len = 3 + strlen(tp->f_fn)) + lpos > 72)
        !           307:        {
        !           308:            lpos = 8;
        !           309:            fprintf(fp, "\\\n\t");
        !           310:        }
        !           311:        fprintf(fp, "../%s ", tp->f_fn);
        !           312:        lpos += len + 1;
        !           313:     }
        !           314:     if (lpos != 8)
        !           315:        putc('\n', fp);
        !           316: }
        !           317: 
        !           318: /*
        !           319:  * tail:
        !           320:  *     Return tail end of a filename
        !           321:  */
        !           322: 
        !           323: char *tail(fn)
        !           324: char *fn;
        !           325: {
        !           326:     register char *cp;
        !           327:     char *strrchr();
        !           328: 
        !           329:     cp = strrchr(fn, '/');
        !           330:     return cp+1;
        !           331: }
        !           332: 
        !           333: /*
        !           334:  * do_rules:
        !           335:  *     Spit out the rules for making each file
        !           336:  */
        !           337: 
        !           338: do_rules(f)
        !           339: FILE *f;
        !           340: {
        !           341:     register char *cp, *np, och, *tp;
        !           342:     register struct file_list *ftp;
        !           343: 
        !           344:     for (ftp = ftab; ftp != NULL; ftp = ftp->f_next)
        !           345:     {
        !           346:        if (ftp->f_type == INVISIBLE)
        !           347:            continue;
        !           348:        cp = (np = ftp->f_fn) + strlen(ftp->f_fn) - 1;
        !           349:        och = *cp;
        !           350:        *cp = '\0';
        !           351:        fprintf(f, "%so: ../%s%c\n", tail(np), np, och);
        !           352:        tp = tail(np);
        !           353:        if (och == 's')
        !           354:        {
        !           355: #ifdef vax
        !           356:            fprintf(f, "\t${AS} -o %so ../%ss\n\n", tp, np);
        !           357: #endif
        !           358: #ifdef sun
        !           359:            fprintf(f, "\t/lib/cpp -E -I. %s ../%ss >%si\n",
        !           360:                "-DLOCORE ${IDENT} -DKERNEL", np, tp);
        !           361:            fprintf(f, "\t${AS} -o %so %si\n", tp, tp);
        !           362:            fprintf(f, "\trm -f %si\n\n", tp);
        !           363: #endif
        !           364:        }
        !           365:        else if (ftp->f_type == NORMAL)
        !           366:        {
        !           367: #ifdef vax
        !           368:            fprintf(f, "\t${CC} -I. -c -S ${COPTS} ../%sc\n", np);
        !           369:            fprintf(f, "\t${C2} %ss | sed -f ../sys/asm.sed | ${AS} -o %so\n",
        !           370:                    tp, tp);
        !           371:            fprintf(f, "\trm -f %ss\n\n", tp);
        !           372: #endif
        !           373: #ifdef sun
        !           374:            fprintf(f, "\t${CC} -I. -c ${CFLAGS} ../%sc\n\n", np);
        !           375: #endif
        !           376:        }
        !           377:        else if (ftp->f_type == DEVICE)
        !           378:        {
        !           379: #ifdef vax
        !           380:            fprintf(f, "\t${CC} -I. -c -S ${COPTS} ../%sc\n", np);
        !           381:            fprintf(f,"\t${C2} -i %ss | sed -f ../sys/asm.sed | ${AS} -o %so\n",
        !           382:                    tp, tp);
        !           383:            fprintf(f, "\trm -f %ss\n\n", tp);
        !           384: #endif
        !           385: #ifdef sun
        !           386:            fprintf(f, "\t${CC} -I. -c ${CFLAGS} ../%sc\n\n", np);
        !           387: #endif
        !           388:        }
        !           389:        else
        !           390:            fprintf(stderr, "Don't know rules for %s", np);
        !           391:        *cp = och;
        !           392:     }
        !           393: }
        !           394: 
        !           395: /*
        !           396:  * Create the load strings
        !           397:  */
        !           398: 
        !           399: do_load(f)
        !           400: register FILE *f;
        !           401: {
        !           402:     register struct file_list *fl;
        !           403:     register bool first = TRUE;
        !           404: 
        !           405:     for (fl = conf_list; fl != NULL; fl = fl->f_next)
        !           406:     {
        !           407: #ifdef vax
        !           408:        fprintf(f, "%s:Q: %s locore.o ${OBJS} ${EMULO} ioconf.o conf.o param.o swap%s.o\n",
        !           409: #endif
        !           410: #ifdef sun
        !           411:        fprintf(f, "%s:Q: %s ${OBJS} ${FOBJS} ubglue.o ioconf.o conf.o param.o swap%s.o stab.o\n",
        !           412: #endif
        !           413:                fl->f_needs, mkfile, fl->f_fn);
        !           414:        fprintf(f, "\techo loading %s\n\trm -f %s\n",
        !           415:                fl->f_needs, fl->f_needs);
        !           416:        if (first)
        !           417:        {
        !           418:                first = FALSE;
        !           419:                fprintf(f, "\tsh ../conf/newvers.sh\n");
        !           420:                fprintf(f, "\tcc ${CFLAGS} -c vers.c\n");
        !           421:        }
        !           422: #ifdef vax
        !           423:        fprintf(f,
        !           424:            "\tld -n -o %s -e start -x -T 80000000 locore.o ${OBJS} ${EMULO} vers.o ioconf.o conf.o param.o swap%s.o\n",
        !           425:            fl->f_needs, fl->f_fn);
        !           426: #endif
        !           427: #ifdef sun
        !           428:        fprintf(f,
        !           429:            "\t${LD} -o %s -e _start -N -X -T 0F004000 ${OBJS} ${FOBJS} ubglue.o vers.o ioconf.o conf.o param.o swap%s.o stab.o\n",
        !           430:            fl->f_needs, fl->f_fn);
        !           431: #endif
        !           432:        fprintf(f, "\tsize %s\n", fl->f_needs);
        !           433:        fprintf(f, "\tchmod 755 %s\n\n", fl->f_needs);
        !           434:     }
        !           435:     for (fl = conf_list; fl != NULL; fl = fl->f_next)
        !           436:     {
        !           437:        fprintf(f, "swap%s.o: ../dev/swap%s.c\n", fl->f_fn, fl->f_fn);
        !           438: #ifdef vax
        !           439:        fprintf(f, "\t${CC} -I. -c -S ${COPTS} ../dev/swap%s.c\n", fl->f_fn);
        !           440:        fprintf(f,
        !           441:            "\t${C2} swap%s.s | sed -f ../sys/asm.sed | ${AS} -o swap%s.o\n",
        !           442:            fl->f_fn, fl->f_fn);
        !           443:        fprintf(f, "\trm -f swap%s.s\n\n", fl->f_fn);
        !           444: #endif
        !           445: #ifdef sun
        !           446:        fprintf(f, "\t${CC} -I. -c ${CFLAGS} ../dev/swap%s.c\n\n", fl->f_fn);
        !           447: #endif
        !           448:     }
        !           449:     fprintf(f, "all:");
        !           450:     for (fl = conf_list; fl != NULL; fl = fl->f_next)
        !           451:        fprintf(f, " %s", fl->f_needs);
        !           452:     putc('\n', f);
        !           453: }
        !           454: 
        !           455: char *
        !           456: raise(str)
        !           457: register char *str;
        !           458: {
        !           459:     register char *cp = str;
        !           460: 
        !           461:     while(*str)
        !           462:     {
        !           463:        if (islower(*str))
        !           464:            *str = toupper(*str);
        !           465:        str++;
        !           466:     }
        !           467:     return cp;
        !           468: }

unix.superglobalmegacorp.com

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