Previous 199869 Revisions Next

r23793 Wednesday 19th June, 2013 at 14:05:35 UTC by Miodrag Milanović
simplified mamemak (nw)
[src/build]makemak.c

trunk/src/build/makemak.c
r23792r23793
118118***************************************************************************/
119119
120120// core output functions
121static int recurse_dir(int srcrootlen, astring &srcdir);
121static int recurse_dir(astring &srcdir);
122122static file_entry &compute_dependencies(astring &srcfile);
123123
124124// path helpers
r23792r23793
405405   }   
406406
407407   // recurse over subdirectories
408   return recurse_dir(srcdir.len(), srcdir);
408   return recurse_dir(srcdir);
409409}
410410
411411
r23792r23793
414414    CORE OUTPUT FUNCTIONS
415415***************************************************************************/
416416
417static int compare_list_entries(const void *p1, const void *p2)
418{
419   const list_entry *entry1 = *(const list_entry **)p1;
420   const list_entry *entry2 = *(const list_entry **)p2;
421   return entry1->name.cmp(entry2->name);
422}
423
424
425417/*-------------------------------------------------
426418    recurse_dependencies - recurse through the
427419    dependencies found, adding the mto the tagmap
r23792r23793
451443    recurse_dir - recurse through a directory
452444-------------------------------------------------*/
453445
454static int recurse_dir(int srcrootlen, astring &srcdir)
446static int recurse_dir(astring &srcdir)
455447{
456   static const osd_dir_entry_type typelist[] = { ENTTYPE_DIR, ENTTYPE_FILE };
457448   int result = 0;
458449
459   // iterate first over directories, then over files
460   for (int entindex = 0; entindex < ARRAY_LENGTH(typelist) && result == 0; entindex++)
450   // iterate through each file
451   for(int i=0;i<sourcecount;i++)
461452   {
462      osd_dir_entry_type entry_type = typelist[entindex];
453      astring srcfile;
463454
464      // open the directory and iterate through it
465      osd_directory *dir = osd_opendir(srcdir);
466      if (dir == NULL)
467      {
468         result = 1;
469         goto error;
470      }
455      // build the source filename
456      srcfile.printf("%s%c%s.c", srcdir.cstr(), PATH_SEPARATOR[0], sourcelst[i]);
457   
458      dependency_map depend_map;
471459
472      // build up the list of files
473      const osd_directory_entry *entry;
474      list_entry *list = NULL;
475      int found = 0;
476      while ((entry = osd_readdir(dir)) != NULL)
477         if (entry->type == entry_type && entry->name[0] != '.')
460      // find dependencies
461      file_entry &file = compute_dependencies(srcfile);
462      recurse_dependencies(file, depend_map);
463     
464         for (dependency_map::entry_t *entry = depend_map.first(); entry != NULL; entry = depend_map.next(entry))
478465         {
479            list_entry *lentry = new list_entry;
480            lentry->name.cpy(entry->name);
481            lentry->next = list;
482            list = lentry;
483            found++;
466            astring t(entry->tag());
467            if (core_filename_ends_with(t, ".h"))
468            {
469               char *foundfile = include_map.find(t);
470               if (foundfile != NULL) {
471                  printf("%s\n", foundfile);
472                  // we add things just once when needed
473                  include_map.remove(t);
474               }
475            }
484476         }
477     
478   }
485479
486      // close the directory
487      osd_closedir(dir);
480     
481   // iterate through each file
482   for(int i=0;i<sourcecount;i++)
483   {
484      astring srcfile;
488485
489      // skip if nothing found
490      if (found == 0)
491         continue;
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;
492490
493      // allocate memory for sorting
494      list_entry **listarray = new list_entry *[found];
495      found = 0;
496      for (list_entry *curlist = list; curlist != NULL; curlist = curlist->next)
497         listarray[found++] = curlist;
491      // find dependencies
492      file_entry &file = compute_dependencies(srcfile);
493      recurse_dependencies(file, depend_map);
498494
499      // sort the list
500      qsort(listarray, found, sizeof(listarray[0]), compare_list_entries);
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());
501501
502      // rebuild the list
503      list = NULL;
504      while (--found >= 0)
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))
505504      {
506         listarray[found]->next = list;
507         list = listarray[found];
508      }
509      delete[] listarray;
510
511      // iterate through each file
512      for (list_entry *curlist = list; curlist != NULL && result == 0; curlist = curlist->next)
513      {
514         astring srcfile;
515
516         // build the source filename
517         srcfile.printf("%s%c%s", srcdir.cstr(), PATH_SEPARATOR[0], curlist->name.cstr());
518
519         // if we have a file, output it
520         if (entry_type == ENTTYPE_FILE)
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"))
521509         {
522            // make sure we care, first
523            if (core_filename_ends_with(curlist->name, ".c"))
524            {
525               dependency_map depend_map;
526
527               // find dependencies
528               file_entry &file = compute_dependencies(srcfile);
529               recurse_dependencies(file, depend_map);
530               astring fn = astring(curlist->name);
531               fn.replace(".c","");
532               if (isonlist(fn))
533               {
534                  for (dependency_map::entry_t *entry = depend_map.first(); entry != NULL; entry = depend_map.next(entry))
535                  {
536                     astring t(entry->tag());
537                     if (core_filename_ends_with(t, ".h"))
538                     {
539                        char *foundfile = include_map.find(t);
540                        if (foundfile != NULL) {
541                           printf("%s\n", foundfile);
542                           // we add things just once when needed
543                           include_map.remove(t);
544                        }
545                     }
546                  }
547               }
548            }
510            printf("\t%s \\\n", t.cstr());
549511         }
550512      }
551
552513     
553      // iterate through each file
554      for (list_entry *curlist = list; curlist != NULL && result == 0; curlist = curlist->next)
514      printf("\n");
515      printf("\n");
516      for (dependency_map::entry_t *entry = depend_map.first(); entry != NULL; entry = depend_map.next(entry))
555517      {
556         astring srcfile;
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");
557524
558         // build the source filename
559         srcfile.printf("%s%c%s", srcdir.cstr(), PATH_SEPARATOR[0], curlist->name.cstr());
560
561         // if we have a file, output it
562         if (entry_type == ENTTYPE_FILE)
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"))
563531         {
564            // make sure we care, first
565            if (core_filename_ends_with(curlist->name, ".c"))
566            {
567               dependency_map depend_map;
532            astring target2(file.name);
533            target2.replace(0, "src/", "$(OBJ)/");
534            target2.replace(0, ".c", ".o");
568535
569               // find dependencies
570               file_entry &file = compute_dependencies(srcfile);
571               recurse_dependencies(file, depend_map);
572               astring fn = astring(curlist->name);
573               fn.replace(".c","");
574               if (isonlist(fn))
575               {
576                  // convert the target from source to object (makes assumptions about rules)
577                  astring target(file.name);
578                  target.replace(0, "src/", "$(OBJ)/");
579                  target.replace(0, "drivers/", "");
580                  target.replace(0, ".c", ".a");
581                  printf("\n%s : \\\n", target.cstr());
582
583                  // iterate over the hashed dependencies and output them as well
584                  for (dependency_map::entry_t *entry = depend_map.first(); entry != NULL; entry = depend_map.next(entry))
585                  {
586                     astring t(entry->tag());
587                     t.replace(0, "src/", "$(OBJ)/");
588                     t.replace(0, ".c", ".o");
589                     if (core_filename_ends_with(t, ".o"))
590                     {
591                        printf("\t%s \\\n", t.cstr());
592                     }
593                  }
594                 
595                  printf("\n");
596                  printf("\n");
597                  for (dependency_map::entry_t *entry = depend_map.first(); entry != NULL; entry = depend_map.next(entry))
598                  {
599                     astring t(entry->tag());
600                     if (core_filename_ends_with(t, ".lay"))
601                     {
602                        astring target2(file.name);
603                        target2.replace(0, "src/", "$(OBJ)/");
604                        target2.replace(0, ".c", ".o");
605
606                        t.replace(0, "src/", "$(OBJ)/");
607                        t.replace(0, ".lay", ".lh");
608                       
609                        printf("%s:   %s\n", target2.cstr(), t.cstr());
610                     }
611                     if (core_filename_ends_with(t, ".inc"))
612                     {
613                        astring target2(file.name);
614                        target2.replace(0, "src/", "$(OBJ)/");
615                        target2.replace(0, ".c", ".o");
616
617                        printf("%s:   %s\n", target2.cstr(), t.cstr());
618                     }
619                  }
620               }
621            }
536            printf("%s:   %s\n", target2.cstr(), t.cstr());
622537         }
623538      }
624
625      // free all the allocated entries
626      while (list != NULL)
627      {
628         list_entry *next = list->next;
629         delete list;
630         list = next;
631      }
539     
632540   }
633
634error:
635541   return result;
636542}
637543

Previous 199869 Revisions Next


© 1997-2024 The MAME Team