diff options
-rw-r--r-- | maje.c | 2 | ||||
-rw-r--r-- | make.c | 17 |
2 files changed, 12 insertions, 7 deletions
@@ -1,4 +1,5 @@ #define _XOPEN_SOURCE 700 +#include <libgen.h> #include <stdio.h> #include <string.h> #include <unistd.h> @@ -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) { @@ -1,4 +1,5 @@ #define _XOPEN_SOURCE 700 +#include <libgen.h> #include <string.h> #include <stdio.h> @@ -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) |