Rewrite Makefile for new directory structure

This commit is contained in:
Andrew Scott 2024-08-24 17:34:21 -04:00
parent 02d017af64
commit 73e2716100
Signed by: a
GPG key ID: 7CD5A5977E4931C1

View file

@ -1,47 +1,45 @@
CC = gcc CC = gcc
CFLAGS = -O3 -Wall -Wextra -Wpedantic CFLAGS =
CPPFLAGS = -Iinclude -MMD -MP
SRCS = main.c vm.c gc.c galloc.c SRCDIR = src
OBJS = $(SRCS:.c=.o)
SRCS = $(wildcard $(SRCDIR)/*.c)
OBJS = $(patsubst $(SRCDIR)/%.c,%.o,$(SRCS))
EXE = gc EXE = gc
DBDIR = debug DBDIR = debug
DBEXE = $(DBDIR)/$(EXE) DBEXE = $(DBDIR)/$(EXE)
DBOBJS = $(addprefix $(DBDIR)/, $(OBJS)) DBOBJS = $(addprefix $(DBDIR)/, $(OBJS))
DBCFLAGS = -g -O0 -DDEBUG DBCFLAGS = -g -O0 -DDEBUG
REDIR = build REDIR = bin
REEXE = $(REDIR)/$(EXE) REEXE = $(REDIR)/$(EXE)
REOBJS = $(addprefix $(REDIR)/, $(OBJS)) REOBJS = $(addprefix $(REDIR)/, $(OBJS))
RECFLAGS = -O3 -Wall -Wextra -Wpedantic -Werror
.PHONY: all clean debug release prep .PHONY: all clean debug prep release
all: debug release gc all: debug release
gc: $(REEXE)
@cp $< $@
debug: prep $(DBEXE) debug: prep $(DBEXE)
$(DBEXE): $(DBOBJS) $(DBEXE): $(DBOBJS)
$(CC) $(CFLAGS) $(DBCFLAGS) -DTEST -o $@ $^ $(CC) $(CFLAGS) $(DBCFLAGS) -o $@ $^
$(DBDIR)/%.o: %.c $(DBDIR)/%.o: $(SRCDIR)/%.c
$(CC) -c $(CFLAGS) $(DBCFLAGS) -o $@ $< $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DBCFLAGS) -o $@ $<
release: prep $(REEXE) release: prep $(REEXE)
$(REEXE): $(REOBJS) $(REEXE): $(REOBJS)
$(CC) $(CFLAGS) -o $@ $^ $(CC) $(CFLAGS) $(RECFLAGS) -o $@ $^
$(REDIR)/%.o: %.c $(REDIR)/%.o: $(SRCDIR)/%.c
$(CC) -c $(CFLAGS) -o $@ $< $(CC) -c $(CPPFLAGS) $(CFLAGS) $(RECFLAGS) -o $@ $<
prep: prep:
@mkdir -p $(DBDIR) $(REDIR) @mkdir -p $(DBDIR) $(REDIR)
clean: clean:
rm -rf gc $(DBDIR) $(REDIR) rm -rf $(DBDIR) $(REDIR)