static void recurse_dependencies(file_entry &file, dependency_map &map) { // skip if we're in an exclude path int filelen = file.name.len(); for (exclude_path *exclude = excpaths; exclude != NULL; exclude = exclude->next) if (exclude->pathlen < filelen && strncmp(file.name, exclude->path, exclude->pathlen) == 0) if (exclude->recursive || file.name.chr(exclude->pathlen + 1, '/') == -1) return; // attempt to add; if we get an error, we're already present if (map.add(file.name, 0) != TMERR_NONE) return; // recurse the list from there for (dependency *dep = file.deplist; dep != NULL; dep = dep->next) recurse_dependencies(*dep->file, map); }
static void recurse_dependencies(file_entry *file, tagmap *map) { int filelen = astring_len(file->name); exclude_path *exclude; dependency *dep; /* skip if we're in an exclude path */ for (exclude = excpaths; exclude != NULL; exclude = exclude->next) if (exclude->pathlen < filelen && strncmp(astring_c(file->name), astring_c(exclude->path), exclude->pathlen) == 0) if (exclude->recursive || astring_chr(file->name, exclude->pathlen + 1, '/') == -1) return; /* attempt to add; if we get an error, we're already present */ if (tagmap_add(map, astring_c(file->name), file->name, FALSE) != TMERR_NONE) return; /* recurse the list from there */ for (dep = file->deplist; dep != NULL; dep = dep->next) recurse_dependencies(dep->file, map); }
static int recurse_dir(int srcrootlen, astring &srcdir) { static const osd_dir_entry_type typelist[] = { ENTTYPE_DIR, ENTTYPE_FILE }; int result = 0; // iterate first over directories, then over files for (int entindex = 0; entindex < ARRAY_LENGTH(typelist) && result == 0; entindex++) { osd_dir_entry_type entry_type = typelist[entindex]; // open the directory and iterate through it osd_directory *dir = osd_opendir(srcdir); if (dir == NULL) { result = 1; goto error; } // build up the list of files const osd_directory_entry *entry; list_entry *list = NULL; int found = 0; while ((entry = osd_readdir(dir)) != NULL) if (entry->type == entry_type && entry->name[0] != '.') { list_entry *lentry = new list_entry; lentry->name.cpy(entry->name); lentry->next = list; list = lentry; found++; } // close the directory osd_closedir(dir); // skip if nothing found if (found == 0) continue; // allocate memory for sorting list_entry **listarray = new list_entry *[found]; found = 0; for (list_entry *curlist = list; curlist != NULL; curlist = curlist->next) listarray[found++] = curlist; // sort the list qsort(listarray, found, sizeof(listarray[0]), compare_list_entries); // rebuild the list list = NULL; while (--found >= 0) { listarray[found]->next = list; list = listarray[found]; } delete[] listarray; // iterate through each file for (list_entry *curlist = list; curlist != NULL && result == 0; curlist = curlist->next) { astring srcfile; // build the source filename srcfile.printf("%s%c%s", srcdir.cstr(), PATH_SEPARATOR[0], curlist->name.cstr()); // if we have a file, output it if (entry_type == ENTTYPE_FILE) { // make sure we care, first if (core_filename_ends_with(curlist->name, ".c")) { dependency_map depend_map; // find dependencies file_entry &file = compute_dependencies(srcrootlen, srcfile); recurse_dependencies(file, depend_map); // convert the target from source to object (makes assumptions about rules) astring target(file.name); target.replace(0, "src/", "$(OBJ)/"); target.replace(0, ".c", ".o"); printf("\n%s : \\\n", target.cstr()); // iterate over the hashed dependencies and output them as well for (dependency_map::entry_t *entry = depend_map.first(); entry != NULL; entry = depend_map.next(entry)) printf("\t%s \\\n", entry->tag().cstr()); } } // if we have a directory, recurse else result = recurse_dir(srcrootlen, srcfile); } // free all the allocated entries while (list != NULL) { list_entry *next = list->next; delete list; list = next; } } error: return result; }
static int recurse_dir(int srcrootlen, const astring *srcdir) { static const osd_dir_entry_type typelist[] = { ENTTYPE_DIR, ENTTYPE_FILE }; int result = 0; int entindex; /* iterate first over directories, then over files */ for (entindex = 0; entindex < ARRAY_LENGTH(typelist) && result == 0; entindex++) { osd_dir_entry_type entry_type = typelist[entindex]; const osd_directory_entry *entry; list_entry **listarray = NULL; list_entry *list = NULL; list_entry *curlist; osd_directory *dir; int found = 0; /* open the directory and iterate through it */ dir = osd_opendir(astring_c(srcdir)); if (dir == NULL) { result = 1; goto error; } /* build up the list of files */ while ((entry = osd_readdir(dir)) != NULL) if (entry->type == entry_type && entry->name[0] != '.') { list_entry *lentry = (list_entry *)malloc(sizeof(*lentry)); lentry->name = astring_dupc(entry->name); lentry->next = list; list = lentry; found++; } /* close the directory */ osd_closedir(dir); /* skip if nothing found */ if (found == 0) continue; /* allocate memory for sorting */ listarray = (list_entry **)malloc(sizeof(list_entry *) * found); found = 0; for (curlist = list; curlist != NULL; curlist = curlist->next) listarray[found++] = curlist; /* sort the list */ qsort(listarray, found, sizeof(listarray[0]), compare_list_entries); /* rebuild the list */ list = NULL; while (--found >= 0) { listarray[found]->next = list; list = listarray[found]; } free(listarray); /* iterate through each file */ for (curlist = list; curlist != NULL && result == 0; curlist = curlist->next) { astring *srcfile; /* build the source filename */ srcfile = astring_alloc(); astring_printf(srcfile, "%s%c%s", astring_c(srcdir), PATH_SEPARATOR[0], astring_c(curlist->name)); /* if we have a file, output it */ if (entry_type == ENTTYPE_FILE) { /* make sure we care, first */ if (core_filename_ends_with(astring_c(curlist->name), ".c")) { tagmap *depend_map = tagmap_alloc(); tagmap_entry *map_entry; file_entry *file; astring *target; int taghash; /* find dependencies */ file = compute_dependencies(srcrootlen, srcfile); recurse_dependencies(file, depend_map); /* convert the target from source to object (makes assumptions about rules) */ target = astring_dup(file->name); astring_replacec(target, 0, "src/", "$(OBJ)/"); astring_replacec(target, 0, ".c", ".o"); printf("\n%s : \\\n", astring_c(target)); /* iterate over the hashed dependencies and output them as well */ for (taghash = 0; taghash < TAGMAP_HASH_SIZE; taghash++) for (map_entry = depend_map->table[taghash]; map_entry != NULL; map_entry = map_entry->next) printf("\t%s \\\n", astring_c((astring *)map_entry->object)); astring_free(target); tagmap_free(depend_map); } } /* if we have a directory, recurse */ else result = recurse_dir(srcrootlen, srcfile); /* free memory for the names */ astring_free(srcfile); } /* free all the allocated entries */ while (list != NULL) { list_entry *next = list->next; astring_free((astring *)list->name); free(list); list = next; } } error: return result; }
static int recurse_dir(astring &srcdir) { int result = 0; // iterate through each file for (librarylist_entry *lib = librarylist; lib != NULL; lib = lib->next) { for (list_entry *src = lib->sourcefiles; src != NULL; src = src->next) { astring srcfile; // build the source filename srcfile.printf("%s%s.c", srcdir.cstr(), src->name.cstr()); dependency_map depend_map; // find dependencies file_entry &file = compute_dependencies(srcfile); recurse_dependencies(file, depend_map); for (dependency_map::entry_t *entry = depend_map.first(); entry != NULL; entry = depend_map.next(entry)) { astring t(entry->tag()); if (core_filename_ends_with(t, ".h")) { char *foundfile = include_map.find(t); if (foundfile != NULL) { printf("%s\n", foundfile); // we add things just once when needed include_map.remove(t); } } } } } // iterate through each file for (librarylist_entry *lib = librarylist; lib != NULL; lib = lib->next) { // convert the target from source to object (makes assumptions about rules) astring target("$(OBJ)/target/",lib->name.cstr()); target.cat(".a"); printf("\n%s : \\\n", target.cstr()); for (list_entry *src = lib->sourcefiles; src != NULL; src = src->next) { astring srcfile; // build the source filename srcfile.printf("%s%s.c", srcdir.cstr(), src->name.cstr()); dependency_map depend_map; // find dependencies file_entry &file = compute_dependencies(srcfile); recurse_dependencies(file, depend_map); // iterate over the hashed dependencies and output them as well for (dependency_map::entry_t *entry = depend_map.first(); entry != NULL; entry = depend_map.next(entry)) { astring t(entry->tag()); t.replace(0, "src/", "$(OBJ)/"); t.replace(0, ".c", ".o"); if (core_filename_ends_with(t, ".o")) { printf("\t%s \\\n", t.cstr()); } } } printf("\n"); for (list_entry *src = lib->sourcefiles; src != NULL; src = src->next) { astring srcfile; // build the source filename srcfile.printf("%s%s.c", srcdir.cstr(), src->name.cstr()); dependency_map depend_map; // find dependencies file_entry &file = compute_dependencies(srcfile); recurse_dependencies(file, depend_map); for (dependency_map::entry_t *entry = depend_map.first(); entry != NULL; entry = depend_map.next(entry)) { astring t(entry->tag()); if (core_filename_ends_with(t, ".lay")) { astring target2(file.name); target2.replace(0, "src/", "$(OBJ)/"); target2.replace(0, ".c", ".o"); t.replace(0, "src/", "$(OBJ)/"); t.replace(0, ".lay", ".lh"); printf("%s: %s\n", target2.cstr(), t.cstr()); } if (core_filename_ends_with(t, ".inc")) { astring target2(file.name); target2.replace(0, "src/", "$(OBJ)/"); target2.replace(0, ".c", ".o"); printf("%s: %s\n", target2.cstr(), t.cstr()); } } } } return result; }