summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-01-14 11:52:15 -0500
committerJakob Kaivo <jkk@ung.org>2020-01-14 11:52:15 -0500
commitd39c5014e6b64e1f6d13d466cb7b3dbeb57880c5 (patch)
treefb48d63f47aabe52f9c89b56303bac90b4fd897b
parent9caf5a540b571685ab2b99434eb8b790f895a624 (diff)
always build in current directory, source from specified path
-rw-r--r--maje.c2
-rw-r--r--make.c17
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 <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) {
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 <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)