|
|
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: #ifdef tahoe ! 121: if (maxusers >= 30) ! 122: fprintf(ofp, " -DGLOBKEY" ); ! 123: #endif ! 124: fprintf(ofp, "\n"); ! 125: if (hadtz == 0) ! 126: printf("timezone not specified; gmt assumed\n"); ! 127: #ifdef tahoe ! 128: if (maxusers == 0) { ! 129: printf("maxusers not specified; 4 assumed\n"); ! 130: maxusers = 4; ! 131: } else if (maxusers < 2) { ! 132: printf("minimum of 2 maxusers assumed\n"); ! 133: maxusers = 2; ! 134: } else if (maxusers > 128) { ! 135: printf("maxusers truncated to 128\n"); ! 136: maxusers = 128; ! 137: } ! 138: #endif ! 139: #ifdef vax ! 140: if (maxusers == 0) { ! 141: printf("maxusers not specified; 24 assumed\n"); ! 142: maxusers = 24; ! 143: } else if (maxusers < 8) { ! 144: printf("minimum of 8 maxusers assumed\n"); ! 145: maxusers = 8; ! 146: } else if (maxusers > 128) { ! 147: printf("maxusers truncated to 128\n"); ! 148: maxusers = 128; ! 149: } ! 150: #endif ! 151: #ifdef sun ! 152: if (maxusers == 0) { ! 153: printf("maxusers not specified; 8 assumed\n"); ! 154: maxusers = 8; ! 155: } else if (maxusers < 2) { ! 156: printf("minimum of 2 maxusers assumed\n"); ! 157: maxusers = 2; ! 158: } else if (maxusers > 32) { ! 159: printf("maxusers truncated to 32\n"); ! 160: maxusers = 32; ! 161: } ! 162: #endif ! 163: fprintf(ofp, "PARAM=-DHZ=%d -DTIMEZONE=%d -DDST=%d -DMAXUSERS=%d\n", ! 164: hz,timezone, dst, maxusers); ! 165: while (fgets(line, BUFSIZ, ifp) != 0) { ! 166: if (*line == '%') ! 167: goto percent; ! 168: if (profiling && strncmp(line, "COPTS=", 6) == 0) { ! 169: register char *cp; ! 170: ! 171: fprintf(ofp, ! 172: "GPROF.EX=/usr/src/lib/libc/%s/csu/gmon.ex\n", ! 173: machinename); ! 174: cp = index(line, '\n'); ! 175: if (cp) ! 176: *cp = 0; ! 177: cp = line + 6; ! 178: while (*cp && (*cp == ' ' || *cp == '\t')) ! 179: cp++; ! 180: COPTS = malloc((unsigned)(strlen(cp) + 1)); ! 181: if (COPTS == 0) { ! 182: printf("config: out of memory\n"); ! 183: exit(1); ! 184: } ! 185: strcpy(COPTS, cp); ! 186: fprintf(ofp, "%s -pg\n", line); ! 187: continue; ! 188: } ! 189: fprintf(ofp, "%s", line); ! 190: continue; ! 191: percent: ! 192: if (eq(line, "%OBJS\n")) ! 193: do_objs(ofp); ! 194: else if (eq(line, "%CFILES\n")) ! 195: do_cfiles(ofp); ! 196: else if (eq(line, "%RULES\n")) ! 197: do_rules(ofp); ! 198: else if (eq(line, "%LOAD\n")) ! 199: do_load(ofp); ! 200: else ! 201: fprintf(stderr, ! 202: "Unknown %% construct in generic makefile: %s", ! 203: line); ! 204: } ! 205: (void) fclose(ifp); ! 206: (void) fclose(ofp); ! 207: } ! 208: ! 209: /* ! 210: * Read in the information about files used in making the system. ! 211: * Store it in the ftab linked list. ! 212: */ ! 213: read_files() ! 214: { ! 215: FILE *fp; ! 216: register struct file_list *tp; ! 217: register struct device *dp; ! 218: char *wd, *this, *needs, *devorprof; ! 219: char fname[32]; ! 220: int nreqs, first = 1, configdep; ! 221: ! 222: ftab = 0; ! 223: (void) strcpy(fname, "files"); ! 224: openit: ! 225: fp = fopen(fname, "r"); ! 226: if (fp == 0) { ! 227: perror(fname); ! 228: exit(1); ! 229: } ! 230: next: ! 231: /* ! 232: * filename [ standard | optional ] [ config-dependent ] ! 233: * [ dev* | profiling-routine ] [ device-driver] ! 234: */ ! 235: wd = get_word(fp); ! 236: if (wd == (char *)EOF) { ! 237: (void) fclose(fp); ! 238: if (first == 1) { ! 239: (void) sprintf(fname, "files.%s", machinename); ! 240: first++; ! 241: goto openit; ! 242: } ! 243: if (first == 2) { ! 244: (void) sprintf(fname, "files.%s", raise(ident)); ! 245: first++; ! 246: fp = fopen(fname, "r"); ! 247: if (fp != 0) ! 248: goto next; ! 249: } ! 250: return; ! 251: } ! 252: if (wd == 0) ! 253: goto next; ! 254: this = ns(wd); ! 255: next_word(fp, wd); ! 256: if (wd == 0) { ! 257: printf("%s: No type for %s.\n", ! 258: fname, this); ! 259: exit(1); ! 260: } ! 261: if (fl_lookup(this)) { ! 262: printf("%s: Duplicate file %s.\n", ! 263: fname, this); ! 264: exit(1); ! 265: } ! 266: tp = 0; ! 267: if (first == 3 && (tp = fltail_lookup(this)) != 0) ! 268: printf("%s: Local file %s overrides %s.\n", ! 269: fname, this, tp->f_fn); ! 270: nreqs = 0; ! 271: devorprof = ""; ! 272: configdep = 0; ! 273: needs = 0; ! 274: if (eq(wd, "standard")) ! 275: goto checkdev; ! 276: if (!eq(wd, "optional")) { ! 277: printf("%s: %s must be optional or standard\n", fname, this); ! 278: exit(1); ! 279: } ! 280: nextopt: ! 281: next_word(fp, wd); ! 282: if (wd == 0) ! 283: goto doneopt; ! 284: if (eq(wd, "config-dependent")) { ! 285: configdep++; ! 286: goto nextopt; ! 287: } ! 288: devorprof = wd; ! 289: if (eq(wd, "device-driver") || eq(wd, "profiling-routine")) { ! 290: next_word(fp, wd); ! 291: goto save; ! 292: } ! 293: nreqs++; ! 294: if (needs == 0) ! 295: needs = ns(wd); ! 296: for (dp = dtab; dp != 0; dp = dp->d_next) ! 297: if (eq(dp->d_name, wd)) ! 298: goto nextopt; ! 299: while ((wd = get_word(fp)) != 0) ! 300: ; ! 301: if (tp == 0) ! 302: tp = new_fent(); ! 303: tp->f_fn = this; ! 304: tp->f_type = INVISIBLE; ! 305: tp->f_needs = needs; ! 306: goto next; ! 307: ! 308: doneopt: ! 309: if (nreqs == 0) { ! 310: printf("%s: what is %s optional on?\n", ! 311: fname, this); ! 312: exit(1); ! 313: } ! 314: ! 315: checkdev: ! 316: if (wd) { ! 317: next_word(fp, wd); ! 318: if (wd) { ! 319: if (eq(wd, "config-dependent")) { ! 320: configdep++; ! 321: goto checkdev; ! 322: } ! 323: devorprof = wd; ! 324: next_word(fp, wd); ! 325: } ! 326: } ! 327: ! 328: save: ! 329: if (wd) { ! 330: printf("%s: syntax error describing %s\n", ! 331: fname, this); ! 332: exit(1); ! 333: } ! 334: if (eq(devorprof, "profiling-routine") && profiling == 0) ! 335: goto next; ! 336: if (tp == 0) ! 337: tp = new_fent(); ! 338: tp->f_fn = this; ! 339: if (eq(devorprof, "device-driver")) ! 340: tp->f_type = DRIVER; ! 341: else if (eq(devorprof, "profiling-routine")) ! 342: tp->f_type = PROFILING; ! 343: else ! 344: tp->f_type = NORMAL; ! 345: tp->f_flags = 0; ! 346: if (configdep) ! 347: tp->f_flags |= CONFIGDEP; ! 348: tp->f_needs = needs; ! 349: goto next; ! 350: } ! 351: ! 352: do_objs(fp) ! 353: FILE *fp; ! 354: { ! 355: register struct file_list *tp, *fl; ! 356: register int lpos, len; ! 357: register char *cp, och, *sp; ! 358: char swapname[32]; ! 359: ! 360: fprintf(fp, "OBJS="); ! 361: lpos = 6; ! 362: for (tp = ftab; tp != 0; tp = tp->f_next) { ! 363: if (tp->f_type == INVISIBLE) ! 364: continue; ! 365: sp = tail(tp->f_fn); ! 366: for (fl = conf_list; fl; fl = fl->f_next) { ! 367: if (fl->f_type != SWAPSPEC) ! 368: continue; ! 369: sprintf(swapname, "swap%s.c", fl->f_fn); ! 370: if (eq(sp, swapname)) ! 371: goto cont; ! 372: } ! 373: cp = sp + (len = strlen(sp)) - 1; ! 374: och = *cp; ! 375: *cp = 'o'; ! 376: if (len + lpos > 72) { ! 377: lpos = 8; ! 378: fprintf(fp, "\\\n\t"); ! 379: } ! 380: fprintf(fp, "%s ", sp); ! 381: lpos += len + 1; ! 382: *cp = och; ! 383: cont: ! 384: ; ! 385: } ! 386: if (lpos != 8) ! 387: putc('\n', fp); ! 388: } ! 389: ! 390: do_cfiles(fp) ! 391: FILE *fp; ! 392: { ! 393: register struct file_list *tp; ! 394: register int lpos, len; ! 395: ! 396: fprintf(fp, "CFILES="); ! 397: lpos = 8; ! 398: for (tp = ftab; tp != 0; tp = tp->f_next) { ! 399: if (tp->f_type == INVISIBLE) ! 400: continue; ! 401: if (tp->f_fn[strlen(tp->f_fn)-1] != 'c') ! 402: continue; ! 403: if ((len = 3 + strlen(tp->f_fn)) + lpos > 72) { ! 404: lpos = 8; ! 405: fprintf(fp, "\\\n\t"); ! 406: } ! 407: fprintf(fp, "../%s ", tp->f_fn); ! 408: lpos += len + 1; ! 409: } ! 410: if (lpos != 8) ! 411: putc('\n', fp); ! 412: } ! 413: ! 414: char * ! 415: tail(fn) ! 416: char *fn; ! 417: { ! 418: register char *cp; ! 419: ! 420: cp = rindex(fn, '/'); ! 421: if (cp == 0) ! 422: return (fn); ! 423: return (cp+1); ! 424: } ! 425: ! 426: /* ! 427: * Create the makerules for each file ! 428: * which is part of the system. ! 429: * Devices are processed with the special c2 option -i ! 430: * which avoids any problem areas with i/o addressing ! 431: * (e.g. for the VAX); assembler files are processed by as. ! 432: */ ! 433: do_rules(f) ! 434: FILE *f; ! 435: { ! 436: register char *cp, *np, och, *tp; ! 437: register struct file_list *ftp; ! 438: char *extras; ! 439: ! 440: for (ftp = ftab; ftp != 0; ftp = ftp->f_next) { ! 441: if (ftp->f_type == INVISIBLE) ! 442: continue; ! 443: cp = (np = ftp->f_fn) + strlen(ftp->f_fn) - 1; ! 444: och = *cp; ! 445: *cp = '\0'; ! 446: fprintf(f, "%so: ../%s%c\n", tail(np), np, och); ! 447: tp = tail(np); ! 448: if (och == 's') { ! 449: fprintf(f, "\t${AS} -o %so ../%ss\n\n", tp, np); ! 450: continue; ! 451: } ! 452: if (och == 'x') { ! 453: fprintf(f, "\t/lib/cpp ../%sx | ${AS} -o %so\n", np, tp); ! 454: fprintf(f, "\t${LD} -x -r %so \n", tp); ! 455: fprintf(f, "\tmv a.out %so \n\n", tp); ! 456: continue; ! 457: } ! 458: if (ftp->f_flags & CONFIGDEP) ! 459: extras = "${PARAM} "; ! 460: else ! 461: extras = ""; ! 462: switch (ftp->f_type) { ! 463: ! 464: case NORMAL: ! 465: switch (machine) { ! 466: ! 467: case MACHINE_VAX: ! 468: fprintf(f, "\t${CC} -I. -c -S ${COPTS} %s../%sc\n", ! 469: extras, np); ! 470: fprintf(f, "\t${C2} %ss | sed -f ../%s/asm.sed |", ! 471: tp, machinename); ! 472: fprintf(f, " ${AS} -o %so\n", tp); ! 473: fprintf(f, "\trm -f %ss\n\n", tp); ! 474: break; ! 475: ! 476: case MACHINE_SUN: ! 477: case MACHINE_TAHOE: ! 478: fprintf(f, "\t${CC} -I. -c -O ${COPTS} %s../%sc\n\n", ! 479: extras, np); ! 480: break; ! 481: } ! 482: break; ! 483: ! 484: case DRIVER: ! 485: switch (machine) { ! 486: ! 487: case MACHINE_VAX: ! 488: fprintf(f, "\t${CC} -I. -c -S ${COPTS} %s../%sc\n", ! 489: extras, np); ! 490: fprintf(f,"\t${C2} -i %ss | sed -f ../%s/asm.sed |", ! 491: tp, machinename); ! 492: fprintf(f, " ${AS} -o %so\n", tp); ! 493: fprintf(f, "\trm -f %ss\n\n", tp); ! 494: break; ! 495: ! 496: case MACHINE_SUN: ! 497: case MACHINE_TAHOE: ! 498: fprintf(f, "\t${CC} -I. -c -O ${COPTS} %s../%sc\n\n", ! 499: extras, np); ! 500: } ! 501: break; ! 502: ! 503: case PROFILING: ! 504: if (!profiling) ! 505: continue; ! 506: if (COPTS == 0) { ! 507: fprintf(stderr, ! 508: "config: COPTS undefined in generic makefile"); ! 509: COPTS = ""; ! 510: } ! 511: switch (machine) { ! 512: ! 513: case MACHINE_VAX: ! 514: fprintf(f, "\t${CC} -I. -c -S %s %s../%sc\n", ! 515: COPTS, extras, np); ! 516: fprintf(f, "\tex - %ss < ${GPROF.EX}\n", tp); ! 517: fprintf(f, ! 518: "\tsed -f ../vax/asm.sed %ss | ${AS} -o %so\n", ! 519: tp, tp); ! 520: fprintf(f, "\trm -f %ss\n\n", tp); ! 521: break; ! 522: ! 523: case MACHINE_TAHOE: ! 524: fprintf(f, "\t${CC} -I. -c -S %s %s../%sc\n", ! 525: COPTS, extras, np); ! 526: fprintf(f, "\tex - %ss < ${GPROF.EX}\n", tp); ! 527: fprintf(f, "\trm -f %ss\n\n", tp); ! 528: break; ! 529: ! 530: case MACHINE_SUN: ! 531: fprintf(stderr, ! 532: "config: don't know how to profile kernel on sun\n"); ! 533: break; ! 534: } ! 535: break; ! 536: ! 537: default: ! 538: printf("Don't know rules for %s\n", np); ! 539: break; ! 540: } ! 541: *cp = och; ! 542: } ! 543: } ! 544: ! 545: /* ! 546: * Create the load strings ! 547: */ ! 548: do_load(f) ! 549: register FILE *f; ! 550: { ! 551: register struct file_list *fl; ! 552: int first = 1; ! 553: struct file_list *do_systemspec(); ! 554: ! 555: fl = conf_list; ! 556: while (fl) { ! 557: if (fl->f_type != SYSTEMSPEC) { ! 558: fl = fl->f_next; ! 559: continue; ! 560: } ! 561: fl = do_systemspec(f, fl, first); ! 562: if (first) ! 563: first = 0; ! 564: } ! 565: fprintf(f, "all:"); ! 566: for (fl = conf_list; fl != 0; fl = fl->f_next) ! 567: if (fl->f_type == SYSTEMSPEC) ! 568: fprintf(f, " %s", fl->f_needs); ! 569: fprintf(f, "\n"); ! 570: } ! 571: ! 572: struct file_list * ! 573: do_systemspec(f, fl, first) ! 574: FILE *f; ! 575: register struct file_list *fl; ! 576: int first; ! 577: { ! 578: ! 579: fprintf(f, "%s: makefile locore.o ${OBJS} param.o", fl->f_needs); ! 580: fprintf(f, " ioconf.o swap%s.o sys5_name.o ${LIBSYS}\n", fl->f_fn); ! 581: fprintf(f, "\t@echo loading %s\n\t@rm -f %s\n", ! 582: fl->f_needs, fl->f_needs); ! 583: if (first) { ! 584: fprintf(f, "\t@sh ../conf/newvers.sh\n"); ! 585: fprintf(f, "\t@${CC} $(CFLAGS) -c vers.c\n"); ! 586: } ! 587: switch (machine) { ! 588: ! 589: case MACHINE_TAHOE: ! 590: fprintf(f, "\t@${LD} -n -o %s -e start -x -T C0000800 ", ! 591: fl->f_needs); ! 592: break; ! 593: ! 594: case MACHINE_VAX: ! 595: fprintf(f, "\t@${LD} -n -o %s -e start -x -T 80000000 ", ! 596: fl->f_needs); ! 597: break; ! 598: ! 599: case MACHINE_SUN: ! 600: fprintf(f, "\t@${LD} -o %s -e start -x -T 4000 ", ! 601: fl->f_needs); ! 602: break; ! 603: } ! 604: fprintf(f, "locore.o ${OBJS} vers.o ioconf.o param.o "); ! 605: fprintf(f, "swap%s.o sys5_name.o ${LIBSYS}\n", fl->f_fn); ! 606: fprintf(f, "\t@echo rearranging symbols\n"); ! 607: if ( machine == MACHINE_TAHOE) ! 608: fprintf(f, "\t@-symorder ../%s/symbols.sort %s\n", ! 609: "machine", fl->f_needs); ! 610: else ! 611: fprintf(f, "\t@-symorder ../%s/symbols.sort %s\n", ! 612: machinename, fl->f_needs); ! 613: fprintf(f, "\t@size %s\n", fl->f_needs); ! 614: fprintf(f, "\t@chmod 755 %s\n\n", fl->f_needs); ! 615: do_swapspec(f, fl->f_fn); ! 616: for (fl = fl->f_next; fl->f_type == SWAPSPEC; fl = fl->f_next) ! 617: ; ! 618: return (fl); ! 619: } ! 620: ! 621: do_swapspec(f, name) ! 622: FILE *f; ! 623: register char *name; ! 624: { ! 625: ! 626: if (!eq(name, "generic")) { ! 627: fprintf(f, "swap%s.o: swap%s.c\n", name, name); ! 628: fprintf(f, "\t${CC} -I. -c -O ${COPTS} swap%s.c\n\n", name); ! 629: return; ! 630: } ! 631: fprintf(f, "swapgeneric.o: ../%s/swapgeneric.c\n", machinename); ! 632: switch (machine) { ! 633: ! 634: case MACHINE_VAX: ! 635: fprintf(f, "\t${CC} -I. -c -S ${COPTS} "); ! 636: fprintf(f, "../%s/swapgeneric.c\n", machinename); ! 637: fprintf(f, "\t${C2} swapgeneric.s | sed -f ../%s/asm.sed", ! 638: machinename); ! 639: fprintf(f, " | ${AS} -o swapgeneric.o\n"); ! 640: fprintf(f, "\trm -f swapgeneric.s\n\n"); ! 641: break; ! 642: ! 643: case MACHINE_TAHOE: ! 644: case MACHINE_SUN: ! 645: fprintf(f, "\t${CC} -I. -c -O ${COPTS} "); ! 646: fprintf(f, "../%s/swapgeneric.c\n\n", machinename); ! 647: break; ! 648: } ! 649: } ! 650: ! 651: char * ! 652: raise(str) ! 653: register char *str; ! 654: { ! 655: register char *cp = str; ! 656: ! 657: while (*str) { ! 658: if (islower(*str)) ! 659: *str = toupper(*str); ! 660: str++; ! 661: } ! 662: return (cp); ! 663: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.