diff --git a/configure.c b/configure.c index b01b351..574b75f 100644 --- a/configure.c +++ b/configure.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -185,18 +186,34 @@ cmd_stdout(char *cmd) FILE *f; char *line = NULL; size_t size; + int result; if (!cmd) { - return NULL; + goto failure; } if (!(f = popen(cmd, "r"))) { - return NULL; + goto failure; } getline(&line, &size, f); - pclose(f); + result = pclose(f); + + if (result < 0) + { + perror("pclose(3)"); + goto failure; + } + else if (result) + { + fprintf(stderr, "command exited with status %d: %s\n", result, cmd); + goto failure; + } return line; + +failure: + free(line); + return NULL; } static int exec_code(char *program, char *argv[]) @@ -293,7 +310,8 @@ collect_sources(char *dir, bool head, char *ext) while ((ent = readdir(handle))) { char *name = ent->d_name; - if (*name == '.') continue; + + if (!strcmp(name, ".") || !strcmp(name, "..")) continue; if (strlen(name) > strlen(ext) && !strcmp(name + strlen(name) - strlen(ext), ext)) @@ -305,22 +323,29 @@ collect_sources(char *dir, bool head, char *ext) free(na); continue; } - if (!strchr(name, '.') && - strcmp(name, "out") && - strcmp(name, "Makefile")) { - str_array_t *sub; char *d1 = string_cat(dir, "/"); char *d2 = string_cat(d1, name); size_t i; + struct stat sb; - sub = collect_sources(d2, false, ext); - for (i = 0; i < str_array_len(sub); i++) + if (stat(d2, &sb)) { - char *file = str_array_get(sub, i); - str_array_add(ret, file); + fprintf(stderr, "stat(2) %s: %s\n", d2, strerror(errno)); + free(d2); + free(d1); } - str_array_free(sub); + else if (S_ISDIR(sb.st_mode)) + { + str_array_t *sub = collect_sources(d2, false, ext); + for (i = 0; i < str_array_len(sub); i++) + { + char *file = str_array_get(sub, i); + str_array_add(ret, file); + } + str_array_free(sub); + } + free(d2); free(d1); } @@ -417,10 +442,13 @@ main_build(int argc, char *argv[]) int opt; str_array_t *sources, *images, *utils, *aya; - if (strchr(repo, '\n')) + if (repo) { - *(strchr(repo, '\n')) = '\0'; + char *lf = strchr(repo, '\n'); + *lf = '\0'; } + else + repo = strdup("N/A"); while ((opt = getopt(argc, argv, "sl")) != -1) { @@ -555,6 +583,7 @@ main_build(int argc, char *argv[]) fprintf(makefile, " -static"); } fprintf(makefile, " $<"); + fprintf(makefile, " -I $(CYTO_INC)"); fprintf(makefile, " -L $(CYTO_LIB)"); if (with_static) {