trunk/src/build/makemak.c
| r23818 | r23819 | |
| 133 | 133 | // path helpers |
| 134 | 134 | static bool find_include_file(astring &srcincpath, const astring &srcfile, const astring &filename); |
| 135 | 135 | |
| 136 | | |
| 136 | static bool check_file(astring &srcincpath) |
| 137 | { |
| 138 | // see if we can open it |
| 139 | core_file *testfile; |
| 140 | if (core_fopen(srcincpath, OPEN_FLAG_READ, &testfile) == FILERR_NONE) |
| 141 | { |
| 142 | // close the file |
| 143 | core_fclose(testfile); |
| 144 | return true; |
| 145 | } |
| 146 | return false; |
| 147 | } |
| 137 | 148 | int include_mapping(const char *srcfile) |
| 138 | 149 | { |
| 139 | 150 | // read source file |
| r23818 | r23819 | |
| 285 | 296 | drivname[pos] = *srcptr++; |
| 286 | 297 | drivname[pos+1] = 0; |
| 287 | 298 | } |
| 288 | | fprintf(stderr, "Creating make dependancy for '%s'\n", drivname); |
| 289 | 299 | |
| 290 | 300 | list_entry *lentry = new list_entry; |
| 291 | 301 | lentry->name.cpy(drivname); |
| r23818 | r23819 | |
| 311 | 321 | drivname[pos] = *srcptr++; |
| 312 | 322 | drivname[pos+1] = 0; |
| 313 | 323 | } |
| 314 | | fprintf(stderr, "Creating library for '%s'\n", drivname); |
| 315 | 324 | |
| 316 | 325 | librarylist_entry *lentry = new librarylist_entry; |
| 317 | 326 | lentry->name.cpy(drivname); |
| r23818 | r23819 | |
| 345 | 354 | return 0; |
| 346 | 355 | } |
| 347 | 356 | |
| 357 | int parse_for_drivers(const char *srcfile) |
| 358 | { |
| 359 | // read source file |
| 360 | core_file *file = NULL; |
| 361 | |
| 362 | file_error filerr = core_fopen(srcfile, OPEN_FLAG_READ, &file); |
| 363 | if (filerr != FILERR_NONE) |
| 364 | { |
| 365 | fprintf(stderr, "Unable to read source file '%s'\n", srcfile); |
| 366 | return 1; |
| 367 | } |
| 368 | // loop over lines in the file |
| 369 | char buffer[4096]; |
| 370 | while (core_fgets(buffer, ARRAY_LENGTH(buffer), file) != NULL) |
| 371 | { |
| 372 | astring line; |
| 373 | |
| 374 | // rip through it to find all drivers |
| 375 | char *srcptr = (char *)buffer; |
| 376 | char *endptr = srcptr + strlen(buffer); |
| 377 | bool in_comment = false; |
| 378 | while (srcptr < endptr) |
| 379 | { |
| 380 | char c = *srcptr++; |
| 381 | |
| 382 | // skip any spaces |
| 383 | if (isspace(c)) |
| 384 | continue; |
| 385 | |
| 386 | // look for end of C comment |
| 387 | if (in_comment && c == '*' && *srcptr == '/') |
| 388 | { |
| 389 | srcptr++; |
| 390 | in_comment = false; |
| 391 | continue; |
| 392 | } |
| 393 | |
| 394 | // skip anything else inside a C comment |
| 395 | if (in_comment) |
| 396 | continue; |
| 397 | |
| 398 | // look for start of C comment |
| 399 | if (c == '/' && *srcptr == '*') |
| 400 | { |
| 401 | srcptr++; |
| 402 | in_comment = true; |
| 403 | continue; |
| 404 | } |
| 405 | |
| 406 | // if we hit a C++ comment, scan to the end of line |
| 407 | if (c == '/' && *srcptr == '/') |
| 408 | { |
| 409 | while (srcptr < endptr && *srcptr != 13 && *srcptr != 10) |
| 410 | srcptr++; |
| 411 | continue; |
| 412 | } |
| 413 | |
| 414 | srcptr--; |
| 415 | for (int pos = 0; srcptr < endptr && !isspace(*srcptr); pos++) |
| 416 | { |
| 417 | line.cat(*srcptr++); |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | if ((line.find(0,"GAME(")==0) || (line.find(0,"GAMEL(")==0) || |
| 422 | (line.find(0,"COMP(")==0) || (line.find(0,"CONS(")==0) || |
| 423 | (line.find(0,"SYST(")==0)) |
| 424 | { |
| 425 | int p1 = line.find(0,","); |
| 426 | if (p1<0) continue; |
| 427 | int p2 = line.find(p1+1,","); |
| 428 | if (p2<0) continue; |
| 429 | |
| 430 | printf("%s\n",line.substr(p1+1,p2-p1-1).cstr()); |
| 431 | } |
| 432 | } |
| 433 | core_fclose(file); |
| 434 | return 0; |
| 435 | } |
| 436 | |
| 348 | 437 | /*************************************************************************** |
| 349 | 438 | MAIN |
| 350 | 439 | ***************************************************************************/ |
| r23818 | r23819 | |
| 376 | 465 | if (parse_file(srcfile)) |
| 377 | 466 | return 1; |
| 378 | 467 | |
| 379 | | include_mapping("src/emu/cpu/cpu.mak"); |
| 380 | | include_mapping("src/emu/video/video.mak"); |
| 381 | | include_mapping("src/emu/sound/sound.mak"); |
| 382 | | include_mapping("src/emu/machine/machine.mak"); |
| 383 | 468 | // loop over arguments |
| 384 | 469 | for (int argnum = 2; argnum < argc; argnum++) |
| 385 | 470 | { |
| r23818 | r23819 | |
| 421 | 506 | usage(argv[0]); |
| 422 | 507 | } |
| 423 | 508 | |
| 424 | | // make sure we got 1 parameter |
| 509 | // generate list of drivers |
| 425 | 510 | if (srcdir.len() == 0) |
| 426 | | usage(argv[0]); |
| 427 | | |
| 428 | | |
| 429 | | if (librarylist!=NULL) |
| 430 | | { |
| 431 | | printf("OBJDIRS += \\\n"); |
| 432 | | printf("\t$(OBJ)/mame/audio \\\n"); |
| 433 | | printf("\t$(OBJ)/mame/drivers \\\n"); |
| 434 | | printf("\t$(OBJ)/mame/layout \\\n"); |
| 435 | | printf("\t$(OBJ)/mame/machine \\\n"); |
| 436 | | printf("\t$(OBJ)/mame/video \\\n"); |
| 437 | | printf("\n\n"); |
| 438 | | printf("DRVLIBS += \\\n"); |
| 439 | | |
| 511 | { |
| 440 | 512 | for (librarylist_entry *lib = librarylist; lib != NULL; lib = lib->next) |
| 441 | 513 | { |
| 442 | | printf("\t$(OBJ)/mame/%s.a \\\n",lib->name.cstr()); |
| 514 | for (list_entry *src = lib->sourcefiles; src != NULL; src = src->next) |
| 515 | { |
| 516 | printf("// Drivers from %s.c\n",src->name.cstr()); |
| 517 | astring srcfile; |
| 518 | // build the source filename |
| 519 | srcfile.printf("%s%c%s.c", "src/mame/drivers", PATH_SEPARATOR[0], src->name.cstr()); |
| 520 | parse_for_drivers(srcfile); |
| 521 | |
| 522 | astring srcfile_inc; |
| 523 | // build the source filename |
| 524 | srcfile_inc.printf("%s%c%s.inc", "src/mame/drivers", PATH_SEPARATOR[0], src->name.cstr()); |
| 525 | if(check_file(srcfile_inc)) |
| 526 | parse_for_drivers(srcfile_inc); |
| 527 | } |
| 443 | 528 | } |
| 444 | | printf("\n"); |
| 445 | | } |
| 529 | return 0; |
| 530 | } |
| 531 | else |
| 532 | { |
| 533 | include_mapping("src/emu/cpu/cpu.mak"); |
| 534 | include_mapping("src/emu/video/video.mak"); |
| 535 | include_mapping("src/emu/sound/sound.mak"); |
| 536 | include_mapping("src/emu/machine/machine.mak"); |
| 537 | if (librarylist!=NULL) |
| 538 | { |
| 539 | printf("OBJDIRS += \\\n"); |
| 540 | printf("\t$(OBJ)/mame/audio \\\n"); |
| 541 | printf("\t$(OBJ)/mame/drivers \\\n"); |
| 542 | printf("\t$(OBJ)/mame/layout \\\n"); |
| 543 | printf("\t$(OBJ)/mame/machine \\\n"); |
| 544 | printf("\t$(OBJ)/mame/video \\\n"); |
| 545 | printf("\n\n"); |
| 546 | printf("DRVLIBS += \\\n"); |
| 547 | |
| 548 | for (librarylist_entry *lib = librarylist; lib != NULL; lib = lib->next) |
| 549 | { |
| 550 | printf("\t$(OBJ)/mame/mame/%s.a \\\n",lib->name.cstr()); |
| 551 | } |
| 552 | printf("\n"); |
| 553 | } |
| 446 | 554 | |
| 447 | | // recurse over subdirectories |
| 448 | | return recurse_dir(srcdir); |
| 555 | // recurse over subdirectories |
| 556 | return recurse_dir(srcdir); |
| 557 | } |
| 449 | 558 | } |
| 450 | 559 | |
| 451 | 560 | |
| r23818 | r23819 | |
| 525 | 634 | for (librarylist_entry *lib = librarylist; lib != NULL; lib = lib->next) |
| 526 | 635 | { |
| 527 | 636 | // convert the target from source to object (makes assumptions about rules) |
| 528 | | astring target("$(OBJ)/mame/",lib->name.cstr()); |
| 637 | astring target("$(OBJ)/mame/mame/",lib->name.cstr()); |
| 529 | 638 | target.cat(".a"); |
| 530 | 639 | printf("\n%s : \\\n", target.cstr()); |
| 531 | 640 | |
| r23818 | r23819 | |
| 593 | 702 | return result; |
| 594 | 703 | } |
| 595 | 704 | |
| 596 | | static bool check_file(astring &srcincpath) |
| 597 | | { |
| 598 | | // see if we can open it |
| 599 | | core_file *testfile; |
| 600 | | if (core_fopen(srcincpath, OPEN_FLAG_READ, &testfile) == FILERR_NONE) |
| 601 | | { |
| 602 | | // close the file |
| 603 | | core_fclose(testfile); |
| 604 | | return true; |
| 605 | | } |
| 606 | | return false; |
| 607 | | } |
| 608 | | |
| 609 | 705 | /*------------------------------------------------- |
| 610 | 706 | output_file - output a file, converting to |
| 611 | 707 | HTML |