From 56205b5b24cff2f3404bee815a2c8a336b152c1d Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Tue, 14 Jan 2020 16:22:57 -0500 Subject: fix segfault when building outside of source tree --- make.c | 10 +++++----- 1 file 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); -- cgit v1.2.1