My previous idea was to generate a list of all the headers, and add it as a dependency for all object files. This way, any changes in a header would trigger a rebuild of all object files, which would in-turn trigger a build of the binary. This will be a bit of an issue later on when we have stuff that's independent of others; a change in parser code won't necessarily affect code generation, but a change in AST will. We don't want to re-trigger builds for everything. This setup forces gcc to generate a clear set of dependencies in the build folder (in a syntax recognisable by Make), then include that in the Makefile itself. These dependencies are specific to each code unit and so only concern the headers that code unit uses.
50 lines
916 B
Makefile
50 lines
916 B
Makefile
CC=cc
|
|
|
|
DIST=build
|
|
OUT=$(DIST)/arl.out
|
|
MODULES=main lib/vec lib/sv parser/ast parser/parser
|
|
OBJECTS:=$(patsubst %,$(DIST)/%.o, $(MODULES))
|
|
|
|
LDFLAGS=
|
|
GFLAGS=-Wall -Wextra -Wpedantic -std=c23 -I./src/
|
|
DFLAGS=-ggdb -fsanitize=address -fsanitize=undefined
|
|
RFLAGS=-O3
|
|
|
|
MODE=release
|
|
ifeq ($(MODE), release)
|
|
CFLAGS=$(GFLAGS) $(RFLAGS)
|
|
else
|
|
CFLAGS=$(GFLAGS) $(DFLAGS)
|
|
endif
|
|
|
|
# Dependency generation
|
|
DEPFLAGS=-MT $@ -MMD -MP -MF
|
|
DEPDIR=$(DIST)/deps
|
|
|
|
$(OUT): $(OBJECTS) | $(DIST)
|
|
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
|
|
|
$(DIST)/%.o: src/arl/%.c | $(DIST) $(DEPDIR)
|
|
$(CC) $(CFLAGS) $(DEPFLAGS) $(DEPDIR)/$*.d -c -o $@ $<
|
|
|
|
$(DIST):
|
|
mkdir -p $(DIST)
|
|
mkdir -p $(DIST)/lib
|
|
mkdir -p $(DIST)/parser
|
|
|
|
$(DEPDIR):
|
|
mkdir -p $(DEPDIR)
|
|
mkdir -p $(DEPDIR)/lib
|
|
mkdir -p $(DEPDIR)/parser
|
|
|
|
.PHONY: run clean
|
|
ARGS=
|
|
run: $(OUT)
|
|
./$^ $(ARGS)
|
|
|
|
clean:
|
|
rm -rf $(DIST)
|
|
|
|
DEPS:=$(patsubst %,$(DEPDIR)/%.d, $(MODULES))
|
|
include $(wildcard $(DEPS))
|