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