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 $@