From ef18ff2bc0588d1d5ab5278e26a94035d15ce293 Mon Sep 17 00:00:00 2001 From: Kyler Date: Sun, 2 Nov 2025 22:15:16 -0700 Subject: [PATCH] Finished makefile --- SLS_C/Makefile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/SLS_C/Makefile b/SLS_C/Makefile index efdeeaa..9d048a4 100644 --- a/SLS_C/Makefile +++ b/SLS_C/Makefile @@ -1,7 +1,7 @@ -# Makefile for SLS project +# Makefile for SLS project with automatic header dependencies CC ?= gcc -CFLAGS ?= -std=c11 -Wall -Wextra -g -Iinclude +CFLAGS ?= -std=c11 -Wall -Wextra -g -Iinclude -MMD -MP LDFLAGS ?= SRCDIR := src @@ -18,7 +18,10 @@ OBJECTS := $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(SOURCES)) TEST_SOURCES := $(wildcard $(TESTDIR)/*.c) TEST_OBJECTS := $(patsubst $(TESTDIR)/%.c,$(OBJDIR)/%.o,$(TEST_SOURCES)) -.PHONY: all compile run test clean +# Include dependency files if they exist +-include $(OBJECTS:.o=.d) $(TEST_OBJECTS:.o=.d) + +.PHONY: all build run test clean # Default: build main program all: $(TARGET) @@ -26,11 +29,10 @@ all: $(TARGET) # Compile object files build: $(OBJECTS) -# Rule to compile .c -> .o +# Rule to compile .c -> .o (handles both src and tests) $(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR) $(CC) $(CFLAGS) -c $< -o $@ -# Rule to compile test .c -> .o $(OBJDIR)/%.o: $(TESTDIR)/%.c | $(OBJDIR) $(CC) $(CFLAGS) -c $< -o $@