From d39c5014e6b64e1f6d13d466cb7b3dbeb57880c5 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Tue, 14 Jan 2020 11:52:15 -0500 Subject: always build in current directory, source from specified path --- maje.c | 2 ++ make.c | 17 ++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/maje.c b/maje.c index 25ab155..3bbc5c0 100644 --- a/maje.c +++ b/maje.c @@ -1,4 +1,5 @@ #define _XOPEN_SOURCE 700 +#include #include #include #include @@ -37,6 +38,7 @@ int main(int argc, char *argv[]) } char *target = strdup(mainname); target[strlen(target) - 2] = '\0'; + target = basename(target); FILE *makefile = fopen("Makefile", "w"); if (makefile == NULL) { diff --git a/make.c b/make.c index 4f8b204..683410f 100644 --- a/make.c +++ b/make.c @@ -1,4 +1,5 @@ #define _XOPEN_SOURCE 700 +#include #include #include @@ -6,29 +7,31 @@ static void make_header(FILE *makefile, const char *target) { - fprintf(makefile, ".POSIX:\n"); + fprintf(makefile, ".POSIX:\n\n"); fprintf(makefile, "# This Makefile was generated by maje\n"); fprintf(makefile, "# See https://gitlab.com/jkaivo/maje/ for more information\n"); - fprintf(makefile, "# Do not edit this Makefile by hand\n"); + fprintf(makefile, "# Do not edit this Makefile by hand\n\n"); - fprintf(makefile, "default: all\n"); + fprintf(makefile, "default: all\n\n"); fprintf(makefile, "CC=c99\n"); - fprintf(makefile, "CFLAGS=-Wall -Wextra -Wpedantic -Werror -g\n"); + fprintf(makefile, "CFLAGS=-Wall -Wextra -Wpedantic -Werror -g\n\n"); - fprintf(makefile, "all: %s\n", target); + fprintf(makefile, "all: %s\n\n", target); fprintf(makefile, "clean:\n"); - fprintf(makefile, "\trm -f %s *.o\n", target); + fprintf(makefile, "\trm -f %s *.o\n\n", target); } static void addfile(FILE *makefile, const char *src, const char *target) { char *obj = strdup(src); obj[strlen(obj) - 1] = 'o'; + obj = basename(obj); - fprintf(makefile, "%s: %s\n", obj, src); fprintf(makefile, "%s: %s\n", target, obj); + fprintf(makefile, "%s: %s\n", obj, src); + fprintf(makefile, "\t$(CC) $(CFLAGS) -c %s\n\n", src); } void make_makefile(const char *makepath, char **sources, const char *target) -- cgit v1.2.1