summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-01-14 16:22:57 -0500
committerJakob Kaivo <jkk@ung.org>2020-01-14 16:22:57 -0500
commit56205b5b24cff2f3404bee815a2c8a336b152c1d (patch)
tree97f947ee8d30da81a53ff5631e6449b329213fcb
parenta649902a5fa065b5f4dfd32f8852428c0827d026 (diff)
fix segfault when building outside of source tree
-rw-r--r--make.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/make.c b/make.c
index 35866bd..d8ea00e 100644
--- a/make.c
+++ b/make.c
@@ -27,17 +27,17 @@ static void make_header(FILE *makefile, const char *target)
fprintf(makefile, "\trm -f %s *.o\n\n", target);
}
-static void addfile(FILE *makefile, const char *src, const char *target)
+static void add_object(FILE *makefile, const char *src, const char *target)
{
- char *obj = strdup(src);
+ char *fullobj = strdup(src);
+ char *obj = basename(fullobj);
obj[strlen(obj) - 1] = 'o';
- obj = basename(obj);
fprintf(makefile, "%s: %s\n", target, obj);
fprintf(makefile, "%s: %s\n", obj, src);
fprintf(makefile, "\t$(CC) $(CFLAGS) -c %s\n\n", src);
- free(obj);
+ free(fullobj);
}
void make_makefile(const char *makepath, struct majefile *sources, const char *target)
@@ -50,7 +50,7 @@ void make_makefile(const char *makepath, struct majefile *sources, const char *t
make_header(makefile, target);
for (struct majefile *src = sources; src != NULL; src = src->next) {
- addfile(makefile, src->path, target);
+ add_object(makefile, src->path, target);
}
fprintf(makefile, "%s:\n", target);