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