From 72c344521267378fd82e675a7c2f40a9ae25287e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 9 Jul 2021 15:40:24 +0200 Subject: Handle non-existent target, dependencies --- build.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/build.c b/build.c index 600ac92..085722d 100644 --- a/build.c +++ b/build.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -124,8 +125,11 @@ main(int argc, char *argv[]) dd("%s: target '%s'\n", argv[i], tgt); if (stat(argv[i], &sb)) err(1, argv[i]); - if (stat(tgt, &ssb)) + if (stat(tgt, &ssb)) { + if (errno == ENOENT) + goto build; err(1, tgt); + } if (sb.st_mtime > ssb.st_mtime) { d("%s: %s is modified, building\n", argv[i], argv[i]); @@ -141,8 +145,13 @@ main(int argc, char *argv[]) dd("%s: depend '%s'\n", argv[i], d); - if (stat(d, &sb)) - err(1, d); + if (stat(d, &sb)) { + if (errno != ENOENT) + err(1, d); + fprintf(stderr, "%s: dependency %s does not " + "exist\n", argv[0], d); + continue; + } free(d); if (sb.st_mtime > ssb.st_mtime) { d("%s: %s is modified, building\n", -- cgit v1.2.3