summaryrefslogtreecommitdiff
path: root/make.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2022-04-25 19:45:31 -0400
committerJakob Kaivo <jkk@ung.org>2022-04-25 19:45:31 -0400
commit319c7568828a01fa5ba8ded0b560d852124ffb84 (patch)
tree7ca966f27a06885ae6451e730128f70994355a4a /make.c
parent0c72419d193ca13edc8302cd8c151bbe80a4716f (diff)
add support for setting flags in source
Diffstat (limited to 'make.c')
-rw-r--r--make.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/make.c b/make.c
index 5d2c808..13bc7eb 100644
--- a/make.c
+++ b/make.c
@@ -6,7 +6,7 @@
#include "maje.h"
-static void make_header(FILE *makefile, const char *target)
+static void make_header(FILE *makefile, const char *target, struct majeflag *flags)
{
fprintf(makefile, ".POSIX:\n\n");
fprintf(makefile, "# This Makefile was generated by maje\n");
@@ -15,9 +15,31 @@ static void make_header(FILE *makefile, const char *target)
fprintf(makefile, "CC=c99\n");
fprintf(makefile, "LD=$(CC)\n");
- fprintf(makefile, "CFLAGS=-Wall -Wextra -Wpedantic -Werror -g\n");
- fprintf(makefile, "LDFLAGS=\n");
- fprintf(makefile, "LDLIBS=\n");
+
+ fprintf(makefile, "CFLAGS=-Wall -Wextra -Wpedantic -Werror -g");
+ for (struct majeflag *flag = flags; flag != NULL; flag = flag->next) {
+ if (flag->type == MAJE_CFLAG) {
+ fprintf(makefile, " %s", flag->flag);
+ }
+ }
+ fprintf(makefile, "\n");
+
+ fprintf(makefile, "LDFLAGS=");
+ for (struct majeflag *flag = flags; flag != NULL; flag = flag->next) {
+ if (flag->type == MAJE_LDFLAG) {
+ fprintf(makefile, " %s", flag->flag);
+ }
+ }
+ fprintf(makefile, "\n");
+
+ fprintf(makefile, "LDLIBS=");
+ for (struct majeflag *flag = flags; flag != NULL; flag = flag->next) {
+ if (flag->type == MAJE_LDLIB) {
+ fprintf(makefile, " %s", flag->flag);
+ }
+ }
+ fprintf(makefile, "\n");
+
fprintf(makefile, "SRCDIR=.\n");
fprintf(makefile, "OBJDIR=.\n");
fprintf(makefile, "BINDIR=$(OBJDIR)\n");
@@ -60,7 +82,12 @@ void make_makefile(const char *makepath, struct majefile *sources, const char *t
return;
}
- make_header(makefile, target);
+ struct majeflag *flags = NULL;
+ for (struct majefile *src = sources; src != NULL; src = src->next) {
+ flags = add_flags(src, flags);
+ }
+
+ make_header(makefile, target, flags);
for (struct majefile *src = sources; src != NULL; src = src->next) {
add_object(makefile, src, target);
}