From 36de4ea4f836874ca005cdf70a581d1a037a8486 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Mon, 30 Mar 2020 10:10:42 -0400 Subject: add BINDIR for final binary --- Makefile | 47 +++++++++++++++++++++++------------------------ make.c | 11 +++++------ 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index 90979bc..48777f3 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,6 @@ # See https://gitlab.com/jkaivo/maje/ for more information # Do not edit this Makefile by hand -default: all - CC=c99 LD=$(CC) CFLAGS=-Wall -Wextra -Wpedantic -Werror -g @@ -13,41 +11,42 @@ LDFLAGS= LDLIBS= SRCDIR=. OBJDIR=. +BINDIR=$(OBJDIR) -all: maje +all: $(BINDIR)/maje clean: - rm -f maje *.o + rm -f $(BINDIR)/maje $(OBJDIR)/*.o -maje: $(OBJDIR)/includes.o -$(OBJDIR)/includes.o: $(SRCDIR)/maje.h -$(OBJDIR)/includes.o: $(SRCDIR)/includes.c - $(CC) $(CFLAGS) -o $@ -c $(SRCDIR)/includes.c +$(BINDIR)/maje: $(OBJDIR)/make.o +$(OBJDIR)/make.o: $(SRCDIR)/maje.h +$(OBJDIR)/make.o: $(SRCDIR)/make.c + $(CC) $(CFLAGS) -o $@ -c $(SRCDIR)/make.c -maje: $(OBJDIR)/list.o -$(OBJDIR)/list.o: $(SRCDIR)/maje.h -$(OBJDIR)/list.o: $(SRCDIR)/list.c - $(CC) $(CFLAGS) -o $@ -c $(SRCDIR)/list.c +$(BINDIR)/maje: $(OBJDIR)/sources.o +$(OBJDIR)/sources.o: $(SRCDIR)/maje.h +$(OBJDIR)/sources.o: $(SRCDIR)/sources.c + $(CC) $(CFLAGS) -o $@ -c $(SRCDIR)/sources.c -maje: $(OBJDIR)/main.o +$(BINDIR)/maje: $(OBJDIR)/main.o $(OBJDIR)/main.o: $(SRCDIR)/maje.h $(OBJDIR)/main.o: $(SRCDIR)/main.c $(CC) $(CFLAGS) -o $@ -c $(SRCDIR)/main.c -maje: $(OBJDIR)/maje.o +$(BINDIR)/maje: $(OBJDIR)/list.o +$(OBJDIR)/list.o: $(SRCDIR)/maje.h +$(OBJDIR)/list.o: $(SRCDIR)/list.c + $(CC) $(CFLAGS) -o $@ -c $(SRCDIR)/list.c + +$(BINDIR)/maje: $(OBJDIR)/maje.o $(OBJDIR)/maje.o: $(SRCDIR)/maje.h $(OBJDIR)/maje.o: $(SRCDIR)/maje.c $(CC) $(CFLAGS) -o $@ -c $(SRCDIR)/maje.c -maje: $(OBJDIR)/make.o -$(OBJDIR)/make.o: $(SRCDIR)/maje.h -$(OBJDIR)/make.o: $(SRCDIR)/make.c - $(CC) $(CFLAGS) -o $@ -c $(SRCDIR)/make.c - -maje: $(OBJDIR)/sources.o -$(OBJDIR)/sources.o: $(SRCDIR)/maje.h -$(OBJDIR)/sources.o: $(SRCDIR)/sources.c - $(CC) $(CFLAGS) -o $@ -c $(SRCDIR)/sources.c +$(BINDIR)/maje: $(OBJDIR)/includes.o +$(OBJDIR)/includes.o: $(SRCDIR)/maje.h +$(OBJDIR)/includes.o: $(SRCDIR)/includes.c + $(CC) $(CFLAGS) -o $@ -c $(SRCDIR)/includes.c -maje: +$(BINDIR)/maje: $(LD) $(LDFLAGS) -o $@ $(OBJDIR)/*.o $(LDLIBS) diff --git a/make.c b/make.c index 7047ff9..918a900 100644 --- a/make.c +++ b/make.c @@ -13,8 +13,6 @@ static void make_header(FILE *makefile, const char *target) fprintf(makefile, "# See https://gitlab.com/jkaivo/maje/ for more information\n"); fprintf(makefile, "# Do not edit this Makefile by hand\n\n"); - fprintf(makefile, "default: all\n\n"); - fprintf(makefile, "CC=c99\n"); fprintf(makefile, "LD=$(CC)\n"); fprintf(makefile, "CFLAGS=-Wall -Wextra -Wpedantic -Werror -g\n"); @@ -22,12 +20,13 @@ static void make_header(FILE *makefile, const char *target) fprintf(makefile, "LDLIBS=\n"); fprintf(makefile, "SRCDIR=.\n"); fprintf(makefile, "OBJDIR=.\n"); + fprintf(makefile, "BINDIR=$(OBJDIR)\n"); fprintf(makefile, "\n"); - fprintf(makefile, "all: %s\n\n", target); + fprintf(makefile, "all: $(BINDIR)/%s\n\n", target); fprintf(makefile, "clean:\n"); - fprintf(makefile, "\trm -f %s *.o\n\n", target); + fprintf(makefile, "\trm -f $(BINDIR)/%s $(OBJDIR)/*.o\n\n", target); } static void add_object(FILE *makefile, const struct majefile *src, const char *target) @@ -36,7 +35,7 @@ static void add_object(FILE *makefile, const struct majefile *src, const char *t char *obj = basename(fullobj); obj[strlen(obj) - 1] = 'o'; - fprintf(makefile, "%s: $(OBJDIR)/%s\n", target, obj); + fprintf(makefile, "$(BINDIR)/%s: $(OBJDIR)/%s\n", target, obj); for (struct majefile *inc = find_includes(src); inc != NULL; inc = inc->next) { fprintf(makefile, "$(OBJDIR)/%s: $(SRCDIR)/%s\n", obj, inc->path); @@ -60,7 +59,7 @@ void make_makefile(const char *makepath, struct majefile *sources, const char *t add_object(makefile, src, target); } - fprintf(makefile, "%s:\n", target); + fprintf(makefile, "$(BINDIR)/%s:\n", target); fprintf(makefile, "\t$(LD) $(LDFLAGS) -o $@ $(OBJDIR)/*.o $(LDLIBS)\n"); fclose(makefile); -- cgit v1.2.1