trunk/src/build/makemak.c
| r23807 | r23808 | |
| 81 | 81 | astring name; |
| 82 | 82 | }; |
| 83 | 83 | |
| 84 | struct librarylist_entry |
| 85 | { |
| 86 | librarylist_entry * next; |
| 87 | list_entry * sourcefiles; |
| 88 | astring name; |
| 89 | }; |
| 84 | 90 | |
| 85 | 91 | struct file_entry; |
| 86 | 92 | |
| r23807 | r23808 | |
| 108 | 114 | static include_path *incpaths; |
| 109 | 115 | static exclude_path *excpaths; |
| 110 | 116 | static tagmap_t<file_entry *> file_map; |
| 111 | | static const char *sourcelst[MAX_SOURCES]; |
| 112 | | static int sourcecount; |
| 117 | static librarylist_entry *librarylist; |
| 118 | |
| 119 | static librarylist_entry *last_libraryitem; |
| 120 | static list_entry *last_sourceitem; |
| 121 | |
| 113 | 122 | static tagmap_t<char *> include_map; |
| 114 | 123 | |
| 115 | 124 | |
| r23807 | r23808 | |
| 186 | 195 | } |
| 187 | 196 | |
| 188 | 197 | //------------------------------------------------- |
| 189 | | // isonlist - return info if item is in source |
| 190 | | // list or not |
| 191 | | //------------------------------------------------- |
| 192 | | |
| 193 | | bool isonlist(const char *drivname) |
| 194 | | { |
| 195 | | if (sourcecount>0) { |
| 196 | | for(int i=0;i<sourcecount;i++) { |
| 197 | | if (strcmp(sourcelst[i],drivname)==0) return true; |
| 198 | | } |
| 199 | | } |
| 200 | | return false; |
| 201 | | } |
| 202 | | |
| 203 | | //------------------------------------------------- |
| 204 | 198 | // parse_file - parse a single file, may be |
| 205 | 199 | // called recursively |
| 206 | 200 | //------------------------------------------------- |
| r23807 | r23808 | |
| 292 | 286 | drivname[pos+1] = 0; |
| 293 | 287 | } |
| 294 | 288 | fprintf(stderr, "Creating make dependancy for '%s'\n", drivname); |
| 295 | | char *name = (char *)malloc(strlen(drivname) + 1); |
| 296 | | strcpy(name, drivname); |
| 297 | | sourcelst[sourcecount++] = name; |
| 289 | |
| 290 | list_entry *lentry = new list_entry; |
| 291 | lentry->name.cpy(drivname); |
| 292 | lentry->next = NULL; |
| 293 | if (last_sourceitem!=NULL) |
| 294 | { |
| 295 | last_sourceitem->next = lentry; |
| 296 | } |
| 297 | last_sourceitem = lentry; |
| 298 | if (last_libraryitem->sourcefiles==NULL) |
| 299 | { |
| 300 | last_libraryitem->sourcefiles = lentry; |
| 301 | } |
| 298 | 302 | continue; |
| 299 | 303 | } |
| 304 | if (c == '+') |
| 305 | { |
| 306 | // Used for makemak tool |
| 307 | char drivname[256]; |
| 308 | drivname[0] = 0; |
| 309 | for (int pos = 0; srcptr < endptr && pos < ARRAY_LENGTH(drivname) - 1 && !isspace(*srcptr); pos++) |
| 310 | { |
| 311 | drivname[pos] = *srcptr++; |
| 312 | drivname[pos+1] = 0; |
| 313 | } |
| 314 | fprintf(stderr, "Creating library for '%s'\n", drivname); |
| 315 | |
| 316 | librarylist_entry *lentry = new librarylist_entry; |
| 317 | lentry->name.cpy(drivname); |
| 318 | lentry->next = NULL; |
| 319 | lentry->sourcefiles = NULL; |
| 320 | if (last_libraryitem!=NULL) |
| 321 | { |
| 322 | last_libraryitem->next = lentry; |
| 323 | } |
| 324 | last_libraryitem = lentry; |
| 325 | last_sourceitem = NULL; |
| 300 | 326 | |
| 327 | if (librarylist==NULL) |
| 328 | { |
| 329 | librarylist = lentry; |
| 330 | } |
| 331 | |
| 332 | continue; |
| 333 | } |
| 334 | |
| 335 | |
| 301 | 336 | srcptr--; |
| 302 | 337 | for (int pos = 0; srcptr < endptr && !isspace(*srcptr); pos++) |
| 303 | 338 | { |
| r23807 | r23808 | |
| 330 | 365 | exclude_path **excpathhead = &excpaths; |
| 331 | 366 | astring srcdir; |
| 332 | 367 | int unadorned = 0; |
| 333 | | sourcecount = 0; |
| 334 | 368 | |
| 369 | librarylist = NULL; |
| 370 | last_libraryitem = NULL; |
| 371 | last_sourceitem = NULL; |
| 372 | |
| 373 | |
| 335 | 374 | // extract arguments |
| 336 | 375 | const char *srcfile = argv[1]; |
| 337 | 376 | if (parse_file(srcfile)) |
| r23807 | r23808 | |
| 387 | 426 | usage(argv[0]); |
| 388 | 427 | |
| 389 | 428 | |
| 390 | | if (sourcecount>0) |
| 429 | if (librarylist!=NULL) |
| 391 | 430 | { |
| 392 | 431 | printf("OBJDIRS += \\\n"); |
| 393 | 432 | printf("\t$(OBJ)/mame/audio \\\n"); |
| r23807 | r23808 | |
| 398 | 437 | printf("\n\n"); |
| 399 | 438 | printf("DRVLIBS += \\\n"); |
| 400 | 439 | |
| 401 | | for(int i=0;i<sourcecount;i++) { |
| 402 | | printf("\t$(OBJ)/mame/%s.a \\\n",sourcelst[i]); |
| 440 | for (librarylist_entry *lib = librarylist; lib != NULL; lib = lib->next) |
| 441 | { |
| 442 | printf("\t$(OBJ)/mame/%s.a \\\n",lib->name.cstr()); |
| 403 | 443 | } |
| 404 | 444 | printf("\n"); |
| 405 | 445 | } |
| r23807 | r23808 | |
| 447 | 487 | { |
| 448 | 488 | int result = 0; |
| 449 | 489 | |
| 450 | | // iterate through each file |
| 451 | | for(int i=0;i<sourcecount;i++) |
| 490 | // iterate through each file |
| 491 | for (librarylist_entry *lib = librarylist; lib != NULL; lib = lib->next) |
| 452 | 492 | { |
| 453 | | astring srcfile; |
| 454 | | |
| 455 | | // build the source filename |
| 456 | | srcfile.printf("%s%c%s.c", srcdir.cstr(), PATH_SEPARATOR[0], sourcelst[i]); |
| 493 | for (list_entry *src = lib->sourcefiles; src != NULL; src = src->next) |
| 494 | { |
| 457 | 495 | |
| 458 | | dependency_map depend_map; |
| 496 | astring srcfile; |
| 459 | 497 | |
| 460 | | // find dependencies |
| 461 | | file_entry &file = compute_dependencies(srcfile); |
| 462 | | recurse_dependencies(file, depend_map); |
| 498 | // build the source filename |
| 499 | srcfile.printf("%s%c%s.c", srcdir.cstr(), PATH_SEPARATOR[0], src->name.cstr()); |
| 463 | 500 | |
| 501 | dependency_map depend_map; |
| 502 | |
| 503 | // find dependencies |
| 504 | file_entry &file = compute_dependencies(srcfile); |
| 505 | recurse_dependencies(file, depend_map); |
| 506 | |
| 464 | 507 | for (dependency_map::entry_t *entry = depend_map.first(); entry != NULL; entry = depend_map.next(entry)) |
| 465 | 508 | { |
| 466 | 509 | astring t(entry->tag()); |
| r23807 | r23808 | |
| 474 | 517 | } |
| 475 | 518 | } |
| 476 | 519 | } |
| 477 | | |
| 520 | } |
| 478 | 521 | } |
| 479 | 522 | |
| 480 | 523 | |
| 481 | 524 | // iterate through each file |
| 482 | | for(int i=0;i<sourcecount;i++) |
| 525 | for (librarylist_entry *lib = librarylist; lib != NULL; lib = lib->next) |
| 483 | 526 | { |
| 484 | | astring srcfile; |
| 527 | // convert the target from source to object (makes assumptions about rules) |
| 528 | astring target("$(OBJ)/mame/",lib->name.cstr()); |
| 529 | target.cat(".a"); |
| 530 | printf("\n%s : \\\n", target.cstr()); |
| 531 | |
| 532 | for (list_entry *src = lib->sourcefiles; src != NULL; src = src->next) |
| 533 | { |
| 534 | astring srcfile; |
| 485 | 535 | |
| 486 | | // build the source filename |
| 487 | | srcfile.printf("%s%c%s.c", srcdir.cstr(), PATH_SEPARATOR[0], sourcelst[i]); |
| 488 | | |
| 489 | | dependency_map depend_map; |
| 536 | // build the source filename |
| 537 | srcfile.printf("%s%c%s.c", srcdir.cstr(), PATH_SEPARATOR[0], src->name.cstr()); |
| 538 | dependency_map depend_map; |
| 490 | 539 | |
| 491 | | // find dependencies |
| 492 | | file_entry &file = compute_dependencies(srcfile); |
| 493 | | recurse_dependencies(file, depend_map); |
| 540 | // find dependencies |
| 541 | file_entry &file = compute_dependencies(srcfile); |
| 542 | recurse_dependencies(file, depend_map); |
| 494 | 543 | |
| 495 | | // convert the target from source to object (makes assumptions about rules) |
| 496 | | astring target(file.name); |
| 497 | | target.replace(0, "src/", "$(OBJ)/"); |
| 498 | | target.replace(0, "drivers/", ""); |
| 499 | | target.replace(0, ".c", ".a"); |
| 500 | | printf("\n%s : \\\n", target.cstr()); |
| 501 | | |
| 502 | | // iterate over the hashed dependencies and output them as well |
| 503 | | for (dependency_map::entry_t *entry = depend_map.first(); entry != NULL; entry = depend_map.next(entry)) |
| 504 | | { |
| 505 | | astring t(entry->tag()); |
| 506 | | t.replace(0, "src/", "$(OBJ)/"); |
| 507 | | t.replace(0, ".c", ".o"); |
| 508 | | if (core_filename_ends_with(t, ".o")) |
| 544 | // iterate over the hashed dependencies and output them as well |
| 545 | for (dependency_map::entry_t *entry = depend_map.first(); entry != NULL; entry = depend_map.next(entry)) |
| 509 | 546 | { |
| 510 | | printf("\t%s \\\n", t.cstr()); |
| 547 | astring t(entry->tag()); |
| 548 | t.replace(0, "src/", "$(OBJ)/"); |
| 549 | t.replace(0, ".c", ".o"); |
| 550 | if (core_filename_ends_with(t, ".o")) |
| 551 | { |
| 552 | printf("\t%s \\\n", t.cstr()); |
| 553 | } |
| 511 | 554 | } |
| 512 | 555 | } |
| 513 | | |
| 514 | | printf("\n"); |
| 515 | | printf("\n"); |
| 516 | | for (dependency_map::entry_t *entry = depend_map.first(); entry != NULL; entry = depend_map.next(entry)) |
| 556 | printf("\n"); |
| 557 | for (list_entry *src = lib->sourcefiles; src != NULL; src = src->next) |
| 517 | 558 | { |
| 518 | | astring t(entry->tag()); |
| 519 | | if (core_filename_ends_with(t, ".lay")) |
| 520 | | { |
| 521 | | astring target2(file.name); |
| 522 | | target2.replace(0, "src/", "$(OBJ)/"); |
| 523 | | target2.replace(0, ".c", ".o"); |
| 559 | astring srcfile; |
| 524 | 560 | |
| 525 | | t.replace(0, "src/", "$(OBJ)/"); |
| 526 | | t.replace(0, ".lay", ".lh"); |
| 527 | | |
| 528 | | printf("%s: %s\n", target2.cstr(), t.cstr()); |
| 529 | | } |
| 530 | | if (core_filename_ends_with(t, ".inc")) |
| 561 | // build the source filename |
| 562 | srcfile.printf("%s%c%s.c", srcdir.cstr(), PATH_SEPARATOR[0], src->name.cstr()); |
| 563 | dependency_map depend_map; |
| 564 | |
| 565 | // find dependencies |
| 566 | file_entry &file = compute_dependencies(srcfile); |
| 567 | recurse_dependencies(file, depend_map); |
| 568 | for (dependency_map::entry_t *entry = depend_map.first(); entry != NULL; entry = depend_map.next(entry)) |
| 531 | 569 | { |
| 532 | | astring target2(file.name); |
| 533 | | target2.replace(0, "src/", "$(OBJ)/"); |
| 534 | | target2.replace(0, ".c", ".o"); |
| 570 | astring t(entry->tag()); |
| 571 | if (core_filename_ends_with(t, ".lay")) |
| 572 | { |
| 573 | astring target2(file.name); |
| 574 | target2.replace(0, "src/", "$(OBJ)/"); |
| 575 | target2.replace(0, ".c", ".o"); |
| 535 | 576 | |
| 536 | | printf("%s: %s\n", target2.cstr(), t.cstr()); |
| 577 | t.replace(0, "src/", "$(OBJ)/"); |
| 578 | t.replace(0, ".lay", ".lh"); |
| 579 | |
| 580 | printf("%s: %s\n", target2.cstr(), t.cstr()); |
| 581 | } |
| 582 | if (core_filename_ends_with(t, ".inc")) |
| 583 | { |
| 584 | astring target2(file.name); |
| 585 | target2.replace(0, "src/", "$(OBJ)/"); |
| 586 | target2.replace(0, ".c", ".o"); |
| 587 | |
| 588 | printf("%s: %s\n", target2.cstr(), t.cstr()); |
| 589 | } |
| 537 | 590 | } |
| 538 | 591 | } |
| 539 | | |
| 540 | 592 | } |
| 541 | 593 | return result; |
| 542 | 594 | } |